blob: a4616e9e4a67ec57d219c688e57d43f80fde6ce4 [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;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080050import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070055import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080068import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070078import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070079import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080080import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070083import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080084import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080085import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070086import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
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);
1024 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001025 break;
1026
1027 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 if (ar.exception == null && ar.result != null) {
1031 request.result = ar.result;
1032 } else {
1033 if (ar.result == null) {
1034 loge("queryModemActivityInfo: Empty response");
1035 } else if (ar.exception instanceof CommandException) {
1036 loge("queryModemActivityInfo: CommandException: " +
1037 ar.exception);
1038 } else {
1039 loge("queryModemActivityInfo: Unknown exception");
1040 }
1041 }
Amit Mahajand4766222016-01-28 15:28:28 -08001042 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
1043 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -07001044 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -08001045 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001046 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001047 break;
1048
Meng Wang1a7c35a2016-05-05 20:56:15 -07001049 case CMD_SET_ALLOWED_CARRIERS:
1050 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001051 CarrierRestrictionRules argument =
1052 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001053 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001054 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001055 break;
1056
1057 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
1060 if (ar.exception == null && ar.result != null) {
1061 request.result = ar.result;
1062 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001063 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1064 if (ar.exception instanceof CommandException) {
1065 loge("setAllowedCarriers: CommandException: " + ar.exception);
1066 CommandException.Error error =
1067 ((CommandException) (ar.exception)).getCommandError();
1068 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1069 request.result =
1070 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1071 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001072 } else {
1073 loge("setAllowedCarriers: Unknown exception");
1074 }
1075 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001076 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001077 break;
1078
1079 case CMD_GET_ALLOWED_CARRIERS:
1080 request = (MainThreadRequest) msg.obj;
1081 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001082 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001083 break;
1084
1085 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
1088 if (ar.exception == null && ar.result != null) {
1089 request.result = ar.result;
1090 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001091 request.result = new IllegalStateException(
1092 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001093 if (ar.result == null) {
1094 loge("getAllowedCarriers: Empty response");
1095 } else if (ar.exception instanceof CommandException) {
1096 loge("getAllowedCarriers: CommandException: " +
1097 ar.exception);
1098 } else {
1099 loge("getAllowedCarriers: Unknown exception");
1100 }
1101 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001102 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001103 break;
1104
Nathan Haroldb3014052017-01-25 15:57:32 -08001105 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1106 ar = (AsyncResult) msg.obj;
1107 request = (MainThreadRequest) ar.userObj;
1108 if (ar.exception == null && ar.result != null) {
1109 request.result = ar.result;
1110 } else {
1111 request.result = new IllegalArgumentException(
1112 "Failed to retrieve Forbidden Plmns");
1113 if (ar.result == null) {
1114 loge("getForbiddenPlmns: Empty response");
1115 } else {
1116 loge("getForbiddenPlmns: Unknown exception");
1117 }
1118 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001119 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001120 break;
1121
1122 case CMD_GET_FORBIDDEN_PLMNS:
1123 request = (MainThreadRequest) msg.obj;
1124 uiccCard = getUiccCardFromRequest(request);
1125 if (uiccCard == null) {
1126 loge("getForbiddenPlmns() UiccCard is null");
1127 request.result = new IllegalArgumentException(
1128 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001129 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001130 break;
1131 }
1132 Integer appType = (Integer) request.argument;
1133 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1134 if (uiccApp == null) {
1135 loge("getForbiddenPlmns() no app with specified type -- "
1136 + appType);
1137 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001138 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001139 break;
1140 } else {
1141 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1142 + " specified type -- " + appType);
1143 }
1144 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1145 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1146 onCompleted);
1147 break;
1148
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001149 case CMD_SWITCH_SLOTS:
1150 request = (MainThreadRequest) msg.obj;
1151 int[] physicalSlots = (int[]) request.argument;
1152 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1153 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1154 break;
1155
1156 case EVENT_SWITCH_SLOTS_DONE:
1157 ar = (AsyncResult) msg.obj;
1158 request = (MainThreadRequest) ar.userObj;
1159 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001160 notifyRequester(request);
1161 break;
1162 case CMD_GET_NETWORK_SELECTION_MODE:
1163 request = (MainThreadRequest) msg.obj;
1164 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1165 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1166 break;
1167
1168 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1169 ar = (AsyncResult) msg.obj;
1170 request = (MainThreadRequest) ar.userObj;
1171 if (ar.exception != null) {
1172 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1173 } else {
1174 int mode = ((int[]) ar.result)[0];
1175 if (mode == 0) {
1176 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1177 } else {
1178 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1179 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001180 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001181 notifyRequester(request);
1182 break;
1183 case CMD_GET_CDMA_ROAMING_MODE:
1184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1186 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1187 break;
1188 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1189 ar = (AsyncResult) msg.obj;
1190 request = (MainThreadRequest) ar.userObj;
1191 if (ar.exception != null) {
1192 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1193 } else {
1194 request.result = ((int[]) ar.result)[0];
1195 }
1196 notifyRequester(request);
1197 break;
1198 case CMD_SET_CDMA_ROAMING_MODE:
1199 request = (MainThreadRequest) msg.obj;
1200 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1201 int mode = (int) request.argument;
1202 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1203 break;
1204 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1205 ar = (AsyncResult) msg.obj;
1206 request = (MainThreadRequest) ar.userObj;
1207 request.result = ar.exception == null;
1208 notifyRequester(request);
1209 break;
1210 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1211 request = (MainThreadRequest) msg.obj;
1212 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1213 int subscriptionMode = (int) request.argument;
1214 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1215 break;
1216 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1217 ar = (AsyncResult) msg.obj;
1218 request = (MainThreadRequest) ar.userObj;
1219 request.result = ar.exception == null;
1220 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001221 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001222 case CMD_GET_ALL_CELL_INFO:
1223 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001224 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001225 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001226 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001227 case EVENT_GET_ALL_CELL_INFO_DONE:
1228 ar = (AsyncResult) msg.obj;
1229 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001230 // If a timeout occurs, the response will be null
1231 request.result = (ar.exception == null && ar.result != null)
1232 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001233 synchronized (request) {
1234 request.notifyAll();
1235 }
1236 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001237 case CMD_REQUEST_CELL_INFO_UPDATE:
1238 request = (MainThreadRequest) msg.obj;
1239 request.phone.requestCellInfoUpdate(request.workSource,
1240 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1241 break;
1242 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1243 ar = (AsyncResult) msg.obj;
1244 request = (MainThreadRequest) ar.userObj;
1245 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1246 try {
1247 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001248 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001249 cb.onError(
1250 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1251 ar.exception.getClass().getName(),
1252 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001253 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001254 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001255 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001256 } else {
1257 // use the result as returned
1258 cb.onCellInfo((List<CellInfo>) ar.result);
1259 }
1260 } catch (RemoteException re) {
1261 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1262 }
1263 break;
1264 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 request = (MainThreadRequest) msg.obj;
1266 WorkSource ws = (WorkSource) request.argument;
1267 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001268 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001269 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001270 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001271 ar = (AsyncResult) msg.obj;
1272 request = (MainThreadRequest) ar.userObj;
1273 if (ar.exception == null) {
1274 request.result = ar.result;
1275 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001276 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001277 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001278 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001279 }
1280
1281 synchronized (request) {
1282 request.notifyAll();
1283 }
1284 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001285 case CMD_MODEM_REBOOT:
1286 request = (MainThreadRequest) msg.obj;
1287 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001288 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001289 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001290 case EVENT_CMD_MODEM_REBOOT_DONE:
1291 handleNullReturnEvent(msg, "rebootModem");
1292 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001293 case CMD_REQUEST_ENABLE_MODEM:
1294 request = (MainThreadRequest) msg.obj;
1295 boolean enable = (boolean) request.argument;
1296 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001297 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001298 PhoneConfigurationManager.getInstance()
1299 .enablePhone(request.phone, enable, onCompleted);
1300 break;
1301 case EVENT_ENABLE_MODEM_DONE:
1302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
1304 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001305 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001306 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001307 if ((boolean) request.result) {
1308 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1309 updateModemStateMetrics();
1310 } else {
1311 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1312 + ar.exception);
1313 }
1314 notifyRequester(request);
1315 break;
1316 case CMD_GET_MODEM_STATUS:
1317 request = (MainThreadRequest) msg.obj;
1318 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1319 PhoneConfigurationManager.getInstance()
1320 .getPhoneStatusFromModem(request.phone, onCompleted);
1321 break;
1322 case EVENT_GET_MODEM_STATUS_DONE:
1323 ar = (AsyncResult) msg.obj;
1324 request = (MainThreadRequest) ar.userObj;
1325 int id = request.phone.getPhoneId();
1326 if (ar.exception == null && ar.result != null) {
1327 request.result = ar.result;
1328 //update the cache as modem status has changed
1329 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1330 (boolean) request.result);
1331 } else {
1332 // Return true if modem status cannot be retrieved. For most cases,
1333 // modem status is on. And for older version modems, GET_MODEM_STATUS
1334 // and disable modem are not supported. Modem is always on.
1335 // TODO: this should be fixed in R to support a third
1336 // status UNKNOWN b/131631629
1337 request.result = true;
1338 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1339 + ar.exception);
1340 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001341 notifyRequester(request);
1342 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001343 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1344 request = (MainThreadRequest) msg.obj;
1345 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1346 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1347 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1348 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1349 break;
1350 }
1351 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1352 ar = (AsyncResult) msg.obj;
1353 request = (MainThreadRequest) ar.userObj;
1354 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1355 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1356 args.second.accept(ar.exception == null);
1357 notifyRequester(request);
1358 break;
1359 }
yincheng zhaod698b842019-09-06 17:06:54 -07001360 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1361 ar = (AsyncResult) msg.obj;
1362 request = (MainThreadRequest) ar.userObj;
1363 if (ar.exception == null && ar.result != null) {
1364 request.result = ar.result;
1365 } else {
1366 request.result = -1;
1367 loge("Failed to set Forbidden Plmns");
1368 if (ar.result == null) {
1369 loge("setForbidenPlmns: Empty response");
1370 } else if (ar.exception != null) {
1371 loge("setForbiddenPlmns: Exception: " + ar.exception);
1372 request.result = -1;
1373 } else {
1374 loge("setForbiddenPlmns: Unknown exception");
1375 }
1376 }
1377 notifyRequester(request);
1378 break;
1379 case CMD_SET_FORBIDDEN_PLMNS:
1380 request = (MainThreadRequest) msg.obj;
1381 uiccCard = getUiccCardFromRequest(request);
1382 if (uiccCard == null) {
1383 loge("setForbiddenPlmns: UiccCard is null");
1384 request.result = -1;
1385 notifyRequester(request);
1386 break;
1387 }
1388 Pair<Integer, List<String>> setFplmnsArgs =
1389 (Pair<Integer, List<String>>) request.argument;
1390 appType = setFplmnsArgs.first;
1391 List<String> fplmns = setFplmnsArgs.second;
1392 uiccApp = uiccCard.getApplicationByType(appType);
1393 if (uiccApp == null) {
1394 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1395 request.result = -1;
1396 loge("Failed to get UICC App");
1397 notifyRequester(request);
1398 } else {
1399 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1400 ((SIMRecords) uiccApp.getIccRecords())
1401 .setForbiddenPlmns(onCompleted, fplmns);
1402 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001403 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001404 case CMD_ERASE_MODEM_CONFIG:
1405 request = (MainThreadRequest) msg.obj;
1406 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1407 defaultPhone.eraseModemConfig(onCompleted);
1408 break;
1409 case EVENT_ERASE_MODEM_CONFIG_DONE:
1410 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001411 break;
zoey chenf95ca592019-12-30 16:11:23 +08001412
1413 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1414 request = (MainThreadRequest) msg.obj;
1415 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1416 Pair<String, String> changed = (Pair<String, String>) request.argument;
1417 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1418 changed.first, changed.second, onCompleted);
1419 break;
1420 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
1423 if (ar.exception == null) {
1424 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1425 } else {
1426 request.result = msg.arg1;
1427 }
1428 notifyRequester(request);
1429 break;
1430
1431 case CMD_SET_ICC_LOCK_ENABLED:
1432 request = (MainThreadRequest) msg.obj;
1433 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1434 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1435 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1436 enabled.first, enabled.second, onCompleted);
1437 break;
1438 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
1441 if (ar.exception == null) {
1442 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1443 } else {
1444 request.result = msg.arg1;
1445 }
1446 notifyRequester(request);
1447 break;
1448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 default:
1450 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1451 break;
1452 }
1453 }
Jake Hambye994d462014-02-03 13:10:13 -08001454
Pengquan Menga1bb6272018-09-06 09:59:22 -07001455 private void notifyRequester(MainThreadRequest request) {
1456 synchronized (request) {
1457 request.notifyAll();
1458 }
1459 }
1460
Jake Hambye994d462014-02-03 13:10:13 -08001461 private void handleNullReturnEvent(Message msg, String command) {
1462 AsyncResult ar = (AsyncResult) msg.obj;
1463 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1464 if (ar.exception == null) {
1465 request.result = true;
1466 } else {
1467 request.result = false;
1468 if (ar.exception instanceof CommandException) {
1469 loge(command + ": CommandException: " + ar.exception);
1470 } else {
1471 loge(command + ": Unknown exception");
1472 }
1473 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001474 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476 }
1477
1478 /**
1479 * Posts the specified command to be executed on the main thread,
1480 * waits for the request to complete, and returns the result.
1481 * @see #sendRequestAsync
1482 */
1483 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001484 return sendRequest(
1485 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001486 }
1487
1488 /**
1489 * Posts the specified command to be executed on the main thread,
1490 * waits for the request to complete, and returns the result.
1491 * @see #sendRequestAsync
1492 */
1493 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1494 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001495 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001496 }
1497
1498 /**
1499 * Posts the specified command to be executed on the main thread,
1500 * waits for the request to complete, and returns the result.
1501 * @see #sendRequestAsync
1502 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001503 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001504 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001505 }
1506
1507 /**
1508 * Posts the specified command to be executed on the main thread,
1509 * waits for the request to complete, and returns the result.
1510 * @see #sendRequestAsync
1511 */
Nathan Harold92bed182018-10-12 18:16:49 -07001512 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1513 return sendRequest(command, argument, subId, null, workSource);
1514 }
1515
1516 /**
1517 * Posts the specified command to be executed on the main thread,
1518 * waits for the request to complete, and returns the result.
1519 * @see #sendRequestAsync
1520 */
1521 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1522 return sendRequest(
1523 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1524 }
1525
1526 /**
1527 * Posts the specified command to be executed on the main thread,
1528 * waits for the request to complete, and returns the result.
1529 * @see #sendRequestAsync
1530 */
1531 private Object sendRequest(
1532 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001533 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1534 throw new RuntimeException("This method will deadlock if called from the main thread.");
1535 }
1536
Nathan Harold92bed182018-10-12 18:16:49 -07001537 MainThreadRequest request = null;
1538 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1539 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1540 } else if (phone != null) {
1541 request = new MainThreadRequest(argument, phone, workSource);
1542 } else {
1543 request = new MainThreadRequest(argument, subId, workSource);
1544 }
1545
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001546 Message msg = mMainThreadHandler.obtainMessage(command, request);
1547 msg.sendToTarget();
1548
1549 // Wait for the request to complete
1550 synchronized (request) {
1551 while (request.result == null) {
1552 try {
1553 request.wait();
1554 } catch (InterruptedException e) {
1555 // Do nothing, go back and wait until the request is complete
1556 }
1557 }
1558 }
1559 return request.result;
1560 }
1561
1562 /**
1563 * Asynchronous ("fire and forget") version of sendRequest():
1564 * Posts the specified command to be executed on the main thread, and
1565 * returns immediately.
1566 * @see #sendRequest
1567 */
1568 private void sendRequestAsync(int command) {
1569 mMainThreadHandler.sendEmptyMessage(command);
1570 }
1571
1572 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001573 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001574 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001575 */
1576 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001577 sendRequestAsync(command, argument, null, null);
1578 }
1579
1580 /**
1581 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1582 * @see {@link #sendRequest(int,Object)}
1583 */
1584 private void sendRequestAsync(
1585 int command, Object argument, Phone phone, WorkSource workSource) {
1586 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001587 Message msg = mMainThreadHandler.obtainMessage(command, request);
1588 msg.sendToTarget();
1589 }
1590
1591 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 * Initialize the singleton PhoneInterfaceManager instance.
1593 * This is only done once, at startup, from PhoneApp.onCreate().
1594 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001595 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 synchronized (PhoneInterfaceManager.class) {
1597 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001598 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 } else {
1600 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1601 }
1602 return sInstance;
1603 }
1604 }
1605
1606 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001607 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001610 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001611 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1613 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001614 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001615 mTelephonySharedPreferences =
1616 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001617 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001618 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001619
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 publish();
1621 }
1622
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001623 private Phone getDefaultPhone() {
1624 Phone thePhone = getPhone(getDefaultSubscription());
1625 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1626 }
1627
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 private void publish() {
1629 if (DBG) log("publish: " + this);
1630
1631 ServiceManager.addService("phone", this);
1632 }
1633
Stuart Scott584921c2015-01-15 17:10:34 -08001634 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001635 if (request.phone != null) {
1636 return request.phone;
1637 } else {
1638 return getPhoneFromSubId(request.subId);
1639 }
1640 }
1641
1642 private Phone getPhoneFromSubId(int subId) {
1643 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1644 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001645 }
1646
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001647 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1648 Phone phone = getPhoneFromRequest(request);
1649 return phone == null ? null :
1650 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1651 }
1652
Wink Saville36469e72014-06-11 15:17:00 -07001653 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001654 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001655 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001658 private void sendEraseModemConfig(Phone phone) {
1659 if (phone != null) {
1660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1661 mApp, phone.getSubId(), "eraseModemConfig");
1662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1665 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
1668 }
1669 }
1670 }
1671
Peter Wang050bb052020-01-13 23:33:09 -08001672 private boolean isImsAvailableOnDevice() {
1673 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1674 if (pm == null) {
1675 // For some reason package manger is not available.. This will fail internally anyway,
1676 // so do not throw error and allow.
1677 return true;
1678 }
1679 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1680 }
1681
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001683 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001684 }
1685
Wink Savilleb564aae2014-10-23 10:18:09 -07001686 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 if (DBG) log("dial: " + number);
1688 // No permission check needed here: This is just a wrapper around the
1689 // ACTION_DIAL intent, which is available to any app since it puts up
1690 // the UI before it does anything.
1691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 String url = createTelUrl(number);
1695 if (url == null) {
1696 return;
1697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001699 // PENDING: should we just silently fail if phone is offhook or ringing?
1700 PhoneConstants.State state = mCM.getState(subId);
1701 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1702 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1703 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1704 mApp.startActivity(intent);
1705 }
1706 } finally {
1707 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 }
1709 }
1710
1711 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001712 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001713 }
1714
Wink Savilleb564aae2014-10-23 10:18:09 -07001715 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 if (DBG) log("call: " + number);
1717
1718 // This is just a wrapper around the ACTION_CALL intent, but we still
1719 // need to do a permission check since we're calling startActivity()
1720 // from the context of the phone app.
1721 enforceCallPermission();
1722
Jordan Liu1617b712019-07-10 15:06:26 -07001723 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 != AppOpsManager.MODE_ALLOWED) {
1725 return;
1726 }
1727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001728 final long identity = Binder.clearCallingIdentity();
1729 try {
1730 String url = createTelUrl(number);
1731 if (url == null) {
1732 return;
1733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001735 boolean isValid = false;
1736 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1737 if (slist != null) {
1738 for (SubscriptionInfo subInfoRecord : slist) {
1739 if (subInfoRecord.getSubscriptionId() == subId) {
1740 isValid = true;
1741 break;
1742 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001743 }
Wink Saville08874612014-08-31 19:19:58 -07001744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745 if (!isValid) {
1746 return;
1747 }
Wink Saville08874612014-08-31 19:19:58 -07001748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001749 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1750 intent.putExtra(SUBSCRIPTION_KEY, subId);
1751 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1752 mApp.startActivity(intent);
1753 } finally {
1754 Binder.restoreCallingIdentity(identity);
1755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
1757
Wink Savilleb564aae2014-10-23 10:18:09 -07001758 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001759 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001760 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1761 }
1762
Wink Savilleb564aae2014-10-23 10:18:09 -07001763 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001764 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001765 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1766 }
1767
Wink Savilleb564aae2014-10-23 10:18:09 -07001768 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001770
1771 final long identity = Binder.clearCallingIdentity();
1772 try {
1773 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1774 checkSimPin.start();
1775 return checkSimPin.unlockSim(null, pin);
1776 } finally {
1777 Binder.restoreCallingIdentity(identity);
1778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 }
1780
Wink Savilleb564aae2014-10-23 10:18:09 -07001781 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001783
1784 final long identity = Binder.clearCallingIdentity();
1785 try {
1786 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1787 checkSimPuk.start();
1788 return checkSimPuk.unlockSim(puk, pin);
1789 } finally {
1790 Binder.restoreCallingIdentity(identity);
1791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 }
1793
1794 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001795 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 * a synchronous one.
1797 */
1798 private static class UnlockSim extends Thread {
1799
1800 private final IccCard mSimCard;
1801
1802 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001803 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1804 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805
1806 // For replies from SimCard interface
1807 private Handler mHandler;
1808
1809 // For async handler to identify request type
1810 private static final int SUPPLY_PIN_COMPLETE = 100;
1811
1812 public UnlockSim(IccCard simCard) {
1813 mSimCard = simCard;
1814 }
1815
1816 @Override
1817 public void run() {
1818 Looper.prepare();
1819 synchronized (UnlockSim.this) {
1820 mHandler = new Handler() {
1821 @Override
1822 public void handleMessage(Message msg) {
1823 AsyncResult ar = (AsyncResult) msg.obj;
1824 switch (msg.what) {
1825 case SUPPLY_PIN_COMPLETE:
1826 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1827 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001828 mRetryCount = msg.arg1;
1829 if (ar.exception != null) {
1830 if (ar.exception instanceof CommandException &&
1831 ((CommandException)(ar.exception)).getCommandError()
1832 == CommandException.Error.PASSWORD_INCORRECT) {
1833 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1834 } else {
1835 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1836 }
1837 } else {
1838 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001840 mDone = true;
1841 UnlockSim.this.notifyAll();
1842 }
1843 break;
1844 }
1845 }
1846 };
1847 UnlockSim.this.notifyAll();
1848 }
1849 Looper.loop();
1850 }
1851
1852 /*
1853 * Use PIN or PUK to unlock SIM card
1854 *
1855 * If PUK is null, unlock SIM card with PIN
1856 *
1857 * If PUK is not null, unlock SIM card with PUK and set PIN code
1858 */
Wink Saville9de0f752013-10-22 19:04:03 -07001859 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860
1861 while (mHandler == null) {
1862 try {
1863 wait();
1864 } catch (InterruptedException e) {
1865 Thread.currentThread().interrupt();
1866 }
1867 }
1868 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1869
1870 if (puk == null) {
1871 mSimCard.supplyPin(pin, callback);
1872 } else {
1873 mSimCard.supplyPuk(puk, pin, callback);
1874 }
1875
1876 while (!mDone) {
1877 try {
1878 Log.d(LOG_TAG, "wait for done");
1879 wait();
1880 } catch (InterruptedException e) {
1881 // Restore the interrupted status
1882 Thread.currentThread().interrupt();
1883 }
1884 }
1885 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001886 int[] resultArray = new int[2];
1887 resultArray[0] = mResult;
1888 resultArray[1] = mRetryCount;
1889 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891 }
1892
1893 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001894 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001895
1896 }
1897
Wink Savilleb564aae2014-10-23 10:18:09 -07001898 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 // No permission check needed here: this call is harmless, and it's
1900 // needed for the ServiceState.requestStateUpdate() call (which is
1901 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001902 final long identity = Binder.clearCallingIdentity();
1903 try {
1904 final Phone phone = getPhone(subId);
1905 if (phone != null) {
1906 phone.updateServiceLocation();
1907 }
1908 } finally {
1909 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 }
1912
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001913 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001914 @Override
1915 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001916 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001917 }
1918
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001919 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001920 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1921 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1922 callingFeatureId);
1923 }
1924
1925 @Deprecated
1926 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001927 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001928 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1929 }
1930
1931 @Override
1932 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1933 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001934 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001935 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001936 return false;
1937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001938
1939 final long identity = Binder.clearCallingIdentity();
1940 try {
1941 return isRadioOnForSubscriber(subId);
1942 } finally {
1943 Binder.restoreCallingIdentity(identity);
1944 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001945 }
1946
1947 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948 final long identity = Binder.clearCallingIdentity();
1949 try {
1950 final Phone phone = getPhone(subId);
1951 if (phone != null) {
1952 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1953 } else {
1954 return false;
1955 }
1956 } finally {
1957 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001958 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 }
1960
1961 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001962 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 }
Wink Saville36469e72014-06-11 15:17:00 -07001964
Wink Savilleb564aae2014-10-23 10:18:09 -07001965 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967
1968 final long identity = Binder.clearCallingIdentity();
1969 try {
1970 final Phone phone = getPhone(subId);
1971 if (phone != null) {
1972 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1973 }
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 }
Wink Saville36469e72014-06-11 15:17:00 -07001977 }
1978
1979 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001980 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001981 }
1982
Wink Savilleb564aae2014-10-23 10:18:09 -07001983 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001984 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985
1986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 final Phone phone = getPhone(subId);
1989 if (phone == null) {
1990 return false;
1991 }
1992 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1993 toggleRadioOnOffForSubscriber(subId);
1994 }
1995 return true;
1996 } finally {
1997 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
Wink Saville36469e72014-06-11 15:17:00 -07002000
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002001 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002002 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002003 /*
2004 * If any of the Radios are available, it will need to be
2005 * shutdown. So return true if any Radio is available.
2006 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002007 final long identity = Binder.clearCallingIdentity();
2008 try {
2009 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2010 Phone phone = PhoneFactory.getPhone(i);
2011 if (phone != null && phone.isRadioAvailable()) return true;
2012 }
2013 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2014 return false;
2015 } finally {
2016 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002017 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002018 }
2019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002021 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022 enforceModifyPermission();
2023
2024 final long identity = Binder.clearCallingIdentity();
2025 try {
2026 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2027 logv("Shutting down Phone " + i);
2028 shutdownRadioUsingPhoneId(i);
2029 }
2030 } finally {
2031 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002032 }
2033 }
2034
2035 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002036 Phone phone = PhoneFactory.getPhone(phoneId);
2037 if (phone != null && phone.isRadioAvailable()) {
2038 phone.shutdownRadio();
2039 }
2040 }
2041
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002043 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002044
2045 final long identity = Binder.clearCallingIdentity();
2046 try {
2047 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2048 if (defaultPhone != null) {
2049 defaultPhone.setRadioPower(turnOn);
2050 return true;
2051 } else {
2052 loge("There's no default phone.");
2053 return false;
2054 }
2055 } finally {
2056 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002057 }
Wink Saville36469e72014-06-11 15:17:00 -07002058 }
2059
Wink Savilleb564aae2014-10-23 10:18:09 -07002060 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002062
2063 final long identity = Binder.clearCallingIdentity();
2064 try {
2065 final Phone phone = getPhone(subId);
2066 if (phone != null) {
2067 phone.setRadioPower(turnOn);
2068 return true;
2069 } else {
2070 return false;
2071 }
2072 } finally {
2073 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002074 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002075 }
2076
Wink Saville36469e72014-06-11 15:17:00 -07002077 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002078 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 public boolean enableDataConnectivity() {
2080 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002081
2082 final long identity = Binder.clearCallingIdentity();
2083 try {
2084 int subId = mSubscriptionController.getDefaultDataSubId();
2085 final Phone phone = getPhone(subId);
2086 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002087 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002088 return true;
2089 } else {
2090 return false;
2091 }
2092 } finally {
2093 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002094 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 }
2096
Wink Saville36469e72014-06-11 15:17:00 -07002097 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002098 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 public boolean disableDataConnectivity() {
2100 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002101
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 int subId = mSubscriptionController.getDefaultDataSubId();
2105 final Phone phone = getPhone(subId);
2106 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002107 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002108 return true;
2109 } else {
2110 return false;
2111 }
2112 } finally {
2113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 }
2116
Sanket Padawe356d7632015-06-22 14:03:32 -07002117 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002118 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002119 final long identity = Binder.clearCallingIdentity();
2120 try {
2121 final Phone phone = getPhone(subId);
2122 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002123 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002124 } else {
2125 return false;
2126 }
2127 } finally {
2128 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002129 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 }
2131
2132 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002133 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002134 }
2135
pkanwarae03a6b2016-11-06 20:37:09 -08002136 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002137 enforceCallPermission();
2138
2139 final long identity = Binder.clearCallingIdentity();
2140 try {
2141 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2142 return;
2143 }
2144 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2145 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2146 } finally {
2147 Binder.restoreCallingIdentity(identity);
2148 }
pkanwar32d516d2016-10-14 19:37:38 -07002149 };
2150
Wink Savilleb564aae2014-10-23 10:18:09 -07002151 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002153
2154 final long identity = Binder.clearCallingIdentity();
2155 try {
2156 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2157 return false;
2158 }
2159 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2160 } finally {
2161 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 }
2164
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002166 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002167 }
2168
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002169 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 Phone phone = PhoneFactory.getPhone(slotIndex);
2173 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2174 PhoneConstantConversions.convertCallState(phone.getState());
2175 } finally {
2176 Binder.restoreCallingIdentity(identity);
2177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 }
2179
Sanket Padawe356d7632015-06-22 14:03:32 -07002180 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002181 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002182 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2183 }
2184
2185 @Override
2186 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002187 final long identity = Binder.clearCallingIdentity();
2188 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002189 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002190 if (phone != null) {
2191 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2192 } else {
2193 return PhoneConstantConversions.convertDataState(
2194 PhoneConstants.DataState.DISCONNECTED);
2195 }
2196 } finally {
2197 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002198 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 }
2200
Sanket Padawe356d7632015-06-22 14:03:32 -07002201 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002202 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002203 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2204 }
2205
2206 @Override
2207 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002208 final long identity = Binder.clearCallingIdentity();
2209 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002210 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002211 if (phone != null) {
2212 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2213 } else {
2214 return TelephonyManager.DATA_ACTIVITY_NONE;
2215 }
2216 } finally {
2217 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220
2221 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002222 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002223 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002224 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002225
2226 LocationAccessPolicy.LocationPermissionResult locationResult =
2227 LocationAccessPolicy.checkLocationPermission(mApp,
2228 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2229 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002230 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002231 .setCallingPid(Binder.getCallingPid())
2232 .setCallingUid(Binder.getCallingUid())
2233 .setMethod("getCellLocation")
2234 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2235 .build());
2236 switch (locationResult) {
2237 case DENIED_HARD:
2238 throw new SecurityException("Not allowed to access cell location");
2239 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002240 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2241 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 }
2243
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002244 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245 final long identity = Binder.clearCallingIdentity();
2246 try {
2247 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002248 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002249 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250 } finally {
2251 Binder.restoreCallingIdentity(identity);
2252 }
Svetoslav64fad262015-04-14 14:35:21 -07002253 }
2254
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002256 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2257 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002258 if (!TextUtils.isEmpty(callingPackage)) {
2259 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2261 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002262 return "";
2263 }
2264 }
2265
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002266 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2267 // registered cell info, so return a NULL country instead.
2268 final long identity = Binder.clearCallingIdentity();
2269 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002270 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2271 // Get default phone in this case.
2272 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2273 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002274 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002275 // Todo: fix this when we can get the actual cellular network info when the device
2276 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002277 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002278 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2279 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002280 return "";
2281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282 Phone phone = PhoneFactory.getPhone(phoneId);
2283 if (phone != null) {
2284 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002285 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286 if (sst != null) {
2287 LocaleTracker lt = sst.getLocaleTracker();
2288 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002289 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2290 return lt.getCurrentCountry();
2291 } else if (emergencyNumberTracker != null) {
2292 return emergencyNumberTracker.getEmergencyCountryIso();
2293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294 }
2295 }
2296 }
2297 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002298 } finally {
2299 Binder.restoreCallingIdentity(identity);
2300 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002301 }
2302
2303 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002305 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002306 }
2307
Sanket Padawe356d7632015-06-22 14:03:32 -07002308 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002309 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 mApp.enforceCallingOrSelfPermission(
2311 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002312
2313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 final Phone phone = getPhone(subId);
2316 if (phone != null) {
2317 phone.enableLocationUpdates();
2318 }
2319 } finally {
2320 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 }
2323
2324 @Override
2325 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002326 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002327 }
2328
Sanket Padawe356d7632015-06-22 14:03:32 -07002329 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002330 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 mApp.enforceCallingOrSelfPermission(
2332 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002333
2334 final long identity = Binder.clearCallingIdentity();
2335 try {
2336 final Phone phone = getPhone(subId);
2337 if (phone != null) {
2338 phone.disableLocationUpdates();
2339 }
2340 } finally {
2341 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 }
2344
Nathan Harold31d7ff32018-10-15 20:20:30 -07002345 /**
2346 * Returns the target SDK version number for a given package name.
2347 *
Nathan Haroldec184742019-07-10 17:04:16 -07002348 * This call MUST be invoked before clearing the calling UID.
2349 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002350 * @return target SDK if the package is found or INT_MAX.
2351 */
2352 private int getTargetSdk(String packageName) {
2353 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002354 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002355 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002356 if (ai != null) return ai.targetSdkVersion;
2357 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002358 loge("Failed to get package info for pkg="
2359 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002360 }
2361 return Integer.MAX_VALUE;
2362 }
2363
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 @Override
2365 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002366 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2367 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002368 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002369 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2370 throw new SecurityException(
2371 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2372 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002373
Jordan Liu1617b712019-07-10 15:06:26 -07002374 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2376 return null;
2377 }
Svetoslav64fad262015-04-14 14:35:21 -07002378
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002379 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002381 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002382 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383
Nathan Haroldf180aac2018-06-01 18:43:55 -07002384 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2385 for (CellInfo ci : info) {
2386 if (ci instanceof CellInfoGsm) {
2387 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2388 } else if (ci instanceof CellInfoWcdma) {
2389 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002392 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 }
2394
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002395 private List<CellInfo> getCachedCellInfo() {
2396 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2397 for (Phone phone : PhoneFactory.getPhones()) {
2398 List<CellInfo> info = phone.getAllCellInfo();
2399 if (info != null) cellInfos.addAll(info);
2400 }
2401 return cellInfos;
2402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403
2404 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002405 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002406 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002407 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002408
2409 LocationAccessPolicy.LocationPermissionResult locationResult =
2410 LocationAccessPolicy.checkLocationPermission(mApp,
2411 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2412 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002413 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002414 .setCallingPid(Binder.getCallingPid())
2415 .setCallingUid(Binder.getCallingUid())
2416 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002417 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002418 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2419 .build());
2420 switch (locationResult) {
2421 case DENIED_HARD:
2422 throw new SecurityException("Not allowed to access cell info");
2423 case DENIED_SOFT:
2424 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 }
2426
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002427 final int targetSdk = getTargetSdk(callingPackage);
2428 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2429 return getCachedCellInfo();
2430 }
2431
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002432 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002433 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434 final long identity = Binder.clearCallingIdentity();
2435 try {
2436 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2437 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002438 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002439 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440 if (info != null) cellInfos.addAll(info);
2441 }
2442 return cellInfos;
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446 }
2447
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002448 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002449 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2450 String callingFeatureId) {
2451 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2452 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002453 }
2454
2455 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002456 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2457 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002458 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002459 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002460 }
2461
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002462 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2463 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002464 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002465 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002466
2467 LocationAccessPolicy.LocationPermissionResult locationResult =
2468 LocationAccessPolicy.checkLocationPermission(mApp,
2469 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2470 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002471 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002472 .setCallingPid(Binder.getCallingPid())
2473 .setCallingUid(Binder.getCallingUid())
2474 .setMethod("requestCellInfoUpdate")
2475 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2476 .build());
2477 switch (locationResult) {
2478 case DENIED_HARD:
2479 throw new SecurityException("Not allowed to access cell info");
2480 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002481 try {
2482 cb.onCellInfo(new ArrayList<CellInfo>());
2483 } catch (RemoteException re) {
2484 // Drop without consequences
2485 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002486 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002487 }
2488
Nathan Harolda939a962019-05-09 10:13:47 -07002489
2490 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002491 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2492
2493 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2494 }
2495
2496 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002498 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002499 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500
2501 final long identity = Binder.clearCallingIdentity();
2502 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002503 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504 } finally {
2505 Binder.restoreCallingIdentity(identity);
2506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 }
2508
Shishir Agrawala9f32182016-04-12 12:00:16 -07002509 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002510 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002511 Phone phone = PhoneFactory.getPhone(slotIndex);
2512 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002513 return null;
2514 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002515 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002516 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002517 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002518 return null;
2519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002520
2521 final long identity = Binder.clearCallingIdentity();
2522 try {
2523 return phone.getImei();
2524 } finally {
2525 Binder.restoreCallingIdentity(identity);
2526 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002527 }
2528
2529 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002530 public String getTypeAllocationCodeForSlot(int slotIndex) {
2531 Phone phone = PhoneFactory.getPhone(slotIndex);
2532 String tac = null;
2533 if (phone != null) {
2534 String imei = phone.getImei();
2535 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2536 }
2537 return tac;
2538 }
2539
2540 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002541 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002542 Phone phone = PhoneFactory.getPhone(slotIndex);
2543 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002544 return null;
2545 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002546
Jeff Davidson913390f2018-02-23 17:11:49 -08002547 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002548 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002549 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002550 return null;
2551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 return phone.getMeid();
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
2558 }
Jack Yu2af8d712017-03-15 17:14:14 -07002559 }
2560
2561 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002562 public String getManufacturerCodeForSlot(int slotIndex) {
2563 Phone phone = PhoneFactory.getPhone(slotIndex);
2564 String manufacturerCode = null;
2565 if (phone != null) {
2566 String meid = phone.getMeid();
2567 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2568 }
2569 return manufacturerCode;
2570 }
2571
2572 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002573 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2574 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002575 Phone phone = PhoneFactory.getPhone(slotIndex);
2576 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002577 return null;
2578 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002579 int subId = phone.getSubId();
2580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002581 mApp, subId, callingPackage, callingFeatureId,
2582 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002583 return null;
2584 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585
2586 final long identity = Binder.clearCallingIdentity();
2587 try {
2588 return phone.getDeviceSvn();
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002592 }
2593
fionaxu43304da2017-11-27 22:51:16 -08002594 @Override
2595 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 final Phone phone = getPhone(subId);
2599 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
2602 }
fionaxu43304da2017-11-27 22:51:16 -08002603 }
2604
2605 @Override
2606 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 final Phone phone = getPhone(subId);
2610 return phone == null ? null : phone.getCarrierName();
2611 } finally {
2612 Binder.restoreCallingIdentity(identity);
2613 }
fionaxu43304da2017-11-27 22:51:16 -08002614 }
2615
calvinpanffe225e2018-11-01 19:43:06 +08002616 @Override
chen xu0026ca62019-03-06 15:28:50 -08002617 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 final Phone phone = getPhone(subId);
2621 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002622 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002623 } finally {
2624 Binder.restoreCallingIdentity(identity);
2625 }
2626 }
2627
2628 @Override
chen xu0026ca62019-03-06 15:28:50 -08002629 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002633 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002634 } finally {
2635 Binder.restoreCallingIdentity(identity);
2636 }
2637 }
2638
chen xu651eec72018-11-11 19:03:44 -08002639 @Override
chen xu864e11c2018-12-06 22:10:03 -08002640 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2641 if (!isSubscriptionMccMnc) {
2642 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2643 }
chen xu651eec72018-11-11 19:03:44 -08002644 final Phone phone = PhoneFactory.getPhone(slotIndex);
2645 if (phone == null) {
2646 return TelephonyManager.UNKNOWN_CARRIER_ID;
2647 }
2648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2651 } finally {
2652 Binder.restoreCallingIdentity(identity);
2653 }
2654 }
2655
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656 //
2657 // Internal helper methods.
2658 //
2659
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002660 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2662 *
2663 * @throws SecurityException if the caller does not have the required permission
2664 */
2665 private void enforceModifyPermission() {
2666 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2667 }
2668
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002669 /**
2670 * Make sure the caller is system.
2671 *
2672 * @throws SecurityException if the caller is not system.
2673 */
2674 private void enforceSystemCaller() {
2675 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2676 throw new SecurityException("Caller must be system");
2677 }
2678 }
2679
Shuo Qianf2b2df42019-11-13 17:43:31 -08002680 private void enforceActiveEmergencySessionPermission() {
2681 mApp.enforceCallingOrSelfPermission(
2682 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2683 }
2684
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 /**
2686 * Make sure the caller has the CALL_PHONE permission.
2687 *
2688 * @throws SecurityException if the caller does not have the required permission
2689 */
2690 private void enforceCallPermission() {
2691 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2692 }
2693
paulhu423b5f22019-08-23 19:17:33 +08002694 private void enforceSettingsPermission() {
2695 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002696 }
2697
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 private String createTelUrl(String number) {
2699 if (TextUtils.isEmpty(number)) {
2700 return null;
2701 }
2702
Jake Hambye994d462014-02-03 13:10:13 -08002703 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 }
2705
Ihab Awadf9e92732013-12-05 18:02:52 -08002706 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2708 }
2709
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002710 private static void logv(String msg) {
2711 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2712 }
2713
Ihab Awadf9e92732013-12-05 18:02:52 -08002714 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2716 }
2717
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002718 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002719 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002720 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002721 }
2722
Sanket Padawe356d7632015-06-22 14:03:32 -07002723 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002724 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 final Phone phone = PhoneFactory.getPhone(slotIndex);
2728 if (phone == null) {
2729 return PhoneConstants.PHONE_TYPE_NONE;
2730 } else {
2731 return phone.getPhoneType();
2732 }
2733 } finally {
2734 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 }
2737
2738 /**
2739 * Returns the CDMA ERI icon index to display
2740 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002741 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002742 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2743 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2744 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002745 }
2746
Sanket Padawe356d7632015-06-22 14:03:32 -07002747 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002748 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2749 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002750 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002751 mApp, subId, callingPackage, callingFeatureId,
2752 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002753 return -1;
2754 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755
2756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 final Phone phone = getPhone(subId);
2759 if (phone != null) {
2760 return phone.getCdmaEriIconIndex();
2761 } else {
2762 return -1;
2763 }
2764 } finally {
2765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002767 }
2768
2769 /**
2770 * Returns the CDMA ERI icon mode,
2771 * 0 - ON
2772 * 1 - FLASHING
2773 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002774 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002775 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2776 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2777 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002778 }
2779
Sanket Padawe356d7632015-06-22 14:03:32 -07002780 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002781 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2782 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002784 mApp, subId, callingPackage, callingFeatureId,
2785 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002786 return -1;
2787 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788
2789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 final Phone phone = getPhone(subId);
2792 if (phone != null) {
2793 return phone.getCdmaEriIconMode();
2794 } else {
2795 return -1;
2796 }
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002800 }
2801
2802 /**
2803 * Returns the CDMA ERI text,
2804 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002805 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002806 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2807 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2808 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002809 }
2810
Sanket Padawe356d7632015-06-22 14:03:32 -07002811 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002812 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2813 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002815 mApp, subId, callingPackage, callingFeatureId,
2816 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002817 return null;
2818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 final Phone phone = getPhone(subId);
2823 if (phone != null) {
2824 return phone.getCdmaEriText();
2825 } else {
2826 return null;
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 }
2832
2833 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002834 * Returns the CDMA MDN.
2835 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002837 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2839 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002844 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 return phone.getLine1Number();
2846 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002847 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 return null;
2849 }
2850 } finally {
2851 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002852 }
2853 }
2854
2855 /**
2856 * Returns the CDMA MIN.
2857 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002859 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2861 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862
2863 final long identity = Binder.clearCallingIdentity();
2864 try {
2865 final Phone phone = getPhone(subId);
2866 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2867 return phone.getCdmaMin();
2868 } else {
2869 return null;
2870 }
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002873 }
2874 }
2875
Hall Liud892bec2018-11-30 14:51:45 -08002876 @Override
2877 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2878 INumberVerificationCallback callback, String callingPackage) {
2879 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2880 != PERMISSION_GRANTED) {
2881 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2882 }
2883 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2884
2885 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2886 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2887 throw new SecurityException("Calling package must be configured in the device config");
2888 }
2889
2890 if (range == null) {
2891 throw new NullPointerException("Range must be non-null");
2892 }
2893
2894 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002895 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002896
2897 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2898 }
2899
Junda Liuca05d5d2014-08-14 22:36:34 -07002900 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 * Returns true if CDMA provisioning needs to run.
2902 */
2903 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904 final long identity = Binder.clearCallingIdentity();
2905 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002906 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 } finally {
2908 Binder.restoreCallingIdentity(identity);
2909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 }
2911
2912 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002913 * Sets the voice mail number of a given subId.
2914 */
2915 @Override
2916 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002917 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2918 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919
2920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2923 new Pair<String, String>(alphaTag, number), new Integer(subId));
2924 return success;
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
2927 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002928 }
2929
Ta-wei Yen87c49842016-05-13 21:19:52 -07002930 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002931 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2932 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002933 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2934 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002935 if (!TextUtils.equals(callingPackage, systemDialer)) {
2936 throw new SecurityException("caller must be system dialer");
2937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938
2939 final long identity = Binder.clearCallingIdentity();
2940 try {
2941 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2942 if (phoneAccountHandle == null) {
2943 return null;
2944 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002945 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 } finally {
2947 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002948 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002949 }
2950
2951 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002952 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2953 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002954 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002956 mApp, subId, callingPackage, callingFeatureId,
2957 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002958 return null;
2959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002961 final long identity = Binder.clearCallingIdentity();
2962 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002963 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002967 }
2968
2969 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002970 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2971 VisualVoicemailSmsFilterSettings settings) {
2972 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002973
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002977 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002981 }
2982
2983 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002984 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2985 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986
2987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002990 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002994 }
2995
2996 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002997 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2998 String callingPackage, int subId) {
2999 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003008 }
3009
3010 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003011 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003012 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003017 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 } finally {
3019 Binder.restoreCallingIdentity(identity);
3020 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003021 }
3022
3023 @Override
3024 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3025 String number, int port, String text, PendingIntent sentIntent) {
3026 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003027 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003028 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003029 SmsController smsController = PhoneFactory.getSmsController();
3030 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3031 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003032 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003033
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003034 /**
fionaxu0152e512016-11-14 13:36:14 -08003035 * Sets the voice activation state of a given subId.
3036 */
3037 @Override
3038 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3040 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 final Phone phone = getPhone(subId);
3045 if (phone != null) {
3046 phone.setVoiceActivationState(activationState);
3047 } else {
3048 loge("setVoiceActivationState fails with invalid subId: " + subId);
3049 }
3050 } finally {
3051 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003052 }
3053 }
3054
3055 /**
3056 * Sets the data activation state of a given subId.
3057 */
3058 @Override
3059 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3061 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062
3063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 final Phone phone = getPhone(subId);
3066 if (phone != null) {
3067 phone.setDataActivationState(activationState);
3068 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003069 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003070 }
3071 } finally {
3072 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003073 }
3074 }
3075
3076 /**
3077 * Returns the voice activation state of a given subId.
3078 */
3079 @Override
3080 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003081 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082
fionaxu0152e512016-11-14 13:36:14 -08003083 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 if (phone != null) {
3087 return phone.getVoiceActivationState();
3088 } else {
3089 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3090 }
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003093 }
3094 }
3095
3096 /**
3097 * Returns the data activation state of a given subId.
3098 */
3099 @Override
3100 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003101 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102
fionaxu0152e512016-11-14 13:36:14 -08003103 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 if (phone != null) {
3107 return phone.getDataActivationState();
3108 } else {
3109 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3110 }
3111 } finally {
3112 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003113 }
3114 }
3115
3116 /**
Wink Saville36469e72014-06-11 15:17:00 -07003117 * Returns the unread count of voicemails for a subId
3118 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003119 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003120 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3121 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003123 mApp, subId, callingPackage, callingFeatureId,
3124 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003125 return 0;
3126 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003127 final long identity = Binder.clearCallingIdentity();
3128 try {
3129 final Phone phone = getPhone(subId);
3130 if (phone != null) {
3131 return phone.getVoiceMessageCount();
3132 } else {
3133 return 0;
3134 }
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003138 }
3139
3140 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003141 * returns true, if the device is in a state where both voice and data
3142 * are supported simultaneously. This can change based on location or network condition.
3143 */
3144 @Override
3145 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 final Phone phone = getPhone(subId);
3149 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003153 }
3154
3155 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003156 * Send the dialer code if called from the current default dialer or the caller has
3157 * carrier privilege.
3158 * @param inputCode The dialer code to send
3159 */
3160 @Override
3161 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003162 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003163 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003164 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3165 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003166 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003167 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003168 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003169 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003170
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003173 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
fionaxu235cc5e2017-03-06 22:25:57 -08003177 }
3178
Pengquan Menga1bb6272018-09-06 09:59:22 -07003179 @Override
3180 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003181 TelephonyPermissions
3182 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3183 mApp, subId, "getNetworkSelectionMode");
3184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 if (!isActiveSubscription(subId)) {
3187 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3188 }
3189 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3190 } finally {
3191 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003192 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003193 }
3194
Brad Ebinger35c841c2018-10-01 10:40:55 -07003195 @Override
Sarah Chin5f0ecd72019-12-06 10:24:18 -08003196 public PhoneCapability getPhoneCapability(int subId, String callingPackage,
3197 String callingFeatureId) {
3198 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3199 mApp, subId, callingPackage, callingFeatureId, "getPhoneCapability")) {
3200 return null;
3201 }
3202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 return mPhoneConfigurationManager.getStaticPhoneCapability();
3205 } finally {
3206 Binder.restoreCallingIdentity(identity);
3207 }
3208 }
3209
3210 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003211 public boolean isInEmergencySmsMode() {
3212 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
3215 for (Phone phone : PhoneFactory.getPhones()) {
3216 if (phone.isInEmergencySmsMode()) {
3217 return true;
3218 }
3219 }
3220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
3223 return false;
3224 }
3225
shilu366312e2019-12-17 09:28:10 -08003226 /**
3227 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3228 * @param subId The subscription to use to check the configuration.
3229 * @param c The callback that will be used to send the result.
3230 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003231 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003232 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3233 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003234 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3235 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003236
Brad Ebinger77b832e2019-10-17 17:03:22 -07003237 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3238 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3239 "IMS not available on device.");
3240 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 final long token = Binder.clearCallingIdentity();
3242 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003243 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003244 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003246 } catch (ImsException e) {
3247 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 } finally {
3249 Binder.restoreCallingIdentity(token);
3250 }
3251 }
3252
shilu366312e2019-12-17 09:28:10 -08003253 /**
3254 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3255 * @param subId The subscription to use to check the configuration.
3256 * @param c The callback that will be used to send the result.
3257 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003258 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003259 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003260 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3261 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003262 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3263 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3264 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003265 final long token = Binder.clearCallingIdentity();
3266 try {
3267 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3268 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3269 .removeRegistrationCallbackForSubscription(c, subId);
3270 } catch (ImsException e) {
3271 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3272 + "is inactive, ignoring unregister.");
3273 // If the subscription is no longer active, just return, since the callback
3274 // will already have been removed internally.
3275 } finally {
3276 Binder.restoreCallingIdentity(token);
3277 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 }
3279
Brad Ebinger774ba362019-10-22 17:36:18 -07003280 /**
3281 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3282 */
3283 @Override
3284 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3285 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3286 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3287 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3288 "IMS not available on device.");
3289 }
3290 final long token = Binder.clearCallingIdentity();
3291 try {
3292 Phone phone = getPhone(subId);
3293 if (phone == null) {
3294 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3295 + subId + "'");
3296 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3297 }
3298 phone.getImsRegistrationState(regState -> {
3299 try {
3300 consumer.accept((regState == null)
3301 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3302 } catch (RemoteException e) {
3303 // Ignore if the remote process is no longer available to call back.
3304 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3305 }
3306 });
3307 } finally {
3308 Binder.restoreCallingIdentity(token);
3309 }
3310 }
3311
3312 /**
3313 * Get the transport type for the IMS service registration state.
3314 */
3315 @Override
3316 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003317 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3318 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003319 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3320 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3321 "IMS not available on device.");
3322 }
3323 final long token = Binder.clearCallingIdentity();
3324 try {
3325 Phone phone = getPhone(subId);
3326 if (phone == null) {
3327 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3328 + subId + "'");
3329 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3330 }
3331 phone.getImsRegistrationTech(regTech -> {
3332 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3333 int regTechConverted = (regTech == null)
3334 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3335 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3336 regTechConverted);
3337 try {
3338 consumer.accept(regTechConverted);
3339 } catch (RemoteException e) {
3340 // Ignore if the remote process is no longer available to call back.
3341 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3342 }
3343 });
3344 } finally {
3345 Binder.restoreCallingIdentity(token);
3346 }
3347 }
3348
shilu366312e2019-12-17 09:28:10 -08003349 /**
3350 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3351 * @param subId The subscription to use to check the configuration.
3352 * @param c The callback that will be used to send the result.
3353 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003354 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003355 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3356 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003357 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3358 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003359 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3360 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3361 "IMS not available on device.");
3362 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3364 final long token = Binder.clearCallingIdentity();
3365 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003366 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003367 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003368 } catch (ImsException e) {
3369 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003370 } finally {
3371 Binder.restoreCallingIdentity(token);
3372 }
3373 }
3374
shilu366312e2019-12-17 09:28:10 -08003375 /**
3376 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3377 * @param subId The subscription to use to check the configuration.
3378 * @param c The callback that will be used to send the result.
3379 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003381 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003382 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3383 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003384 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3385 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3386 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003387
3388 final long token = Binder.clearCallingIdentity();
3389 try {
3390 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3391 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003392 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003393 } catch (ImsException e) {
3394 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3395 + "is inactive, ignoring unregister.");
3396 // If the subscription is no longer active, just return, since the callback
3397 // will already have been removed internally.
3398 } finally {
3399 Binder.restoreCallingIdentity(token);
3400 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003401 }
3402
3403 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003404 public boolean isCapable(int subId, int capability, int regTech) {
3405 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003406 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3407 final long token = Binder.clearCallingIdentity();
3408 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003409 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003411 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3413 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003414 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003415 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3416 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003417 } finally {
3418 Binder.restoreCallingIdentity(token);
3419 }
3420 }
3421
3422 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003423 public boolean isAvailable(int subId, int capability, int regTech) {
3424 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003425 final long token = Binder.clearCallingIdentity();
3426 try {
3427 Phone phone = getPhone(subId);
3428 if (phone == null) return false;
3429 return phone.isImsCapabilityAvailable(capability, regTech);
3430 } finally {
3431 Binder.restoreCallingIdentity(token);
3432 }
3433 }
3434
Brad Ebinger77b832e2019-10-17 17:03:22 -07003435 /**
3436 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3437 * subscription.
3438 * @param subId The subscription to use to check the configuration.
3439 * @param callback The callback that will be used to send the result.
3440 * @param capability The MmTelFeature capability that will be used to send the result.
3441 * @param transportType The transport type of the MmTelFeature capability.
3442 */
3443 @Override
3444 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3445 int transportType) {
3446 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3447 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3448 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3449 "IMS not available on device.");
3450 }
3451 final long token = Binder.clearCallingIdentity();
3452 try {
3453 int slotId = getSlotIndex(subId);
3454 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3455 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3456 + subId + "'");
3457 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3458 }
3459 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3460 transportType, aBoolean -> {
3461 try {
3462 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3463 } catch (RemoteException e) {
3464 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3465 + "running. Ignore");
3466 }
3467 });
3468 } finally {
3469 Binder.restoreCallingIdentity(token);
3470 }
3471 }
3472
shilu366312e2019-12-17 09:28:10 -08003473 /**
3474 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3475 * @param subId The subscription to use to check the configuration.
3476 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003477 @Override
3478 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003479 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3480 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003481
Brad Ebinger35c841c2018-10-01 10:40:55 -07003482 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3483 final long token = Binder.clearCallingIdentity();
3484 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003485 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003486 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003487 } catch (ImsException e) {
3488 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003489 } finally {
3490 Binder.restoreCallingIdentity(token);
3491 }
3492 }
3493
3494 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003495 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003497 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003498 final long identity = Binder.clearCallingIdentity();
3499 try {
3500 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003501 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003503 } catch (ImsException e) {
3504 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 } finally {
3506 Binder.restoreCallingIdentity(identity);
3507 }
3508 }
3509
shilu366312e2019-12-17 09:28:10 -08003510 /**
3511 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3512 * @param subId The subscription to use to check the configuration.
3513 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003515 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003516 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3517 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 final long identity = Binder.clearCallingIdentity();
3519 try {
3520 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003521 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3522 } catch (ImsException e) {
3523 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003524 } finally {
3525 Binder.restoreCallingIdentity(identity);
3526 }
3527 }
3528
3529 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003530 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003532 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003536 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003537 } catch (ImsException e) {
3538 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003539 } finally {
3540 Binder.restoreCallingIdentity(identity);
3541 }
3542 }
3543
shilu366312e2019-12-17 09:28:10 -08003544 /**
3545 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3546 * @param subId The subscription to use to check the configuration.
3547 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 @Override
3549 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003550 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3551 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003555 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003556 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003557 } catch (ImsException e) {
3558 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003559 } finally {
3560 Binder.restoreCallingIdentity(identity);
3561 }
3562 }
3563
3564 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003565 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003567 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003571 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003572 } catch (ImsException e) {
3573 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003574 } finally {
3575 Binder.restoreCallingIdentity(identity);
3576 }
3577 }
3578
shilu366312e2019-12-17 09:28:10 -08003579 /**
3580 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3581 * @param subId The subscription to use to check the configuration.
3582 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 @Override
3584 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003585 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3586 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003590 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003591 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003592 } catch (ImsException e) {
3593 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003594 } finally {
3595 Binder.restoreCallingIdentity(identity);
3596 }
3597 }
3598
3599 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003600 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003602 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003606 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003608 } catch (ImsException e) {
3609 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 } finally {
3611 Binder.restoreCallingIdentity(identity);
3612 }
3613 }
3614
3615 @Override
3616 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3618 "setVoWiFiNonPersistent");
3619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003622 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003623 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003624 } catch (ImsException e) {
3625 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003626 } finally {
3627 Binder.restoreCallingIdentity(identity);
3628 }
3629 }
3630
shilu366312e2019-12-17 09:28:10 -08003631 /**
3632 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3633 * @param subId The subscription to use to check the configuration.
3634 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003635 @Override
3636 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003637 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3638 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003642 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003644 } catch (ImsException e) {
3645 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003646 } finally {
3647 Binder.restoreCallingIdentity(identity);
3648 }
3649 }
3650
3651 @Override
3652 public void setVoWiFiModeSetting(int subId, int mode) {
3653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3654 "setVoWiFiModeSetting");
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003658 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003660 } catch (ImsException e) {
3661 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
3665 }
3666
3667 @Override
3668 public int getVoWiFiRoamingModeSetting(int subId) {
3669 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003673 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003674 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003675 } catch (ImsException e) {
3676 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
3680 }
3681
3682 @Override
3683 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3685 "setVoWiFiRoamingModeSetting");
3686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003689 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003690 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003691 } catch (ImsException e) {
3692 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
3696 }
3697
3698 @Override
3699 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3701 "setRttCapabilityEnabled");
3702 final long identity = Binder.clearCallingIdentity();
3703 try {
3704 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003705 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3706 } catch (ImsException e) {
3707 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
3711 }
3712
shilu366312e2019-12-17 09:28:10 -08003713 /**
3714 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3715 * @param subId The subscription to use to check the configuration.
3716 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 @Override
3718 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003719 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3720 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 final long identity = Binder.clearCallingIdentity();
3722 try {
3723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003724 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003726 } catch (ImsException e) {
3727 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003728 } finally {
3729 Binder.restoreCallingIdentity(identity);
3730 }
3731 }
3732
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003733 @Override
3734 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3735 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003738 if (!isImsAvailableOnDevice()) {
3739 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3740 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003741 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003742 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003743 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003744 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003745 } catch (ImsException e) {
3746 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
3750 }
3751
3752 @Override
3753 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3754 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3755 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003756 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3757 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3758 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003759 try {
3760 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003761 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003762 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003763 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003764 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3765 + "is inactive, ignoring unregister.");
3766 // If the subscription is no longer active, just return, since the callback will already
3767 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003768 } finally {
3769 Binder.restoreCallingIdentity(identity);
3770 }
3771 }
3772
allenwtsu99c623b2020-01-03 18:24:23 +08003773
3774 private void checkModifyPhoneStatePermission(int subId, String message) {
3775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3776 message);
3777 }
3778
3779 private boolean isImsProvisioningRequired(int subId, int capability,
3780 boolean isMmtelCapability) {
3781 Phone phone = getPhone(subId);
3782 if (phone == null) {
3783 loge("phone instance null for subid " + subId);
3784 return false;
3785 }
3786 if (isMmtelCapability) {
3787 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3788 return false;
3789 }
3790 } else {
3791 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3792 return false;
3793 }
3794 }
3795 return true;
3796 }
3797
3798 @Override
3799 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3800 boolean isProvisioned) {
3801 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3802
3803 final long identity = Binder.clearCallingIdentity();
3804 try {
3805 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3806 if (!isImsProvisioningRequired(subId, capability, false)) {
3807 return;
3808 }
3809
3810 // this capability requires provisioning, route to the correct API.
3811 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3812 switch (capability) {
3813 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3814 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3815 ims.setEabProvisioned(isProvisioned);
3816 break;
3817 default: {
3818 throw new IllegalArgumentException("Tried to set provisioning for "
3819 + "rcs capability '" + capability + "', which does not require "
3820 + "provisioning.");
3821 }
3822 }
3823 } finally {
3824 Binder.restoreCallingIdentity(identity);
3825 }
3826
3827 }
3828
3829
3830 @Override
3831 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3832 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3836 if (!isImsProvisioningRequired(subId, capability, false)) {
3837 return true;
3838 }
3839
3840 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3841 switch (capability) {
3842 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3843 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3844 return ims.isEabProvisionedOnDevice();
3845
3846 default: {
3847 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3848 + "capability '" + capability + "', which does not require "
3849 + "provisioning.");
3850 }
3851 }
3852
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
3855 }
3856 }
3857
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003858 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003859 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3860 boolean isProvisioned) {
3861 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3862 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3863 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3864 }
allenwtsu99c623b2020-01-03 18:24:23 +08003865 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003869 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003870 return;
3871 }
3872
3873 // this capability requires provisioning, route to the correct API.
3874 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3875 switch (capability) {
3876 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3877 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3878 ims.setVolteProvisioned(isProvisioned);
3879 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3880 ims.setWfcProvisioned(isProvisioned);
3881 }
3882 break;
3883 }
3884 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3885 // There is currently no difference in VT provisioning type.
3886 ims.setVtProvisioned(isProvisioned);
3887 break;
3888 }
3889 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3890 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3891 // change the capability of the feature instead if needed.
3892 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3893 == isProvisioned) {
3894 // No change in provisioning.
3895 return;
3896 }
3897 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3898 try {
3899 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003900 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003901 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3902 + ", Exception" + e.getMessage());
3903 }
3904 break;
3905 }
3906 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003907 throw new IllegalArgumentException("Tried to set provisioning for "
3908 + "MmTel capability '" + capability + "', which does not require "
3909 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003910 }
3911 }
3912
3913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
3916 }
3917
3918 @Override
3919 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3920 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3921 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3922 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3923 }
3924 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3925 final long identity = Binder.clearCallingIdentity();
3926 try {
3927 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003928 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003929 return true;
3930 }
3931
3932 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3933 switch (capability) {
3934 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3935 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3936 return ims.isVolteProvisionedOnDevice();
3937 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3938 return ims.isWfcProvisionedOnDevice();
3939 }
3940 // This should never happen, since we are checking tech above to make sure it
3941 // is either LTE or IWLAN.
3942 throw new IllegalArgumentException("Invalid radio technology for voice "
3943 + "capability.");
3944 }
3945 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3946 // There is currently no difference in VT provisioning type.
3947 return ims.isVtProvisionedOnDevice();
3948 }
3949 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3950 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3951 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3952 }
3953 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003954 throw new IllegalArgumentException(
3955 "Tried to get provisioning for MmTel capability '" + capability
3956 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003957 }
3958 }
3959
3960 } finally {
3961 Binder.restoreCallingIdentity(identity);
3962 }
3963 }
3964
3965 @Override
3966 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3967 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3968 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3969 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3970 }
3971 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3972 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3973 return (provisionedBits & capability) > 0;
3974 }
3975
3976 @Override
3977 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3978 boolean isProvisioned) {
3979 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3980 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3981 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3982 }
3983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3984 "setProvisioningStatusForCapability");
3985 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3986 // If the current provisioning status for capability already matches isProvisioned,
3987 // do nothing.
3988 if (((provisionedBits & capability) > 0) == isProvisioned) {
3989 return;
3990 }
3991 if (isProvisioned) {
3992 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3993 } else {
3994 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3995 }
3996 }
3997
3998 /**
3999 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4000 * technology. The bitfield should mirror the bitfield defined by
4001 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4002 */
4003 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4004 String key = getMmTelProvisioningKey(subId, tech);
4005 // Default is no capabilities are provisioned.
4006 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4007 }
4008
4009 /**
4010 * Sets the MmTel capability provisioning bitfield (defined by
4011 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4012 * technology specified.
4013 *
4014 * Note: This is a synchronous command and should not be called on UI thread.
4015 */
4016 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4017 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4018 String key = getMmTelProvisioningKey(subId, tech);
4019 editor.putInt(key, newField);
4020 editor.commit();
4021 }
4022
4023 private static String getMmTelProvisioningKey(int subId, int tech) {
4024 // resulting key is provision_ims_mmtel_{subId}_{tech}
4025 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4026 }
4027
4028 /**
4029 * Query CarrierConfig to see if the specified capability requires provisioning for the
4030 * carrier associated with the subscription id.
4031 */
4032 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4033 int capability) {
4034 CarrierConfigManager configManager = new CarrierConfigManager(context);
4035 PersistableBundle c = configManager.getConfigForSubId(subId);
4036 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004037 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004038 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4039 false);
4040 boolean requireVoiceVtProvisioning = c.getBoolean(
4041 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4042
4043 // First check to make sure that the capability requires provisioning.
4044 switch (capability) {
4045 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4046 // intentional fallthrough
4047 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4048 if (requireVoiceVtProvisioning) {
4049 // Voice and Video requires provisioning
4050 return true;
4051 }
4052 break;
4053 }
4054 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4055 if (requireUtProvisioning) {
4056 // UT requires provisioning
4057 return true;
4058 }
4059 break;
4060 }
4061 }
4062 return false;
4063 }
4064
allenwtsu99c623b2020-01-03 18:24:23 +08004065 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4066 int capability) {
4067 CarrierConfigManager configManager = new CarrierConfigManager(context);
4068 PersistableBundle c = configManager.getConfigForSubId(subId);
4069
4070 boolean requireRcsProvisioning = c.getBoolean(
4071 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4072
4073 // First check to make sure that the capability requires provisioning.
4074 switch (capability) {
4075 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4076 // intentional fallthrough
4077 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4078 if (requireRcsProvisioning) {
4079 // OPTION or PRESENCE requires provisioning
4080 return true;
4081 }
4082 break;
4083 }
4084 }
4085 return false;
4086 }
4087
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004088 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004089 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004090 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4091 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4092 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004093 enforceReadPrivilegedPermission("getImsProvisioningInt");
4094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004097 int slotId = getSlotIndex(subId);
4098 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4099 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4100 + subId + "' for key:" + key);
4101 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4102 }
4103 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004104 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004105 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4106 + subId + "' for key:" + key);
4107 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
4111 }
4112
4113 @Override
4114 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004115 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4116 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4117 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004118 enforceReadPrivilegedPermission("getImsProvisioningString");
4119 final long identity = Binder.clearCallingIdentity();
4120 try {
4121 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004122 int slotId = getSlotIndex(subId);
4123 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4124 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4125 + subId + "' for key:" + key);
4126 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4127 }
4128 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004129 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004130 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4131 + subId + "' for key:" + key);
4132 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004133 } finally {
4134 Binder.restoreCallingIdentity(identity);
4135 }
4136 }
4137
4138 @Override
4139 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004140 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4141 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4142 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4144 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004148 int slotId = getSlotIndex(subId);
4149 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4150 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4151 + subId + "' for key:" + key);
4152 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4153 }
4154 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004155 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004156 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4157 + "' for key:" + key);
4158 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
4162 }
4163
4164 @Override
4165 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004166 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4167 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4168 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4170 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004171 final long identity = Binder.clearCallingIdentity();
4172 try {
4173 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004174 int slotId = getSlotIndex(subId);
4175 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4176 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4177 + subId + "' for key:" + key);
4178 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4179 }
4180 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004181 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004182 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4183 + "' for key:" + key);
4184 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004185 } finally {
4186 Binder.restoreCallingIdentity(identity);
4187 }
4188 }
4189
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004190 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 int slotId = SubscriptionManager.getSlotIndex(subId);
4192 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004193 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4194 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 }
4196 return slotId;
4197 }
4198
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004199 private int getSlotIndex(int subId) {
4200 int slotId = SubscriptionManager.getSlotIndex(subId);
4201 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4202 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4203 }
4204 return slotId;
4205 }
4206
Wink Saville36469e72014-06-11 15:17:00 -07004207 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004208 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004209 */
4210 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004211 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4212 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004213 final int targetSdk = getTargetSdk(callingPackage);
4214 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004215 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004216 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004217 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004218 mApp, subId, callingPackage, callingFeatureId,
4219 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004220 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4221 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004223 final long identity = Binder.clearCallingIdentity();
4224 try {
4225 final Phone phone = getPhone(subId);
4226 if (phone != null) {
4227 return phone.getServiceState().getDataNetworkType();
4228 } else {
4229 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4230 }
4231 } finally {
4232 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004234 }
4235
4236 /**
4237 * Returns the data network type
4238 */
4239 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004240 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4241 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4242 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004243 }
4244
4245 /**
4246 * Returns the data network type for a subId
4247 */
4248 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004249 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4250 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004252 mApp, subId, callingPackage, callingFeatureId,
4253 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004254 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4255 }
4256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 final long identity = Binder.clearCallingIdentity();
4258 try {
4259 final Phone phone = getPhone(subId);
4260 if (phone != null) {
4261 return phone.getServiceState().getDataNetworkType();
4262 } else {
4263 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4264 }
4265 } finally {
4266 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004268 }
4269
4270 /**
Wink Saville36469e72014-06-11 15:17:00 -07004271 * Returns the Voice network type for a subId
4272 */
4273 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004274 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4275 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004277 mApp, subId, callingPackage, callingFeatureId,
4278 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004279 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4280 }
4281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282 final long identity = Binder.clearCallingIdentity();
4283 try {
4284 final Phone phone = getPhone(subId);
4285 if (phone != null) {
4286 return phone.getServiceState().getVoiceNetworkType();
4287 } else {
4288 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4289 }
4290 } finally {
4291 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004293 }
4294
4295 /**
4296 * @return true if a ICC card is present
4297 */
4298 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004299 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004300 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4301 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004302 }
4303
4304 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004305 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004306 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004307 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004308 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 final long identity = Binder.clearCallingIdentity();
4310 try {
4311 final Phone phone = PhoneFactory.getPhone(slotIndex);
4312 if (phone != null) {
4313 return phone.getIccCard().hasIccCard();
4314 } else {
4315 return false;
4316 }
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004319 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004320 }
4321
4322 /**
4323 * Return if the current radio is LTE on CDMA. This
4324 * is a tri-state return value as for a period of time
4325 * the mode may be unknown.
4326 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004327 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004328 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004329 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004330 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004331 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004332 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4333 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4334 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004335 }
4336
Sanket Padawe356d7632015-06-22 14:03:32 -07004337 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004338 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4339 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004340 try {
4341 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4342 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004343 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4344 }
4345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346 final long identity = Binder.clearCallingIdentity();
4347 try {
4348 final Phone phone = getPhone(subId);
4349 if (phone == null) {
4350 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4351 } else {
4352 return phone.getLteOnCdmaMode();
4353 }
4354 } finally {
4355 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004356 }
Wink Saville36469e72014-06-11 15:17:00 -07004357 }
4358
Wink Saville36469e72014-06-11 15:17:00 -07004359 /**
4360 * {@hide}
4361 * Returns Default subId, 0 in the case of single standby.
4362 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004363 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004364 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004365 }
4366
Shishir Agrawala9f32182016-04-12 12:00:16 -07004367 private int getSlotForDefaultSubscription() {
4368 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4369 }
4370
Wink Savilleb564aae2014-10-23 10:18:09 -07004371 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004372 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004373 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004374
Pengquan Menge92a50d2018-09-21 15:54:48 -07004375 private boolean isActiveSubscription(int subId) {
4376 return mSubscriptionController.isActiveSubId(subId);
4377 }
4378
Ihab Awadf2177b72013-11-25 13:33:23 -08004379 /**
4380 * @see android.telephony.TelephonyManager.WifiCallingChoices
4381 */
4382 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004383 final long identity = Binder.clearCallingIdentity();
4384 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004385 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004386 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4387 getWhenToMakeWifiCallsDefaultPreference());
4388 } finally {
4389 Binder.restoreCallingIdentity(identity);
4390 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004391 }
4392
4393 /**
4394 * @see android.telephony.TelephonyManager.WifiCallingChoices
4395 */
4396 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397 final long identity = Binder.clearCallingIdentity();
4398 try {
4399 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004400 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004405 }
4406
Sailesh Nepald1e68152013-12-12 19:08:02 -08004407 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004408 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004409 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004410 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004411
Jordan Liu4c733742019-02-28 12:03:40 -08004412 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4413 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4414 if (phoneId == -1) {
4415 throw new IllegalArgumentException("Given slot index: " + slotIndex
4416 + " does not correspond to an active phone");
4417 }
4418 return PhoneFactory.getPhone(phoneId);
4419 }
4420
Shishir Agrawal566b7612013-10-28 14:41:00 -07004421 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004422 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4423 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4425 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004427 if (DBG) {
4428 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4429 }
4430 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4431 p2);
4432 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004433
Jordan Liu4c733742019-02-28 12:03:40 -08004434
4435 @Override
4436 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4437 int slotIndex, String callingPackage, String aid, int p2) {
4438 enforceModifyPermission();
4439 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4440 if (DBG) {
4441 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4442 }
4443 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4444 callingPackage, aid, p2);
4445 }
4446
4447 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4448 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 final long identity = Binder.clearCallingIdentity();
4450 try {
4451 if (TextUtils.equals(ISDR_AID, aid)) {
4452 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004453 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4454 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 if (bestComponent == null
4456 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4457 loge("The calling package is not allowed to access ISD-R.");
4458 throw new SecurityException(
4459 "The calling package is not allowed to access ISD-R.");
4460 }
Derek Tan740e1672017-06-27 14:56:27 -07004461 }
Derek Tan740e1672017-06-27 14:56:27 -07004462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004463 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004464 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4465 null /* workSource */);
4466 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004467 return response;
4468 } finally {
4469 Binder.restoreCallingIdentity(identity);
4470 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004471 }
4472
4473 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004474 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4476 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004477 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4478 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4479 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004480
Jordan Liu4c733742019-02-28 12:03:40 -08004481 @Override
4482 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4483 enforceModifyPermission();
4484 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4485 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4486 channel);
4487 }
4488
4489 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490 final long identity = Binder.clearCallingIdentity();
4491 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 if (channel < 0) {
4493 return false;
4494 }
Jordan Liu4c733742019-02-28 12:03:40 -08004495 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4496 null /* workSource */);
4497 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 return success;
4499 } finally {
4500 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004501 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004502 }
4503
4504 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004505 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004506 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4508 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004509 if (DBG) {
4510 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4511 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4512 + p3 + " data=" + data);
4513 }
4514 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4515 command, p1, p2, p3, data);
4516 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004517
Jordan Liu4c733742019-02-28 12:03:40 -08004518 @Override
4519 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4520 int command, int p1, int p2, int p3, String data) {
4521 enforceModifyPermission();
4522 if (DBG) {
4523 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4524 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4525 + p3 + " data=" + data);
4526 }
4527 return iccTransmitApduLogicalChannelWithPermission(
4528 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4529 data);
4530 }
4531
4532 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4533 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 final long identity = Binder.clearCallingIdentity();
4535 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004536 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537 return "";
4538 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004541 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4542 null /* workSource */);
4543 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004545 // Append the returned status code to the end of the response payload.
4546 String s = Integer.toHexString(
4547 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4548 if (response.payload != null) {
4549 s = IccUtils.bytesToHexString(response.payload) + s;
4550 }
4551 return s;
4552 } finally {
4553 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004554 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004555 }
Jake Hambye994d462014-02-03 13:10:13 -08004556
Evan Charltonc66da362014-05-16 14:06:40 -07004557 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004558 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4559 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4561 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004562 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004563 if (DBG) {
4564 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4565 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4566 }
4567 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4568 cla, command, p1, p2, p3, data);
4569 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004570
Jordan Liu4c733742019-02-28 12:03:40 -08004571 @Override
4572 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4573 int command, int p1, int p2, int p3, String data) {
4574 enforceModifyPermission();
4575 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4576 if (DBG) {
4577 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4578 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4579 + " data=" + data);
4580 }
4581
4582 return iccTransmitApduBasicChannelWithPermission(
4583 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4584 p2, p3, data);
4585 }
4586
4587 // open APDU basic channel assuming the caller has sufficient permissions
4588 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4589 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4593 && TextUtils.equals(ISDR_AID, data)) {
4594 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004595 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4596 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 if (bestComponent == null
4598 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4599 loge("The calling package is not allowed to select ISD-R.");
4600 throw new SecurityException(
4601 "The calling package is not allowed to select ISD-R.");
4602 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004603 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004606 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4607 null /* workSource */);
4608 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004610 // Append the returned status code to the end of the response payload.
4611 String s = Integer.toHexString(
4612 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4613 if (response.payload != null) {
4614 s = IccUtils.bytesToHexString(response.payload) + s;
4615 }
4616 return s;
4617 } finally {
4618 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004619 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004620 }
4621
4622 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004623 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004624 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4626 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004628 final long identity = Binder.clearCallingIdentity();
4629 try {
4630 if (DBG) {
4631 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4632 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4633 }
4634
4635 IccIoResult response =
4636 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4637 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4638 subId);
4639
4640 if (DBG) {
4641 log("Exchange SIM_IO [R]" + response);
4642 }
4643
4644 byte[] result = null;
4645 int length = 2;
4646 if (response.payload != null) {
4647 length = 2 + response.payload.length;
4648 result = new byte[length];
4649 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4650 } else {
4651 result = new byte[length];
4652 }
4653
4654 result[length - 1] = (byte) response.sw2;
4655 result[length - 2] = (byte) response.sw1;
4656 return result;
4657 } finally {
4658 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004659 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004660 }
4661
Nathan Haroldb3014052017-01-25 15:57:32 -08004662 /**
4663 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4664 * on a particular subscription
4665 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004666 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4667 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004668 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004669 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004670 return null;
4671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004672
4673 final long identity = Binder.clearCallingIdentity();
4674 try {
4675 if (appType != TelephonyManager.APPTYPE_USIM
4676 && appType != TelephonyManager.APPTYPE_SIM) {
4677 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4678 return null;
4679 }
4680 Object response = sendRequest(
4681 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4682 if (response instanceof String[]) {
4683 return (String[]) response;
4684 }
yincheng zhaod698b842019-09-06 17:06:54 -07004685 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004686 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004687 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 } finally {
4689 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004690 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004691 }
4692
yincheng zhaod698b842019-09-06 17:06:54 -07004693 /**
4694 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4695 * subscription.
4696 *
4697 * @param subId the id of the subscription.
4698 * @param appType the uicc app type, must be USIM or SIM.
4699 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4700 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004701 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004702 * @return number of fplmns that is successfully written to the SIM.
4703 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004704 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4705 String callingFeatureId) {
4706 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4707 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004708 if (DBG) logv("no permissions for setForbiddenplmns");
4709 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4710 }
4711 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4712 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4713 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4714 }
4715 if (fplmns == null) {
4716 throw new IllegalArgumentException("Fplmn List provided is null");
4717 }
4718 for (String fplmn : fplmns) {
4719 if (!CellIdentity.isValidPlmn(fplmn)) {
4720 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4721 }
4722 }
4723 final long identity = Binder.clearCallingIdentity();
4724 try {
4725 Object response = sendRequest(
4726 CMD_SET_FORBIDDEN_PLMNS,
4727 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4728 subId);
4729 return (int) response;
4730 } finally {
4731 Binder.restoreCallingIdentity(identity);
4732 }
4733 }
4734
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004735 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004736 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4738 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740 final long identity = Binder.clearCallingIdentity();
4741 try {
4742 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4743 if (response.payload == null) {
4744 return "";
4745 }
Evan Charltonc66da362014-05-16 14:06:40 -07004746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004747 // Append the returned status code to the end of the response payload.
4748 String s = Integer.toHexString(
4749 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4750 s = IccUtils.bytesToHexString(response.payload) + s;
4751 return s;
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
4754 }
Evan Charltonc66da362014-05-16 14:06:40 -07004755 }
4756
Jake Hambye994d462014-02-03 13:10:13 -08004757 /**
4758 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4759 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4760 *
4761 * @param itemID the ID of the item to read
4762 * @return the NV item as a String, or null on error.
4763 */
4764 @Override
4765 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004766 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4768 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769
4770 final long identity = Binder.clearCallingIdentity();
4771 try {
4772 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004773 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4775 return value;
4776 } finally {
4777 Binder.restoreCallingIdentity(identity);
4778 }
Jake Hambye994d462014-02-03 13:10:13 -08004779 }
4780
4781 /**
4782 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4783 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4784 *
4785 * @param itemID the ID of the item to read
4786 * @param itemValue the value to write, as a String
4787 * @return true on success; false on any failure
4788 */
4789 @Override
4790 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004791 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4793 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004794
4795 final long identity = Binder.clearCallingIdentity();
4796 try {
4797 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4798 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004799 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004800 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4801 return success;
4802 } finally {
4803 Binder.restoreCallingIdentity(identity);
4804 }
Jake Hambye994d462014-02-03 13:10:13 -08004805 }
4806
4807 /**
4808 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4809 * Used for device configuration by some CDMA operators.
4810 *
4811 * @param preferredRoamingList byte array containing the new PRL
4812 * @return true on success; false on any failure
4813 */
4814 @Override
4815 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4817 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818
4819 final long identity = Binder.clearCallingIdentity();
4820 try {
4821 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4822 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4823 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4824 return success;
4825 } finally {
4826 Binder.restoreCallingIdentity(identity);
4827 }
Jake Hambye994d462014-02-03 13:10:13 -08004828 }
4829
4830 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004831 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004832 * Used for device configuration by some CDMA operators.
4833 *
chen xu6dac5ab2018-10-26 17:39:23 -07004834 * @param slotIndex - device slot.
4835 *
Jake Hambye994d462014-02-03 13:10:13 -08004836 * @return true on success; false on any failure
4837 */
4838 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004839 public boolean resetModemConfig(int slotIndex) {
4840 Phone phone = PhoneFactory.getPhone(slotIndex);
4841 if (phone != null) {
4842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4843 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004844
chen xu6dac5ab2018-10-26 17:39:23 -07004845 final long identity = Binder.clearCallingIdentity();
4846 try {
4847 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4848 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4849 return success;
4850 } finally {
4851 Binder.restoreCallingIdentity(identity);
4852 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853 }
chen xu6dac5ab2018-10-26 17:39:23 -07004854 return false;
4855 }
4856
4857 /**
4858 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4859 *
4860 * @param slotIndex - device slot.
4861 *
4862 * @return true on success; false on any failure
4863 */
4864 @Override
4865 public boolean rebootModem(int slotIndex) {
4866 Phone phone = PhoneFactory.getPhone(slotIndex);
4867 if (phone != null) {
4868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4869 mApp, phone.getSubId(), "rebootModem");
4870
4871 final long identity = Binder.clearCallingIdentity();
4872 try {
4873 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4874 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4875 return success;
4876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
4879 }
4880 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004881 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004882
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004883 public String[] getPcscfAddress(String apnType, String callingPackage,
4884 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004885 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4887 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004888 return new String[0];
4889 }
4890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 final long identity = Binder.clearCallingIdentity();
4892 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004893 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004894 } finally {
4895 Binder.restoreCallingIdentity(identity);
4896 }
Wink Saville36469e72014-06-11 15:17:00 -07004897 }
4898
Brad Ebinger51f743a2017-01-23 13:50:20 -08004899 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004900 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4901 * {@link #disableIms(int)}.
4902 * @param slotIndex device slot.
4903 */
4904 public void resetIms(int slotIndex) {
4905 enforceModifyPermission();
4906
4907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 if (mImsResolver == null) {
4910 // may happen if the does not support IMS.
4911 return;
4912 }
4913 mImsResolver.disableIms(slotIndex);
4914 mImsResolver.enableIms(slotIndex);
4915 } finally {
4916 Binder.restoreCallingIdentity(identity);
4917 }
4918 }
4919
4920 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004921 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4922 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004923 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004924 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004925 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926
4927 final long identity = Binder.clearCallingIdentity();
4928 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004929 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004930 // may happen if the device does not support IMS.
4931 return;
4932 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004933 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004937 }
4938
4939 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004940 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4941 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004942 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004943 public void disableIms(int slotId) {
4944 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945
4946 final long identity = Binder.clearCallingIdentity();
4947 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004948 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004949 // may happen if the device does not support IMS.
4950 return;
4951 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004952 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 } finally {
4954 Binder.restoreCallingIdentity(identity);
4955 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004956 }
4957
4958 /**
4959 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4960 * feature or {@link null} if the service is not available. If the feature is available, the
4961 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4962 */
4963 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004964 IImsServiceFeatureCallback callback) {
4965 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966
4967 final long identity = Binder.clearCallingIdentity();
4968 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004969 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004970 // may happen if the device does not support IMS.
4971 return null;
4972 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004973 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 } finally {
4975 Binder.restoreCallingIdentity(identity);
4976 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004977 }
4978
4979 /**
4980 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4981 * feature during emergency calling or {@link null} if the service is not available. If the
4982 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4983 * listener for feature updates.
4984 */
4985 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4986 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987
4988 final long identity = Binder.clearCallingIdentity();
4989 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004990 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004991 // may happen if the device does not support IMS.
4992 return null;
4993 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004994 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 } finally {
4996 Binder.restoreCallingIdentity(identity);
4997 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004998 }
4999
Brad Ebinger5f64b052017-12-14 14:26:15 -08005000 /**
5001 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005002 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005003 */
5004 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5005 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006
5007 final long identity = Binder.clearCallingIdentity();
5008 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005009 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005010 // may happen if the device does not support IMS.
5011 return null;
5012 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005013 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 } finally {
5015 Binder.restoreCallingIdentity(identity);
5016 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005017 }
5018
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005019 /**
5020 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005021 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005022 */
5023 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5024 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025
5026 final long identity = Binder.clearCallingIdentity();
5027 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005028 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005029 // may happen if the device does not support IMS.
5030 return null;
5031 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005032 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005036 }
5037
Brad Ebinger884c07b2018-02-15 16:17:40 -08005038 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005039 * Sets the ImsService Package Name that Telephony will bind to.
5040 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005041 * @param slotIndex the slot ID that the ImsService should bind for.
5042 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005043 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005044 * @param featureTypes An integer array of feature types associated with a packageName.
5045 * @param packageName The name of the package that the current configuration will be replaced
5046 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005047 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005048 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005049 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5050 int[] featureTypes, String packageName) {
5051 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5052 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5054 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005055 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057 final long identity = Binder.clearCallingIdentity();
5058 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005059 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005060 // may happen if the device does not support IMS.
5061 return false;
5062 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005063 Map<Integer, String> featureConfig = new HashMap<>();
5064 for (int featureType : featureTypes) {
5065 featureConfig.put(featureType, packageName);
5066 }
5067 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5068 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005072 }
5073
5074 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005075 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005076 *
5077 * @param slotId The slot that the ImsService is associated with.
5078 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5079 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005080 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005081 * @return the package name of the ImsService configuration.
5082 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005083 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5084 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005085 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005086 TelephonyPermissions
5087 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5088 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5089 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005090
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 final long identity = Binder.clearCallingIdentity();
5092 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005093 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005094 // may happen if the device does not support IMS.
5095 return "";
5096 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005097 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005098 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5099 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005103 }
5104
Brad Ebinger77b832e2019-10-17 17:03:22 -07005105 /**
5106 * Get the MmTelFeature state associated with the requested subscription id.
5107 * @param subId The subscription that the MmTelFeature is associated with.
5108 * @param callback A callback with an integer containing the
5109 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5110 */
5111 @Override
5112 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5113 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5114 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5115 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5116 "IMS not available on device.");
5117 }
5118 final long token = Binder.clearCallingIdentity();
5119 try {
5120 int slotId = getSlotIndex(subId);
5121 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5122 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5123 + subId + "'");
5124 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5125 }
5126 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5127 try {
5128 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5129 } catch (RemoteException e) {
5130 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5131 + "Ignore");
5132 }
5133 });
5134 } finally {
5135 Binder.restoreCallingIdentity(token);
5136 }
5137 }
5138
Wink Saville36469e72014-06-11 15:17:00 -07005139 public void setImsRegistrationState(boolean registered) {
5140 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141
5142 final long identity = Binder.clearCallingIdentity();
5143 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005144 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 } finally {
5146 Binder.restoreCallingIdentity(identity);
5147 }
Wink Saville36469e72014-06-11 15:17:00 -07005148 }
5149
5150 /**
Stuart Scott54788802015-03-30 13:18:01 -07005151 * Set the network selection mode to automatic.
5152 *
5153 */
5154 @Override
5155 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5157 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158
5159 final long identity = Binder.clearCallingIdentity();
5160 try {
shilufc958392020-01-20 11:36:01 -08005161 if (!isActiveSubscription(subId)) {
5162 return;
5163 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5165 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5166 } finally {
5167 Binder.restoreCallingIdentity(identity);
5168 }
Stuart Scott54788802015-03-30 13:18:01 -07005169 }
5170
Pengquan Mengea84e042018-09-20 14:57:26 -07005171 /**
5172 * Ask the radio to connect to the input network and change selection mode to manual.
5173 *
5174 * @param subId the id of the subscription.
5175 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5176 * the operator to attach to.
5177 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5178 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5179 * normal network selection next time.
5180 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005181 */
5182 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005183 public boolean setNetworkSelectionModeManual(
5184 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5186 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005187
5188 if (!isActiveSubscription(subId)) {
5189 return false;
5190 }
5191
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 final long identity = Binder.clearCallingIdentity();
5193 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005194 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005196 if (DBG) {
5197 log("setNetworkSelectionModeManual: subId: " + subId
5198 + " operator: " + operatorInfo);
5199 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005204 }
5205
5206 /**
5207 * Scans for available networks.
5208 */
5209 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005210 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5211 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5213 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005214 LocationAccessPolicy.LocationPermissionResult locationResult =
5215 LocationAccessPolicy.checkLocationPermission(mApp,
5216 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5217 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005218 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005219 .setCallingPid(Binder.getCallingPid())
5220 .setCallingUid(Binder.getCallingUid())
5221 .setMethod("getCellNetworkScanResults")
5222 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5223 .build());
5224 switch (locationResult) {
5225 case DENIED_HARD:
5226 throw new SecurityException("Not allowed to access scan results -- location");
5227 case DENIED_SOFT:
5228 return null;
5229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230
Pengquan Menga1bb6272018-09-06 09:59:22 -07005231 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 try {
5233 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005234 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005239 }
5240
5241 /**
sqian80370722020-01-29 15:02:51 -08005242 * Get the call forwarding info, given the call forwarding reason.
5243 */
5244 @Override
5245 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5246 enforceReadPrivilegedPermission("getCallForwarding");
5247 long identity = Binder.clearCallingIdentity();
5248 try {
5249 if (DBG) {
5250 log("getCallForwarding: subId " + subId
5251 + " callForwardingReason" + callForwardingReason);
5252 }
5253 return (CallForwardingInfo) sendRequest(
5254 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5255 } finally {
5256 Binder.restoreCallingIdentity(identity);
5257 }
5258 }
5259
5260 /**
5261 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5262 * reason, the number to forward, and the timeout before the forwarding is attempted.
5263 */
5264 @Override
5265 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5266 enforceModifyPermission();
5267 long identity = Binder.clearCallingIdentity();
5268 try {
5269 if (DBG) {
5270 log("setCallForwarding: subId " + subId
5271 + " callForwardingInfo" + callForwardingInfo);
5272 }
5273 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
5277 }
5278
5279 /**
5280 * Get the call forwarding info, given the call forwarding reason.
5281 */
5282 @Override
5283 public int getCallWaitingStatus(int subId) {
5284 enforceReadPrivilegedPermission("getCallForwarding");
5285 long identity = Binder.clearCallingIdentity();
5286 try {
5287 if (DBG) log("getCallWaitingStatus: subId " + subId);
5288 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5289 } finally {
5290 Binder.restoreCallingIdentity(identity);
5291 }
5292 }
5293
5294 /**
5295 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5296 * reason, the number to forward, and the timeout before the forwarding is attempted.
5297 */
5298 @Override
5299 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5300 enforceModifyPermission();
5301 long identity = Binder.clearCallingIdentity();
5302 try {
5303 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5304 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
5308 }
5309
5310 /**
yinxub1bed742017-04-17 11:45:04 -07005311 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005312 *
yinxub1bed742017-04-17 11:45:04 -07005313 * @param subId id of the subscription
5314 * @param request contains the radio access networks with bands/channels to scan
5315 * @param messenger callback messenger for scan results or errors
5316 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005317 * @return the id of the requested scan which can be used to stop the scan.
5318 */
5319 @Override
5320 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005321 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5323 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005324 LocationAccessPolicy.LocationPermissionResult locationResult =
5325 LocationAccessPolicy.checkLocationPermission(mApp,
5326 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5327 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005328 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005329 .setCallingPid(Binder.getCallingPid())
5330 .setCallingUid(Binder.getCallingUid())
5331 .setMethod("requestNetworkScan")
5332 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5333 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005334 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005335 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005336 if (e != null) {
5337 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5338 throw e;
5339 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005340 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005341 return TelephonyScanManager.INVALID_SCAN_ID;
5342 }
5343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344 }
Hall Liu912dfd32019-04-25 14:02:26 -07005345 int callingUid = Binder.getCallingUid();
5346 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005347 final long identity = Binder.clearCallingIdentity();
5348 try {
5349 return mNetworkScanRequestTracker.startNetworkScan(
5350 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005351 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005352 } finally {
5353 Binder.restoreCallingIdentity(identity);
5354 }
yinxu504e1392017-04-12 16:03:22 -07005355 }
5356
Hall Liub2ac8ef2019-02-28 15:56:23 -08005357 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005358 NetworkScanRequest request, int subId) {
5359 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5360 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5361 boolean hasNetworkScanPermission =
5362 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5363 == PERMISSION_GRANTED;
5364
5365 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5366 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5367 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005368 }
5369
5370 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5371 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005372 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5373 return new SecurityException("Specific channels must not be"
5374 + " scanned without location access.");
5375 }
5376 }
5377 }
5378
Hall Liub2ac8ef2019-02-28 15:56:23 -08005379 return null;
5380 }
5381
yinxu504e1392017-04-12 16:03:22 -07005382 /**
5383 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005384 *
5385 * @param subId id of the subscription
5386 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005387 */
5388 @Override
5389 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5391 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005392
Hall Liu912dfd32019-04-25 14:02:26 -07005393 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 final long identity = Binder.clearCallingIdentity();
5395 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005396 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 } finally {
5398 Binder.restoreCallingIdentity(identity);
5399 }
yinxu504e1392017-04-12 16:03:22 -07005400 }
5401
5402 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005403 * Get the calculated preferred network type.
5404 * Used for debugging incorrect network type.
5405 *
5406 * @return the preferred network type, defined in RILConstants.java.
5407 */
5408 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005409 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005410 final Phone defaultPhone = getDefaultPhone();
5411 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005412 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005413 return RILConstants.PREFERRED_NETWORK_MODE;
5414 }
5415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 final long identity = Binder.clearCallingIdentity();
5417 try {
5418 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005419 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
Junda Liu84d15a22014-07-02 11:21:04 -07005423 }
5424
5425 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005426 * Get the preferred network type.
5427 * Used for device configuration by some CDMA operators.
5428 *
5429 * @return the preferred network type, defined in RILConstants.java.
5430 */
5431 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005432 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005433 TelephonyPermissions
5434 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5435 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436
5437 final long identity = Binder.clearCallingIdentity();
5438 try {
5439 if (DBG) log("getPreferredNetworkType");
5440 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5441 int networkType = (result != null ? result[0] : -1);
5442 if (DBG) log("getPreferredNetworkType: " + networkType);
5443 return networkType;
5444 } finally {
5445 Binder.restoreCallingIdentity(identity);
5446 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005447 }
5448
5449 /**
5450 * Set the preferred network type.
5451 * Used for device configuration by some CDMA operators.
5452 *
5453 * @param networkType the preferred network type, defined in RILConstants.java.
5454 * @return true on success; false on any failure.
5455 */
5456 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005457 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5459 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460
5461 final long identity = Binder.clearCallingIdentity();
5462 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005463 Settings.Global.putInt(mApp.getContentResolver(),
5464 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5465 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 } finally {
5467 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005468 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005469 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005470
5471 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005472 * Get the allowed network types that store in the telephony provider.
5473 *
5474 * @param subId the id of the subscription.
5475 * @return allowedNetworkTypes the allowed network types.
5476 */
5477 @Override
5478 public long getAllowedNetworkTypes(int subId) {
5479 TelephonyPermissions
5480 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5481 mApp, subId, "getAllowedNetworkTypes");
5482
5483 final long identity = Binder.clearCallingIdentity();
5484 try {
5485 return SubscriptionManager.getLongSubscriptionProperty(
5486 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5487 } finally {
5488 Binder.restoreCallingIdentity(identity);
5489 }
5490 }
5491
5492 /**
5493 * Set the allowed network types.
5494 *
5495 * @param subId the id of the subscription.
5496 * @param allowedNetworkTypes the allowed network types.
5497 * @return true on success; false on any failure.
5498 */
5499 @Override
5500 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5502 mApp, subId, "setAllowedNetworkTypes");
5503 final long identity = Binder.clearCallingIdentity();
5504 try {
5505 SubscriptionManager.setSubscriptionProperty(subId,
5506 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5507 String.valueOf(allowedNetworkTypes));
5508 return setPreferredNetworkTypesInternal(subId);
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
5512 }
5513
5514 private boolean setPreferredNetworkTypesInternal(int subId) {
5515 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5516 Settings.Global.getInt(mApp.getContentResolver(),
5517 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5518 RILConstants.PREFERRED_NETWORK_MODE));
5519 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5520 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5521 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5522 (int) (networkTypeBitMask & allowedNetworkTypes));
5523
5524 if (DBG) {
5525 log("setPreferredNetworkTypesInternal: subId " + subId
5526 + " networkTypes " + networkTypeBitMask
5527 + " allowedNetworkTypes " + allowedNetworkTypes
5528 + " networkMode " + networkMode);
5529 }
5530
5531 Boolean success = (Boolean) sendRequest(
5532 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5533 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5534 return success;
5535 }
5536
5537 /**
Miaoa84611c2019-03-15 09:21:10 +08005538 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005539 *
Miaoa84611c2019-03-15 09:21:10 +08005540 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005541 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005542 * @hide
5543 */
5544 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005545 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005546 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005548 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 try {
Miaoa84611c2019-03-15 09:21:10 +08005550 if (phone != null) {
5551 return phone.hasMatchedTetherApnSetting();
5552 } else {
5553 return false;
5554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555 } finally {
5556 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005557 }
Junda Liu475951f2014-11-07 16:45:03 -08005558 }
5559
5560 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005561 * Set mobile data enabled
5562 * Used by the user through settings etc to turn on/off mobile data
5563 *
5564 * @param enable {@code true} turn turn data on, else {@code false}
5565 */
5566 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005567 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5569 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570
5571 final long identity = Binder.clearCallingIdentity();
5572 try {
5573 int phoneId = mSubscriptionController.getPhoneId(subId);
5574 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5575 Phone phone = PhoneFactory.getPhone(phoneId);
5576 if (phone != null) {
5577 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005578 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005580 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 }
5582 } finally {
5583 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005584 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005585 }
5586
5587 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005588 * Enable or disable always reporting signal strength changes from radio.
5589 *
5590 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5591 */
5592 @Override
5593 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5594 enforceModifyPermission();
5595 enforceSystemCaller();
5596
5597 final long identity = Binder.clearCallingIdentity();
5598 final Phone phone = getPhone(subId);
5599 try {
5600 if (phone != null) {
5601 if (DBG) {
5602 log("setAlwaysReportSignalStrength: subId=" + subId
5603 + " isEnable=" + isEnable);
5604 }
5605 phone.setAlwaysReportSignalStrength(isEnable);
5606 } else {
5607 loge("setAlwaysReportSignalStrength: no phone found for subId="
5608 + subId);
5609 }
5610 } finally {
5611 Binder.restoreCallingIdentity(identity);
5612 }
5613 }
5614
5615 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005616 * Get the user enabled state of Mobile Data.
5617 *
5618 * TODO: remove and use isUserDataEnabled.
5619 * This can't be removed now because some vendor codes
5620 * calls through ITelephony directly while they should
5621 * use TelephonyManager.
5622 *
5623 * @return true on enabled
5624 */
5625 @Override
5626 public boolean getDataEnabled(int subId) {
5627 return isUserDataEnabled(subId);
5628 }
5629
5630 /**
5631 * Get whether mobile data is enabled per user setting.
5632 *
5633 * There are other factors deciding whether mobile data is actually enabled, but they are
5634 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005635 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005636 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005637 *
5638 * @return {@code true} if data is enabled else {@code false}
5639 */
5640 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005641 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005642 try {
5643 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5644 null);
5645 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5647 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649
5650 final long identity = Binder.clearCallingIdentity();
5651 try {
5652 int phoneId = mSubscriptionController.getPhoneId(subId);
5653 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5654 Phone phone = PhoneFactory.getPhone(phoneId);
5655 if (phone != null) {
5656 boolean retVal = phone.isUserDataEnabled();
5657 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5658 return retVal;
5659 } else {
5660 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5661 return false;
5662 }
5663 } finally {
5664 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005665 }
5666 }
5667
5668 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005669 * Checks if the device is capable of mobile data by considering whether whether the
5670 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5671 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005672 *
Shuo Qian985d1232020-01-08 14:30:06 -08005673 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005674 */
5675 @Override
5676 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005677 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678
5679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 int phoneId = mSubscriptionController.getPhoneId(subId);
5682 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5683 Phone phone = PhoneFactory.getPhone(phoneId);
5684 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005685 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5687 return retVal;
5688 } else {
5689 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5690 return false;
5691 }
5692 } finally {
5693 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005694 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005695 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005696
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005697 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5698 Phone phone) {
5699 //load access rules from carrier configs, and check those as well: b/139133814
5700 SubscriptionController subController = SubscriptionController.getInstance();
5701 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5702 || subController == null) return privilegeFromSim;
5703
5704 int uid = Binder.getCallingUid();
5705 PackageManager pkgMgr = phone.getContext().getPackageManager();
5706 String[] packages = pkgMgr.getPackagesForUid(uid);
5707
5708 final long identity = Binder.clearCallingIdentity();
5709 try {
5710 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5711 SubscriptionManager subManager = (SubscriptionManager)
5712 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5713 for (String pkg : packages) {
5714 if (subManager.canManageSubscription(subInfo, pkg)) {
5715 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5716 }
5717 }
5718 return privilegeFromSim;
5719 } finally {
5720 Binder.restoreCallingIdentity(identity);
5721 }
5722 }
5723
5724 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5725 String pkgName) {
5726 //load access rules from carrier configs, and check those as well: b/139133814
5727 SubscriptionController subController = SubscriptionController.getInstance();
5728 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5729 || subController == null) return privilegeFromSim;
5730
5731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5734 SubscriptionManager subManager = (SubscriptionManager)
5735 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5736 return subManager.canManageSubscription(subInfo, pkgName)
5737 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
5741 }
5742
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005743 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005744 public int getCarrierPrivilegeStatus(int subId) {
5745 final Phone phone = getPhone(subId);
5746 if (phone == null) {
5747 loge("getCarrierPrivilegeStatus: Invalid subId");
5748 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5749 }
5750 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005751 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005752 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005753 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5754 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005755
5756 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5757 card.getCarrierPrivilegeStatusForCurrentTransaction(
5758 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005759 }
Junda Liu29340342014-07-10 15:23:27 -07005760
5761 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005762 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005763 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005764 final Phone phone = getPhone(subId);
5765 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005766 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005767 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5768 }
5769 UiccProfile profile =
5770 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5771 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005772 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005773 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5774 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005775 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005776 profile.getCarrierPrivilegeStatusForUid(
5777 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005778 }
5779
5780 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005781 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5782 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005783 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005784 }
5785
5786 int phoneId = SubscriptionManager.getPhoneId(subId);
5787 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005788 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005789 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5791 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005792 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5793 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5794 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005795 }
5796
5797 @Override
5798 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005799 if (TextUtils.isEmpty(pkgName))
5800 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005801 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5802 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5803 UiccCard card = UiccController.getInstance().getUiccCard(i);
5804 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005805 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005806 continue;
5807 }
5808
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005809 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5810 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5811 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005812 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5813 break;
5814 }
5815 }
5816
5817 return result;
Junda Liu29340342014-07-10 15:23:27 -07005818 }
Derek Tan89e89d42014-07-08 17:00:10 -07005819
5820 @Override
Junda Liue64de782015-04-16 17:19:16 -07005821 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5822 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5823 loge("phoneId " + phoneId + " is not valid.");
5824 return null;
5825 }
5826 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005827 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005828 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005829 return null ;
5830 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005831 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005832 }
5833
Amith Yamasani6e118872016-02-19 12:53:51 -08005834 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005835 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005836 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005837 List<String> privilegedPackages = new ArrayList<>();
5838 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005839 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5840 // has UICC in that slot.
5841 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005842 if (card.hasCarrierPrivilegeRules()) {
5843 if (packages == null) {
5844 // Only check packages in user 0 for now
5845 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005846 PackageManager.MATCH_DISABLED_COMPONENTS
5847 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005848 | PackageManager.GET_SIGNING_CERTIFICATES,
5849 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005850 }
5851 for (int p = packages.size() - 1; p >= 0; p--) {
5852 PackageInfo pkgInfo = packages.get(p);
5853 if (pkgInfo != null && pkgInfo.packageName != null
5854 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005855 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005856 privilegedPackages.add(pkgInfo.packageName);
5857 }
5858 }
5859 }
5860 }
5861 return privilegedPackages;
5862 }
5863
chen xuf7e9fe82019-05-09 19:31:02 -07005864 @Override
5865 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005866 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5867
5868 final long identity = Binder.clearCallingIdentity();
5869
chen xuf7e9fe82019-05-09 19:31:02 -07005870 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005871 try {
5872 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5873 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5874 }
5875 } finally {
5876 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005877 }
5878 return privilegedPackages;
5879 }
5880
Wink Savilleb564aae2014-10-23 10:18:09 -07005881 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005882 final Phone phone = getPhone(subId);
5883 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005884 if (card == null) {
5885 loge("getIccId: No UICC");
5886 return null;
5887 }
5888 String iccId = card.getIccId();
5889 if (TextUtils.isEmpty(iccId)) {
5890 loge("getIccId: ICC ID is null or empty.");
5891 return null;
5892 }
5893 return iccId;
5894 }
5895
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005896 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005897 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5898 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005899 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005900 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 final long identity = Binder.clearCallingIdentity();
5903 try {
5904 final String iccId = getIccId(subId);
5905 final Phone phone = getPhone(subId);
5906 if (phone == null) {
5907 return false;
5908 }
5909 final String subscriberId = phone.getSubscriberId();
5910
5911 if (DBG_MERGE) {
5912 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5913 + subscriberId + " to " + number);
5914 }
5915
5916 if (TextUtils.isEmpty(iccId)) {
5917 return false;
5918 }
5919
5920 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5921
5922 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5923 if (alphaTag == null) {
5924 editor.remove(alphaTagPrefKey);
5925 } else {
5926 editor.putString(alphaTagPrefKey, alphaTag);
5927 }
5928
5929 // Record both the line number and IMSI for this ICCID, since we need to
5930 // track all merged IMSIs based on line number
5931 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5932 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5933 if (number == null) {
5934 editor.remove(numberPrefKey);
5935 editor.remove(subscriberPrefKey);
5936 } else {
5937 editor.putString(numberPrefKey, number);
5938 editor.putString(subscriberPrefKey, subscriberId);
5939 }
5940
5941 editor.commit();
5942 return true;
5943 } finally {
5944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005945 }
Derek Tan7226c842014-07-02 17:42:23 -07005946 }
5947
5948 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005949 public String getLine1NumberForDisplay(int subId, String callingPackage,
5950 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005951 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005953 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005954 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005955 return null;
5956 }
Derek Tan97ebb422014-09-05 16:55:38 -07005957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 final long identity = Binder.clearCallingIdentity();
5959 try {
5960 String iccId = getIccId(subId);
5961 if (iccId != null) {
5962 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5963 if (DBG_MERGE) {
5964 log("getLine1NumberForDisplay returning "
5965 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5966 }
5967 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5970 return null;
5971 } finally {
5972 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005973 }
Derek Tan7226c842014-07-02 17:42:23 -07005974 }
5975
5976 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005977 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5978 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005980 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005981 return null;
5982 }
Derek Tan97ebb422014-09-05 16:55:38 -07005983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 final long identity = Binder.clearCallingIdentity();
5985 try {
5986 String iccId = getIccId(subId);
5987 if (iccId != null) {
5988 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5989 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5990 }
5991 return null;
5992 } finally {
5993 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005994 }
Derek Tan7226c842014-07-02 17:42:23 -07005995 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005996
5997 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005998 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5999 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006000 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6001 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006003 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006004 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006005 return null;
6006 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006007
Jordan Liub49b04b2019-05-06 14:45:15 -07006008 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6009 // the process, where TelephonyManager was instantiated.
6010 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006011 final long identity = Binder.clearCallingIdentity();
6012 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006013 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 final TelephonyManager tele = TelephonyManager.from(context);
6015 final SubscriptionManager sub = SubscriptionManager.from(context);
6016
6017 // Figure out what subscribers are currently active
6018 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019
Jordan Liub49b04b2019-05-06 14:45:15 -07006020 // Only consider subs which match the current subId
6021 // This logic can be simplified. See b/131189269 for progress.
6022 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006023 activeSubscriberIds.add(tele.getSubscriberId(subId));
6024 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025
6026 // First pass, find a number override for an active subscriber
6027 String mergeNumber = null;
6028 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6029 for (String key : prefs.keySet()) {
6030 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6031 final String subscriberId = (String) prefs.get(key);
6032 if (activeSubscriberIds.contains(subscriberId)) {
6033 final String iccId = key.substring(
6034 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6035 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6036 mergeNumber = (String) prefs.get(numberKey);
6037 if (DBG_MERGE) {
6038 Slog.d(LOG_TAG, "Found line number " + mergeNumber
6039 + " for active subscriber " + subscriberId);
6040 }
6041 if (!TextUtils.isEmpty(mergeNumber)) {
6042 break;
6043 }
6044 }
6045 }
6046 }
6047
6048 // Shortcut when no active merged subscribers
6049 if (TextUtils.isEmpty(mergeNumber)) {
6050 return null;
6051 }
6052
6053 // Second pass, find all subscribers under that line override
6054 final ArraySet<String> result = new ArraySet<>();
6055 for (String key : prefs.keySet()) {
6056 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6057 final String number = (String) prefs.get(key);
6058 if (mergeNumber.equals(number)) {
6059 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6060 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6061 final String subscriberId = (String) prefs.get(subscriberKey);
6062 if (!TextUtils.isEmpty(subscriberId)) {
6063 result.add(subscriberId);
6064 }
6065 }
6066 }
6067 }
6068
6069 final String[] resultArray = result.toArray(new String[result.size()]);
6070 Arrays.sort(resultArray);
6071 if (DBG_MERGE) {
6072 Slog.d(LOG_TAG,
6073 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6074 }
6075 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006076 } finally {
6077 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006078 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006079 }
6080
6081 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006082 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6083 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6084
6085 final long identity = Binder.clearCallingIdentity();
6086 try {
6087 final TelephonyManager telephonyManager = mApp.getSystemService(
6088 TelephonyManager.class);
6089 String subscriberId = telephonyManager.getSubscriberId(subId);
6090 if (subscriberId == null) {
6091 if (DBG) {
6092 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6093 + subId);
6094 }
6095 return null;
6096 }
6097
6098 final SubscriptionInfo info = SubscriptionController.getInstance()
6099 .getSubscriptionInfo(subId);
6100 final ParcelUuid groupUuid = info.getGroupUuid();
6101 // If it doesn't belong to any group, return just subscriberId of itself.
6102 if (groupUuid == null) {
6103 return new String[]{subscriberId};
6104 }
6105
6106 // Get all subscriberIds from the group.
6107 final List<String> mergedSubscriberIds = new ArrayList<>();
6108 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006109 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6110 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006111 for (SubscriptionInfo subInfo : groupInfos) {
6112 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6113 if (subscriberId != null) {
6114 mergedSubscriberIds.add(subscriberId);
6115 }
6116 }
6117
6118 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
6121
6122 }
6123 }
6124
6125 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006126 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006127 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006128 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129
6130 final long identity = Binder.clearCallingIdentity();
6131 try {
6132 final Phone phone = getPhone(subId);
6133 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006137 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006138
6139 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006140 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006141 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6142 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006143 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6144 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145
6146 final long identity = Binder.clearCallingIdentity();
6147 try {
6148 final Phone phone = getPhone(subId);
6149 if (phone == null) {
6150 return false;
6151 }
6152 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6153 cdmaNonRoamingList);
6154 } finally {
6155 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006156 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006157 }
6158
6159 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006160 @Deprecated
6161 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6162 enforceModifyPermission();
6163
6164 int returnValue = 0;
6165 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006166 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006167 if(result.exception == null) {
6168 if (result.result != null) {
6169 byte[] responseData = (byte[])(result.result);
6170 if(responseData.length > oemResp.length) {
6171 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6172 responseData.length + "bytes. Buffer Size is " +
6173 oemResp.length + "bytes.");
6174 }
6175 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6176 returnValue = responseData.length;
6177 }
6178 } else {
6179 CommandException ex = (CommandException) result.exception;
6180 returnValue = ex.getCommandError().ordinal();
6181 if(returnValue > 0) returnValue *= -1;
6182 }
6183 } catch (RuntimeException e) {
6184 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6185 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6186 if(returnValue > 0) returnValue *= -1;
6187 }
6188
6189 return returnValue;
6190 }
6191
6192 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006193 public void setRadioCapability(RadioAccessFamily[] rafs) {
6194 try {
6195 ProxyController.getInstance().setRadioCapability(rafs);
6196 } catch (RuntimeException e) {
6197 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6198 }
6199 }
6200
6201 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006202 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006203 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006204 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006205 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006206 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208 final long identity = Binder.clearCallingIdentity();
6209 try {
chen xub97461a2018-10-26 14:17:57 -07006210 TelephonyPermissions
6211 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6212 mApp, phone.getSubId(), "getRadioAccessFamily");
6213 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 } finally {
6215 Binder.restoreCallingIdentity(identity);
6216 }
chen xub97461a2018-10-26 14:17:57 -07006217 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006218 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006219
6220 @Override
6221 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006222 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006223 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224
6225 final long identity = Binder.clearCallingIdentity();
6226 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006227 ImsManager.getInstance(defaultPhone.getContext(),
6228 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 } finally {
6230 Binder.restoreCallingIdentity(identity);
6231 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006232 }
6233
6234 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006235 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006236 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006237 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6238 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006239 return false;
6240 }
Svet Ganovb320e182015-04-16 12:30:10 -07006241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 final long identity = Binder.clearCallingIdentity();
6243 try {
6244 // Check the user preference and the system-level IMS setting. Even if the user has
6245 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6246 // In the long run, we may instead need to check if there exists a connection service
6247 // which can support video calling.
6248 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006249 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 return imsManager.isVtEnabledByPlatform()
6251 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6252 && imsManager.isVtEnabledByUser();
6253 } finally {
6254 Binder.restoreCallingIdentity(identity);
6255 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006256 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006257
Andrew Leea1239f22015-03-02 17:44:07 -08006258 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006259 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6260 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006262 mApp, subId, callingPackage, callingFeatureId,
6263 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006264 return false;
6265 }
6266
6267 final long identity = Binder.clearCallingIdentity();
6268 try {
6269 CarrierConfigManager configManager =
6270 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006271 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6273 } finally {
6274 Binder.restoreCallingIdentity(identity);
6275 }
Andrew Leea1239f22015-03-02 17:44:07 -08006276 }
6277
6278 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006279 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006281 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 return false;
6283 }
6284
6285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 CarrierConfigManager configManager =
6288 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006289 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6291 } finally {
6292 Binder.restoreCallingIdentity(identity);
6293 }
Andrew Leea1239f22015-03-02 17:44:07 -08006294 }
6295
Andrew Lee9431b832015-03-09 18:46:45 -07006296 @Override
6297 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006298 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006299 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006300 }
6301
6302 @Override
6303 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 final long identity = Binder.clearCallingIdentity();
6305 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006306 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 } finally {
6308 Binder.restoreCallingIdentity(identity);
6309 }
Andrew Lee9431b832015-03-09 18:46:45 -07006310 }
6311
Hall Liuf6668912018-10-31 17:05:23 -07006312 /**
6313 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6314 * support for the feature and device firmware support.
6315 *
6316 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6317 */
6318 @Override
6319 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006321 final Phone phone = getPhone(subscriptionId);
6322 if (phone == null) {
6323 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6324 return false;
6325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006327 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6329 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006330 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 return isCarrierSupported && isDeviceSupported;
6332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
Hall Liu98187582018-01-22 19:15:32 -08006335 }
6336
Hall Liuf6668912018-10-31 17:05:23 -07006337 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006338 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6339 * RTT setting, will return true if the device and carrier both support RTT.
6340 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006341 */
6342 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 final long identity = Binder.clearCallingIdentity();
6344 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006345 boolean isRttSupported = isRttSupported(subscriptionId);
6346 boolean isUserRttSettingOn = Settings.Secure.getInt(
6347 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6348 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6349 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6350 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006351 } finally {
6352 Binder.restoreCallingIdentity(identity);
6353 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006354 }
6355
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006356 @Deprecated
6357 @Override
6358 public String getDeviceId(String callingPackage) {
6359 return getDeviceIdWithFeature(callingPackage, null);
6360 }
6361
Sanket Padawe7310cc72015-01-14 09:53:20 -08006362 /**
6363 * Returns the unique device ID of phone, for example, the IMEI for
6364 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6365 *
6366 * <p>Requires Permission:
6367 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6368 */
6369 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006370 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006371 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006372 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006373 return null;
6374 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006375 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006376 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006377 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006378 return null;
6379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380
6381 final long identity = Binder.clearCallingIdentity();
6382 try {
6383 return phone.getDeviceId();
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006387 }
6388
Ping Sunc67b7c22016-03-02 19:16:45 +08006389 /**
6390 * {@hide}
6391 * Returns the IMS Registration Status on a particular subid
6392 *
6393 * @param subId
6394 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006395 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006396 Phone phone = getPhone(subId);
6397 if (phone != null) {
6398 return phone.isImsRegistered();
6399 } else {
6400 return false;
6401 }
6402 }
6403
Santos Cordon7a1885b2015-02-03 11:15:19 -08006404 @Override
6405 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 final long identity = Binder.clearCallingIdentity();
6407 try {
6408 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006412 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006413
Tyler Gunnf70ed162019-04-03 15:28:53 -07006414 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006415 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006416 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006418 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006419 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6420 }
6421 final long identity = Binder.clearCallingIdentity();
6422 try {
6423 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
6427 }
6428
6429 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006430 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6431 final long identity = Binder.clearCallingIdentity();
6432 try {
6433 Phone phone = getPhone(subscriptionId);
6434 if (phone == null) {
6435 return null;
6436 }
6437 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6438 } finally {
6439 Binder.restoreCallingIdentity(identity);
6440 }
6441 }
6442
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006443 /**
6444 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006445 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006446 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447 final long identity = Binder.clearCallingIdentity();
6448 try {
6449 Phone phone = getPhone(subId);
6450 if (phone != null) {
6451 return phone.isWifiCallingEnabled();
6452 } else {
6453 return false;
6454 }
6455 } finally {
6456 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006457 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006458 }
6459
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006460 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006461 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006462 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006463 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006464 final long identity = Binder.clearCallingIdentity();
6465 try {
6466 Phone phone = getPhone(subId);
6467 if (phone != null) {
6468 return phone.isVideoEnabled();
6469 } else {
6470 return false;
6471 }
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006474 }
6475 }
6476
6477 /**
6478 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6479 * defined in {@link ImsRegistrationImplBase}.
6480 */
6481 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006482 final long identity = Binder.clearCallingIdentity();
6483 try {
6484 Phone phone = getPhone(subId);
6485 if (phone != null) {
6486 return phone.getImsRegistrationTech();
6487 } else {
6488 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6489 }
6490 } finally {
6491 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006492 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006493 }
6494
Stuart Scott8eef64f2015-04-08 15:13:54 -07006495 @Override
6496 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006497 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006498 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6499 return;
6500 }
6501
Svet Ganovcc087f82015-05-12 20:35:54 -07006502 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006503
Svet Ganovcc087f82015-05-12 20:35:54 -07006504 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006505 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6506 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006507 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006508 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006509 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006510 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6511 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006512 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006513 // There has been issues when Sms raw table somehow stores orphan
6514 // fragments. They lead to garbled message when new fragments come
6515 // in and combined with those stale ones. In case this happens again,
6516 // user can reset all network settings which will clean up this table.
6517 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006518 // Clean up IMS settings as well here.
6519 int slotId = getSlotIndex(subId);
6520 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6521 ImsManager.getInstance(mApp, slotId).factoryReset();
6522 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006523
6524 // Erase modem config if erase modem on network setting is enabled.
6525 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6526 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6527 if (configValue != null && Boolean.parseBoolean(configValue)) {
6528 sendEraseModemConfig(getDefaultPhone());
6529 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006530 } finally {
6531 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006532 }
6533 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006534
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006535 private void cleanUpSmsRawTable(Context context) {
6536 ContentResolver resolver = context.getContentResolver();
6537 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6538 resolver.delete(uri, null, null);
6539 }
6540
Narayan Kamath1c496c22015-04-16 14:40:19 +01006541 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006542 public String getSimLocaleForSubscriber(int subId) {
6543 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6544 final Phone phone = getPhone(subId);
6545 if (phone == null) {
6546 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006547 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006548 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 final long identity = Binder.clearCallingIdentity();
6550 try {
chen xu5d3637b2019-01-21 23:31:38 -08006551 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006552 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006553 if (info == null) {
6554 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6555 return null;
6556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 // Try and fetch the locale from the carrier properties or from the SIM language
6558 // preferences (EF-PL and EF-LI)...
6559 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006561 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6562 if (localeFromDefaultSim != null) {
6563 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6564 if (DBG) log("Using locale from subId: " + subId + " locale: "
6565 + localeFromDefaultSim);
6566 return localeFromDefaultSim.toLanguageTag();
6567 } else {
6568 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006569 }
6570 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 // The SIM language preferences only store a language (e.g. fr = French), not an
6573 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6574 // the SIM and carrier preferences does not include a country we add the country
6575 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006576 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006578 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 return mccLocale.toLanguageTag();
6580 }
6581
6582 if (DBG) log("No locale found - returning null");
6583 return null;
6584 } finally {
6585 Binder.restoreCallingIdentity(identity);
6586 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006587 }
6588
6589 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006590 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6591 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006592 }
6593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 /**
6595 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6596 */
6597 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006598 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6599 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006600 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006601
Chenjie Yu1ba97252018-01-11 18:16:20 -08006602 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006603 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006604
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006605 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006606 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6607 * representing the state of the modem.
6608 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006609 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6610 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006611 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006612 */
6613 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006614 public void requestModemActivityInfo(ResultReceiver result) {
6615 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006616 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617
6618 final long identity = Binder.clearCallingIdentity();
6619 try {
6620 ModemActivityInfo ret = null;
6621 synchronized (mLastModemActivityInfo) {
6622 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6623 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006624 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006625 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006626 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006627 int[] txTimeMs = info.getTransmitTimeMillis();
6628 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006630 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006631 }
6632 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006633 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6634 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635 mLastModemActivityInfo.setIdleTimeMillis(
6636 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006637 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6638 mLastModemActivityInfo.setReceiveTimeMillis(
6639 info.getReceiveTimeMillis() + mLastModemActivityInfo
6640 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006641 }
Chen Xu13851032019-09-10 18:49:52 -07006642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6644 mLastModemActivityInfo.getSleepTimeMillis(),
6645 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006646 mLastModemActivityInfo.getTransmitTimeMillis(),
6647 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 Bundle bundle = new Bundle();
6650 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6651 result.send(0, bundle);
6652 } finally {
6653 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006654 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006655 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006656
Siddharth Rayb8114062018-06-17 15:02:38 -07006657 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6658 // less than total activity duration.
6659 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6660 if (info == null) {
6661 return false;
6662 }
6663 int activityDurationMs =
6664 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6665 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006666 int[] txTimeMs = info.getTransmitTimeMillis();
6667 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6668 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006669 }
6670 return (info.isValid()
6671 && (info.getSleepTimeMillis() <= activityDurationMs)
6672 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006673 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006674 && (totalTxTimeMs <= activityDurationMs));
6675 }
6676
Jack Yu85bd38a2015-11-09 11:34:32 -08006677 /**
6678 * {@hide}
6679 * Returns the service state information on specified subscription.
6680 */
6681 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006682 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6683 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006685 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006686 return null;
6687 }
6688
Hall Liuf19c44f2018-11-27 14:38:17 -08006689 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6690 LocationAccessPolicy.checkLocationPermission(mApp,
6691 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6692 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006693 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006694 .setCallingPid(Binder.getCallingPid())
6695 .setCallingUid(Binder.getCallingUid())
6696 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006697 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006698 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6699 .build());
6700
6701 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6702 LocationAccessPolicy.checkLocationPermission(mApp,
6703 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6704 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006705 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006706 .setCallingPid(Binder.getCallingPid())
6707 .setCallingUid(Binder.getCallingUid())
6708 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006709 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006710 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6711 .build());
6712 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6713 boolean hasFinePermission =
6714 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6715 boolean hasCoarsePermission =
6716 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 final long identity = Binder.clearCallingIdentity();
6719 try {
6720 final Phone phone = getPhone(subId);
6721 if (phone == null) {
6722 return null;
6723 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006724
Hall Liuf19c44f2018-11-27 14:38:17 -08006725 ServiceState ss = phone.getServiceState();
6726
6727 // Scrub out the location info in ServiceState depending on what level of access
6728 // the caller has.
6729 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006730 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6731 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006735 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006736
6737 /**
6738 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6739 *
6740 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6741 * voicemail ringtone.
6742 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6743 * PhoneAccount.
6744 */
6745 @Override
6746 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747 final long identity = Binder.clearCallingIdentity();
6748 try {
6749 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6750 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006751 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006754 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6755 } finally {
6756 Binder.restoreCallingIdentity(identity);
6757 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006758 }
6759
6760 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006761 * Sets the per-account voicemail ringtone.
6762 *
6763 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6764 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6765 *
6766 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6767 * voicemail ringtone.
6768 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6769 * PhoneAccount.
6770 */
6771 @Override
6772 public void setVoicemailRingtoneUri(String callingPackage,
6773 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006774 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006775 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006776 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6777 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6779 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6780 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782
6783 final long identity = Binder.clearCallingIdentity();
6784 try {
6785 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6786 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006787 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 }
6789 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006792 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006793 }
6794
6795 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006796 * Returns whether vibration is set for voicemail notification in Phone settings.
6797 *
6798 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6799 * voicemail vibration setting.
6800 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6801 */
6802 @Override
6803 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 final long identity = Binder.clearCallingIdentity();
6805 try {
6806 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6807 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006808 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6812 } finally {
6813 Binder.restoreCallingIdentity(identity);
6814 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006815 }
6816
Youhan Wange64578a2016-05-02 15:32:42 -07006817 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006818 * Sets the per-account voicemail vibration.
6819 *
6820 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6821 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6822 *
6823 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6824 * voicemail vibration setting.
6825 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6826 * specific PhoneAccount.
6827 */
6828 @Override
6829 public void setVoicemailVibrationEnabled(String callingPackage,
6830 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006831 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006832 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006833 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6834 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6836 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6837 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006838 }
6839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 final long identity = Binder.clearCallingIdentity();
6841 try {
6842 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6843 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006844 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845 }
6846 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6847 } finally {
6848 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006849 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006850 }
6851
6852 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006853 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6854 *
6855 * @throws SecurityException if the caller does not have the required permission
6856 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006857 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006858 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006859 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006860 }
6861
6862 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006863 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6864 * permission.
6865 *
6866 * @throws SecurityException if the caller does not have the required permission
6867 */
6868 private void enforceSendSmsPermission() {
6869 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6870 }
6871
6872 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006873 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006874 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006875 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006876 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006877 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006878 final long identity = Binder.clearCallingIdentity();
6879 try {
6880 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006881 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882 if (componentName == null) {
6883 throw new SecurityException(
6884 "Caller not current active visual voicemail package[null]");
6885 }
6886 String vvmPackage = componentName.getPackageName();
6887 if (!callingPackage.equals(vvmPackage)) {
6888 throw new SecurityException("Caller not current active visual voicemail package["
6889 + vvmPackage + "]");
6890 }
6891 } finally {
6892 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006893 }
6894 }
6895
6896 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006897 * Return the application ID for the app type.
6898 *
6899 * @param subId the subscription ID that this request applies to.
6900 * @param appType the uicc app type.
6901 * @return Application ID for specificied app type, or null if no uicc.
6902 */
6903 @Override
6904 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006905 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006906 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907
6908 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006909 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910 if (phone == null) {
6911 return null;
6912 }
6913 String aid = null;
6914 try {
6915 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6916 .getApplicationByType(appType).getAid();
6917 } catch (Exception e) {
6918 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6919 }
6920 return aid;
6921 } finally {
6922 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006923 }
Youhan Wange64578a2016-05-02 15:32:42 -07006924 }
6925
Youhan Wang4001d252016-05-11 10:29:41 -07006926 /**
6927 * Return the Electronic Serial Number.
6928 *
6929 * @param subId the subscription ID that this request applies to.
6930 * @return ESN or null if error.
6931 */
6932 @Override
6933 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006934 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006935 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936
6937 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006938 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 if (phone == null) {
6940 return null;
6941 }
6942 String esn = null;
6943 try {
6944 esn = phone.getEsn();
6945 } catch (Exception e) {
6946 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6947 }
6948 return esn;
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006951 }
Youhan Wang4001d252016-05-11 10:29:41 -07006952 }
6953
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006954 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006955 * Return the Preferred Roaming List Version.
6956 *
6957 * @param subId the subscription ID that this request applies to.
6958 * @return PRLVersion or null if error.
6959 */
6960 @Override
6961 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006962 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006963 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964
6965 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006966 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 if (phone == null) {
6968 return null;
6969 }
6970 String cdmaPrlVersion = null;
6971 try {
6972 cdmaPrlVersion = phone.getCdmaPrlVersion();
6973 } catch (Exception e) {
6974 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6975 }
6976 return cdmaPrlVersion;
6977 } finally {
6978 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006979 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006980 }
6981
6982 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006983 * Get snapshot of Telephony histograms
6984 * @return List of Telephony histograms
6985 * @hide
6986 */
6987 @Override
6988 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6990 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006991
6992 final long identity = Binder.clearCallingIdentity();
6993 try {
6994 return RIL.getTelephonyRILTimingHistograms();
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
6997 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006998 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006999
7000 /**
7001 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007002 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7003 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007004 * Require system privileges. In the future we may add this to carrier APIs.
7005 *
Michele Berionne482f8202018-11-27 18:57:59 -08007006 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007007 */
7008 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007009 @TelephonyManager.SetCarrierRestrictionResult
7010 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007011 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007012 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007013
Michele Berionne482f8202018-11-27 18:57:59 -08007014 if (carrierRestrictionRules == null) {
7015 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007016 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 final long identity = Binder.clearCallingIdentity();
7019 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007020 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007021 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022 } finally {
7023 Binder.restoreCallingIdentity(identity);
7024 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007025 }
7026
7027 /**
7028 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007029 * Get the allowed carrier list and the excluded carrier list, including the priority between
7030 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007031 * Require system privileges. In the future we may add this to carrier APIs.
7032 *
Michele Berionne482f8202018-11-27 18:57:59 -08007033 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007034 */
7035 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007036 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007037 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007038 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039
7040 final long identity = Binder.clearCallingIdentity();
7041 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007042 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7043 if (response instanceof CarrierRestrictionRules) {
7044 return (CarrierRestrictionRules) response;
7045 }
7046 // Response is an Exception of some kind,
7047 // which is signalled to the user as a NULL retval
7048 return null;
7049 } catch (Exception e) {
7050 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7051 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 } finally {
7053 Binder.restoreCallingIdentity(identity);
7054 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007055 }
7056
fionaxu59545b42016-05-25 15:53:37 -07007057 /**
7058 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7059 * @param subId the subscription ID that this action applies to.
7060 * @param enabled control enable or disable metered apns.
7061 * {@hide}
7062 */
7063 @Override
7064 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7065 enforceModifyPermission();
7066 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067
7068 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007069 if (phone == null) {
7070 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7071 return;
7072 }
7073 try {
7074 phone.carrierActionSetMeteredApnsEnabled(enabled);
7075 } catch (Exception e) {
7076 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077 } finally {
7078 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007079 }
7080 }
7081
7082 /**
7083 * Action set from carrier signalling broadcast receivers to enable/disable radio
7084 * @param subId the subscription ID that this action applies to.
7085 * @param enabled control enable or disable radio.
7086 * {@hide}
7087 */
7088 @Override
7089 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7090 enforceModifyPermission();
7091 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092
7093 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007094 if (phone == null) {
7095 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7096 return;
7097 }
7098 try {
7099 phone.carrierActionSetRadioEnabled(enabled);
7100 } catch (Exception e) {
7101 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 } finally {
7103 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007104 }
7105 }
7106
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007107 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007108 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7109 * network status based on which carrier apps could apply actions accordingly,
7110 * enable/disable default url handler for example.
7111 *
7112 * @param subId the subscription ID that this action applies to.
7113 * @param report control start/stop reporting the default network status.
7114 * {@hide}
7115 */
7116 @Override
7117 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7118 enforceModifyPermission();
7119 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120
7121 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007122 if (phone == null) {
7123 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7124 return;
7125 }
7126 try {
7127 phone.carrierActionReportDefaultNetworkStatus(report);
7128 } catch (Exception e) {
7129 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130 } finally {
7131 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007132 }
7133 }
7134
7135 /**
fionaxud9622282017-07-17 17:51:30 -07007136 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7137 * @param subId the subscription ID that this action applies to.
7138 * {@hide}
7139 */
7140 @Override
7141 public void carrierActionResetAll(int subId) {
7142 enforceModifyPermission();
7143 final Phone phone = getPhone(subId);
7144 if (phone == null) {
7145 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7146 return;
7147 }
7148 try {
7149 phone.carrierActionResetAll();
7150 } catch (Exception e) {
7151 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7152 }
7153 }
7154
7155 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007156 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7157 * bug report is being generated.
7158 */
7159 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007160 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007161 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7162 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007163 writer.println("Permission Denial: can't dump Phone from pid="
7164 + Binder.getCallingPid()
7165 + ", uid=" + Binder.getCallingUid()
7166 + "without permission "
7167 + android.Manifest.permission.DUMP);
7168 return;
7169 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007170 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007171 }
Jack Yueb89b242016-06-22 13:27:47 -07007172
Brad Ebingerdac2f002018-04-03 15:17:52 -07007173 @Override
7174 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7175 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7176 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007177 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7178 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007179 }
7180
Jack Yueb89b242016-06-22 13:27:47 -07007181 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007182 * Policy control of data connection. Usually used when data limit is passed.
7183 * @param enabled True if enabling the data, otherwise disabling.
7184 * @param subId Subscription index
7185 * {@hide}
7186 */
7187 @Override
7188 public void setPolicyDataEnabled(boolean enabled, int subId) {
7189 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190
7191 final long identity = Binder.clearCallingIdentity();
7192 try {
7193 Phone phone = getPhone(subId);
7194 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007195 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 }
7197 } finally {
7198 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007199 }
7200 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007201
7202 /**
7203 * Get Client request stats
7204 * @return List of Client Request Stats
7205 * @hide
7206 */
7207 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007208 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7209 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007210 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007211 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007212 return null;
7213 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007214 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216 final long identity = Binder.clearCallingIdentity();
7217 try {
7218 if (phone != null) {
7219 return phone.getClientRequestStats();
7220 }
7221
7222 return null;
7223 } finally {
7224 Binder.restoreCallingIdentity(identity);
7225 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007226 }
7227
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007228 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007229 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007230 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007231 }
Jack Yueb4124c2017-02-16 15:32:43 -08007232
7233 /**
Grace Chen70990072017-03-24 17:21:30 -07007234 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007235 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007236 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007237 * @param state State of SIM (power down, power up, pass through)
7238 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7239 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7240 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007241 *
7242 **/
7243 @Override
Grace Chen70990072017-03-24 17:21:30 -07007244 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007245 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007246 Phone phone = PhoneFactory.getPhone(slotIndex);
7247
vagdeviaf9a5b92018-08-15 16:01:53 -07007248 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007253 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254 }
7255 } finally {
7256 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007257 }
7258 }
Shuo Qiandd210312017-04-12 22:11:33 +00007259
Tyler Gunn65d45c22017-06-05 11:22:26 -07007260 private boolean isUssdApiAllowed(int subId) {
7261 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007262 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007263 if (configManager == null) {
7264 return false;
7265 }
7266 PersistableBundle pb = configManager.getConfigForSubId(subId);
7267 if (pb == null) {
7268 return false;
7269 }
7270 return pb.getBoolean(
7271 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7272 }
7273
Shuo Qiandd210312017-04-12 22:11:33 +00007274 /**
7275 * Check if phone is in emergency callback mode
7276 * @return true if phone is in emergency callback mode
7277 * @param subId sub id
7278 */
goneil9c5f4872017-12-05 14:07:56 -08007279 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007280 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007281 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007282 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007283
7284 final long identity = Binder.clearCallingIdentity();
7285 try {
7286 if (phone != null) {
7287 return phone.isInEcm();
7288 } else {
7289 return false;
7290 }
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007293 }
7294 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007295
7296 /**
7297 * Get the current signal strength information for the given subscription.
7298 * Because this information is not updated when the device is in a low power state
7299 * it should not be relied-upon to be current.
7300 * @param subId Subscription index
7301 * @return the most recent cached signal strength info from the modem
7302 */
7303 @Override
7304 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 Phone p = getPhone(subId);
7308 if (p == null) {
7309 return null;
7310 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 return p.getSignalStrength();
7313 } finally {
7314 Binder.restoreCallingIdentity(identity);
7315 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007316 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007317
Pengquan Meng77b7f132018-08-22 14:49:57 -07007318 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007319 * Get the current modem radio state for the given slot.
7320 * @param slotIndex slot index.
7321 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007322 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007323 * @return the current radio power state from the modem
7324 */
7325 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007326 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007327 Phone phone = PhoneFactory.getPhone(slotIndex);
7328 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7330 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007331 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7332 }
7333
7334 final long identity = Binder.clearCallingIdentity();
7335 try {
7336 return phone.getRadioPowerState();
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
7340 }
7341 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7342 }
7343
7344 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007345 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7346 *
7347 * <p>Requires one of the following permissions:
7348 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7349 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7350 * privileges.
7351 *
7352 * @param subId subscription id
7353 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7354 * {@code false}.
7355 */
7356 @Override
7357 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007358 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7359 null /* message */);
7360
Pengquan Menga1bb6272018-09-06 09:59:22 -07007361 boolean isEnabled = false;
7362 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007363 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007364 Phone phone = getPhone(subId);
7365 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007366 } catch (Exception e) {
7367 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7368 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007369 } finally {
7370 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007371 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007372 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007373 }
7374
7375
7376 /**
7377 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7378 *
7379 * <p> Requires permission:
7380 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7381 * privileges.
7382 *
7383 * @param subId subscription id
7384 * @param isEnabled {@code true} means enable, {@code false} means disable.
7385 */
7386 @Override
7387 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7389 mApp, subId, "setDataRoamingEnabled");
7390
Pengquan Menga1bb6272018-09-06 09:59:22 -07007391 final long identity = Binder.clearCallingIdentity();
7392 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007393 Phone phone = getPhone(subId);
7394 if (phone != null) {
7395 phone.setDataRoamingEnabled(isEnabled);
7396 }
7397 } finally {
7398 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007399 }
7400 }
7401
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007402 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007403 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007404 TelephonyPermissions
7405 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007406 mApp, subId, "isManualNetworkSelectionAllowed");
7407
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007408 boolean isAllowed = true;
7409 final long identity = Binder.clearCallingIdentity();
7410 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007411 Phone phone = getPhone(subId);
7412 if (phone != null) {
7413 isAllowed = phone.isCspPlmnEnabled();
7414 }
7415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
7418 return isAllowed;
7419 }
7420
7421 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007422 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007423 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007424 try {
7425 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007426 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007427 } catch (SecurityException e) {
7428 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7429 // has carrier privileges on an active UICC
7430 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7431 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007432 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007433 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007434 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007435
7436 final long identity = Binder.clearCallingIdentity();
7437 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007438 UiccController uiccController = UiccController.getInstance();
7439 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007440 if (hasReadPermission) {
7441 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007442 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007443
7444 // Remove private info if the caller doesn't have access
7445 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7446 for (UiccCardInfo cardInfo : cardInfos) {
7447 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7448 // is available
7449 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7450 if (card == null || card.getUiccProfile() == null) {
7451 // assume no access if the card or profile is unavailable
7452 filteredInfos.add(cardInfo.getUnprivileged());
7453 continue;
7454 }
7455 UiccProfile profile = card.getUiccProfile();
7456 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7457 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7458 filteredInfos.add(cardInfo);
7459 } else {
7460 filteredInfos.add(cardInfo.getUnprivileged());
7461 }
7462 }
7463 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
7467 }
7468
7469 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007470 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007471 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007472
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473 final long identity = Binder.clearCallingIdentity();
7474 try {
7475 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7476 if (slots == null) {
7477 Rlog.i(LOG_TAG, "slots is null.");
7478 return null;
7479 }
7480
7481 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7482 for (int i = 0; i < slots.length; i++) {
7483 UiccSlot slot = slots[i];
7484 if (slot == null) {
7485 continue;
7486 }
7487
Jordan Liu7be7e652019-05-06 18:55:02 +00007488 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 UiccCard card = slot.getUiccCard();
7490 if (card != null) {
7491 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007492 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007493 cardId = slot.getEid();
7494 if (TextUtils.isEmpty(cardId)) {
7495 cardId = slot.getIccId();
7496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 }
7498
Jordan Liu857451f2019-05-09 16:35:35 -07007499 if (cardId != null) {
7500 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7501 // if cardId is an EID, it's all digits so this is fine
7502 cardId = IccUtils.stripTrailingFs(cardId);
7503 }
7504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505 int cardState = 0;
7506 switch (slot.getCardState()) {
7507 case CARDSTATE_ABSENT:
7508 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7509 break;
7510 case CARDSTATE_PRESENT:
7511 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7512 break;
7513 case CARDSTATE_ERROR:
7514 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7515 break;
7516 case CARDSTATE_RESTRICTED:
7517 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7518 break;
7519 default:
7520 break;
7521
7522 }
7523
7524 infos[i] = new UiccSlotInfo(
7525 slot.isActive(),
7526 slot.isEuicc(),
7527 cardId,
7528 cardState,
7529 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007530 slot.isExtendedApduSupported(),
7531 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 }
7533 return infos;
7534 } finally {
7535 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007536 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007537 }
7538
7539 @Override
7540 public boolean switchSlots(int[] physicalSlots) {
7541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542
7543 final long identity = Binder.clearCallingIdentity();
7544 try {
7545 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7546 } finally {
7547 Binder.restoreCallingIdentity(identity);
7548 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007549 }
Jack Yu4c988042018-02-27 15:30:01 -08007550
7551 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007552 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007553 final long identity = Binder.clearCallingIdentity();
7554 try {
7555 return UiccController.getInstance().getCardIdForDefaultEuicc();
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
7559 }
7560
7561 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007562 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7563 enforceModifyPermission();
7564 final Phone phone = getPhone(subId);
7565 if (phone == null) {
7566 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7567 return;
7568 }
7569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 phone.setRadioIndicationUpdateMode(filters, mode);
7573 } finally {
7574 Binder.restoreCallingIdentity(identity);
7575 }
Jack Yu4c988042018-02-27 15:30:01 -08007576 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007577
7578 /**
goneil47ffb6e2018-04-06 15:40:58 -07007579 * A test API to reload the UICC profile.
7580 *
7581 * <p>Requires that the calling app has permission
7582 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7583 * @hide
7584 */
7585 @Override
7586 public void refreshUiccProfile(int subId) {
7587 enforceModifyPermission();
7588
7589 final long identity = Binder.clearCallingIdentity();
7590 try {
7591 Phone phone = getPhone(subId);
7592 if (phone == null) {
7593 return;
7594 }
7595 UiccCard uiccCard = phone.getUiccCard();
7596 if (uiccCard == null) {
7597 return;
7598 }
7599 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7600 if (uiccProfile == null) {
7601 return;
7602 }
7603 uiccProfile.refresh();
7604 } finally {
7605 Binder.restoreCallingIdentity(identity);
7606 }
7607 }
7608
7609 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007610 * Returns false if the mobile data is disabled by default, otherwise return true.
7611 */
7612 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007613 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007614 }
7615
7616 /**
7617 * Returns true if the data roaming is enabled by default, i.e the system property
7618 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7619 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7620 */
7621 private boolean getDefaultDataRoamingEnabled(int subId) {
7622 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007623 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007624 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007625 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7626 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7627 return isDataRoamingEnabled;
7628 }
7629
7630 /**
7631 * Returns the default network type for the given {@code subId}, if the default network type is
7632 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7633 */
7634 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007635 List<Integer> list = TelephonyProperties.default_network();
7636 int phoneId = mSubscriptionController.getPhoneId(subId);
7637 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7638 return list.get(phoneId);
7639 }
7640 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007641 }
fionaxua13278b2018-03-21 00:08:13 -07007642
7643 @Override
7644 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007645 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007646 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647
7648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 final Phone phone = getPhone(subId);
7651 if (phone == null) {
7652 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7653 return;
7654 }
chen xueaba88a2019-03-15 13:15:10 -07007655 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7656 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 } finally {
7658 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007659 }
fionaxua13278b2018-03-21 00:08:13 -07007660 }
7661
7662 @Override
7663 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007664 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665
7666 final long identity = Binder.clearCallingIdentity();
7667 try {
7668 final Phone phone = getPhone(subId);
7669 if (phone == null) {
7670 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7671 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7672 }
7673 return phone.getCarrierIdListVersion();
7674 } finally {
7675 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007676 }
fionaxua13278b2018-03-21 00:08:13 -07007677 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007678
7679 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007680 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7681 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007683 mApp, subId, callingPackage, callingFeatureId,
7684 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007685 return -1;
7686 }
7687
7688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
7693 }
7694 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007695
7696 @Override
7697 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007698 TelephonyPermissions
7699 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007700 mApp, subId, "getCdmaRoamingMode");
7701
7702 final long identity = Binder.clearCallingIdentity();
7703 try {
7704 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7705 } finally {
7706 Binder.restoreCallingIdentity(identity);
7707 }
7708 }
7709
7710 @Override
7711 public boolean setCdmaRoamingMode(int subId, int mode) {
7712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7713 mApp, subId, "setCdmaRoamingMode");
7714
7715 final long identity = Binder.clearCallingIdentity();
7716 try {
7717 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7718 } finally {
7719 Binder.restoreCallingIdentity(identity);
7720 }
7721 }
7722
7723 @Override
7724 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7726 mApp, subId, "setCdmaSubscriptionMode");
7727
7728 final long identity = Binder.clearCallingIdentity();
7729 try {
7730 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7731 } finally {
7732 Binder.restoreCallingIdentity(identity);
7733 }
7734 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007735
sqianc5eccab2018-10-19 18:46:41 -07007736 @Override
sqian8c685422019-02-22 15:55:18 -08007737 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007738 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007740 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7741 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007742 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7743 }
7744 final long identity = Binder.clearCallingIdentity();
7745 try {
sqian854d44b2018-12-12 16:48:18 -08007746 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7747 for (Phone phone: PhoneFactory.getPhones()) {
7748 if (phone.getEmergencyNumberTracker() != null
7749 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7750 emergencyNumberListInternal.put(
7751 phone.getSubId(),
7752 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7753 }
sqian11b7a0e2018-12-05 18:48:28 -08007754 }
sqian854d44b2018-12-12 16:48:18 -08007755 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007756 } finally {
7757 Binder.restoreCallingIdentity(identity);
7758 }
sqianc5eccab2018-10-19 18:46:41 -07007759 }
7760
7761 @Override
sqian8c685422019-02-22 15:55:18 -08007762 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007763 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007764 if (!exactMatch) {
7765 TelephonyPermissions
7766 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007767 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007768 }
7769 final long identity = Binder.clearCallingIdentity();
7770 try {
sqian854d44b2018-12-12 16:48:18 -08007771 for (Phone phone: PhoneFactory.getPhones()) {
7772 if (phone.getEmergencyNumberTracker() != null
7773 && phone.getEmergencyNumberTracker() != null) {
7774 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7775 number, exactMatch)) {
7776 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007777 }
7778 }
sqian11b7a0e2018-12-05 18:48:28 -08007779 }
7780 return false;
7781 } finally {
7782 Binder.restoreCallingIdentity(identity);
7783 }
7784 }
7785
sqianf4ca7ed2019-01-15 18:32:07 -08007786 /**
7787 * Update emergency number list for test mode.
7788 */
7789 @Override
7790 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7791 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7792 "updateEmergencyNumberListTestMode");
7793
7794 final long identity = Binder.clearCallingIdentity();
7795 try {
7796 for (Phone phone: PhoneFactory.getPhones()) {
7797 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7798 if (tracker != null) {
7799 tracker.executeEmergencyNumberTestModeCommand(action, num);
7800 }
7801 }
7802 } finally {
7803 Binder.restoreCallingIdentity(identity);
7804 }
7805 }
7806
7807 /**
7808 * Get the full emergency number list for test mode.
7809 */
7810 @Override
7811 public List<String> getEmergencyNumberListTestMode() {
7812 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7813 "getEmergencyNumberListTestMode");
7814
7815 final long identity = Binder.clearCallingIdentity();
7816 try {
7817 Set<String> emergencyNumbers = new HashSet<>();
7818 for (Phone phone: PhoneFactory.getPhones()) {
7819 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7820 if (tracker != null) {
7821 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7822 emergencyNumbers.add(num.getNumber());
7823 }
7824 }
7825 }
7826 return new ArrayList<>(emergencyNumbers);
7827 } finally {
7828 Binder.restoreCallingIdentity(identity);
7829 }
7830 }
7831
chen xud6b45bd2018-10-30 22:27:10 -07007832 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007833 public int getEmergencyNumberDbVersion(int subId) {
7834 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7835
7836 final long identity = Binder.clearCallingIdentity();
7837 try {
7838 final Phone phone = getPhone(subId);
7839 if (phone == null) {
7840 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7841 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7842 }
7843 return phone.getEmergencyNumberDbVersion();
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
7846 }
7847 }
7848
7849 @Override
7850 public void notifyOtaEmergencyNumberDbInstalled() {
7851 enforceModifyPermission();
7852
7853 final long identity = Binder.clearCallingIdentity();
7854 try {
7855 for (Phone phone: PhoneFactory.getPhones()) {
7856 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7857 if (tracker != null) {
7858 tracker.updateOtaEmergencyNumberDatabase();
7859 }
7860 }
7861 } finally {
7862 Binder.restoreCallingIdentity(identity);
7863 }
7864 }
7865
7866 @Override
7867 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7868 enforceActiveEmergencySessionPermission();
7869
7870 final long identity = Binder.clearCallingIdentity();
7871 try {
7872 for (Phone phone: PhoneFactory.getPhones()) {
7873 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7874 if (tracker != null) {
7875 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7876 }
7877 }
7878 } finally {
7879 Binder.restoreCallingIdentity(identity);
7880 }
7881 }
7882
7883 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007884 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7885 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7886 Phone phone = getPhone(subId);
7887 if (phone == null) {
7888 return null;
7889 }
7890 final long identity = Binder.clearCallingIdentity();
7891 try {
7892 UiccProfile profile = UiccController.getInstance()
7893 .getUiccProfileForPhone(phone.getPhoneId());
7894 if (profile != null) {
7895 return profile.getCertsFromCarrierPrivilegeAccessRules();
7896 }
7897 } finally {
7898 Binder.restoreCallingIdentity(identity);
7899 }
7900 return null;
7901 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007902
7903 /**
7904 * Enable or disable a modem stack.
7905 */
7906 @Override
7907 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7908 enforceModifyPermission();
7909
7910 final long identity = Binder.clearCallingIdentity();
7911 try {
7912 Phone phone = PhoneFactory.getPhone(slotIndex);
7913 if (phone == null) {
7914 return false;
7915 } else {
7916 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7917 }
7918 } finally {
7919 Binder.restoreCallingIdentity(identity);
7920 }
7921 }
Michelecea4cf22018-12-21 15:00:11 -08007922
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007923 /**
7924 * Whether a modem stack is enabled or not.
7925 */
7926 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007927 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7928 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007929 Phone phone = PhoneFactory.getPhone(slotIndex);
7930 if (phone == null) return false;
7931
7932 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007933 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7934 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007935 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7936 }
7937
7938 final long identity = Binder.clearCallingIdentity();
7939 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007940 try {
7941 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7942 } catch (NoSuchElementException ex) {
7943 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7944 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007945 } finally {
7946 Binder.restoreCallingIdentity(identity);
7947 }
7948 }
7949
Michelecea4cf22018-12-21 15:00:11 -08007950 @Override
Michele0ea7d782019-03-19 14:58:42 -07007951 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007952 enforceModifyPermission();
7953
7954 final long identity = Binder.clearCallingIdentity();
7955 try {
7956 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007957 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007958 .commit();
7959 } finally {
7960 Binder.restoreCallingIdentity(identity);
7961 }
7962 }
7963
7964 @Override
Michele0ea7d782019-03-19 14:58:42 -07007965 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007966 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007968 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7969 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007970 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007971 }
Michelecea4cf22018-12-21 15:00:11 -08007972
7973 final long identity = Binder.clearCallingIdentity();
7974 try {
Michele0ea7d782019-03-19 14:58:42 -07007975 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007976 } finally {
7977 Binder.restoreCallingIdentity(identity);
7978 }
7979 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007980
Michele0ea7d782019-03-19 14:58:42 -07007981 @TelephonyManager.IsMultiSimSupportedResult
7982 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007983 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7984 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7985 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007986 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7987 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007988 }
7989 // Check if the hardware supports multisim functionality. If usage of multisim is not
7990 // supported by the modem, indicate that it is restricted.
7991 PhoneCapability staticCapability =
7992 mPhoneConfigurationManager.getStaticPhoneCapability();
7993 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007994 loge("isMultiSimSupportedInternal: no static configuration available");
7995 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007996 }
Sarah Chin5f0ecd72019-12-06 10:24:18 -08007997 if (staticCapability.getLogicalModemUuids().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007998 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7999 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008000 }
8001 // Check if support of multiple SIMs is restricted by carrier
8002 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008003 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008004 }
8005
Michele0ea7d782019-03-19 14:58:42 -07008006 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008007 }
8008
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008009 /**
8010 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008011 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8012 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8013 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008014 * @param numOfSims number of active sims we want to switch to
8015 */
8016 @Override
8017 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008018 if (numOfSims == 1) {
8019 enforceModifyPermission();
8020 } else {
8021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8022 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8023 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008024 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008025
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008026 try {
Michele30b57b22019-03-01 12:01:14 -08008027 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008028 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008029 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8030 return;
8031 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008032 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8033 } finally {
8034 Binder.restoreCallingIdentity(identity);
8035 }
8036 }
8037
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008038 @Override
8039 public boolean isApplicationOnUicc(int subId, int appType) {
8040 enforceReadPrivilegedPermission("isApplicationOnUicc");
8041 Phone phone = getPhone(subId);
8042 if (phone == null) {
8043 return false;
8044 }
8045 final long identity = Binder.clearCallingIdentity();
8046 try {
8047 UiccCard uiccCard = phone.getUiccCard();
8048 if (uiccCard == null) {
8049 return false;
8050 }
8051 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8052 if (uiccProfile == null) {
8053 return false;
8054 }
8055 if (TelephonyManager.APPTYPE_SIM <= appType
8056 && appType <= TelephonyManager.APPTYPE_ISIM) {
8057 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8058 }
8059 return false;
8060 } finally {
8061 Binder.restoreCallingIdentity(identity);
8062 }
8063 }
8064
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008065 /**
chen xub4baa772019-04-03 10:23:41 -07008066 * Get whether making changes to modem configurations will trigger reboot.
8067 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008068 */
8069 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008070 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8071 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008073 mApp, subId, callingPackage, callingFeatureId,
8074 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008075 return false;
8076 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008077 final long identity = Binder.clearCallingIdentity();
8078 try {
8079 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8080 } finally {
8081 Binder.restoreCallingIdentity(identity);
8082 }
8083 }
8084
Nathan Harold29f5f052019-02-15 13:41:57 -08008085 private void updateModemStateMetrics() {
8086 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8087 // TODO: check the state for each modem if the api is ready.
8088 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8089 }
8090
Pengquan Meng3889a572019-01-23 11:16:29 -08008091 @Override
8092 public int[] getSlotsMapping() {
8093 enforceReadPrivilegedPermission("getSlotsMapping");
8094
8095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8098 // All logical slots should have a mapping to a physical slot.
8099 int[] logicalSlotsMapping = new int[phoneCount];
8100 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8101 for (int i = 0; i < slotInfos.length; i++) {
8102 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8103 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8104 }
8105 }
8106 return logicalSlotsMapping;
8107 } finally {
8108 Binder.restoreCallingIdentity(identity);
8109 }
8110 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008111
8112 /**
8113 * Get the IRadio HAL Version
8114 */
8115 @Override
8116 public int getRadioHalVersion() {
8117 Phone phone = getDefaultPhone();
8118 if (phone == null) return -1;
8119 HalVersion hv = phone.getHalVersion();
8120 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8121 return hv.major * 100 + hv.minor;
8122 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008123
8124 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008125 * Get the current calling package name.
8126 * @return the current calling package name
8127 */
8128 @Override
8129 public String getCurrentPackageName() {
8130 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8131 }
8132
8133 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008134 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8135 * corresponding network requests on a subId.
8136 *
8137 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008138 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008139 * 2) APN is un-metered for this subscription, or
8140 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008141 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008142 *
8143 * @return whether data is allowed for a apn type.
8144 *
8145 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008146 */
8147 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008148 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008149 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8150 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008151
8152 // Now that all security checks passes, perform the operation as ourselves.
8153 final long identity = Binder.clearCallingIdentity();
8154 try {
8155 Phone phone = getPhone(subId);
8156 if (phone == null) return false;
8157
Jack Yu41407ee2019-05-13 16:54:09 -07008158 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008159 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
8162 }
8163 }
8164
8165 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008166 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008167 enforceReadPrivilegedPermission("isApnMetered");
8168
8169 // Now that all security checks passes, perform the operation as ourselves.
8170 final long identity = Binder.clearCallingIdentity();
8171 try {
8172 Phone phone = getPhone(subId);
8173 if (phone == null) return true; // By default return true.
8174
Jack Yu41407ee2019-05-13 16:54:09 -07008175 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008176 } finally {
8177 Binder.restoreCallingIdentity(identity);
8178 }
8179 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008180
8181 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008182 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8183 int subscriptionId, IBooleanConsumer resultCallback) {
8184 enforceModifyPermission();
8185 long token = Binder.clearCallingIdentity();
8186 try {
8187 Phone phone = getPhone(subscriptionId);
8188 if (phone == null) {
8189 try {
8190 if (resultCallback != null) {
8191 resultCallback.accept(false);
8192 }
8193 } catch (RemoteException e) {
8194 // ignore
8195 }
8196 return;
8197 }
8198 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8199 Pair.create(specifiers, (x) -> {
8200 try {
8201 if (resultCallback != null) {
8202 resultCallback.accept(x);
8203 }
8204 } catch (RemoteException e) {
8205 // ignore
8206 }
8207 });
8208 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8209 } finally {
8210 Binder.restoreCallingIdentity(token);
8211 }
8212 }
8213
8214 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008215 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8216 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8217 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8218 if (iccRecords == null) {
8219 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8220 return false;
8221 }
8222 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8223 }
8224
8225 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008226 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008227 if (callingPackage == null) {
8228 callingPackage = getCurrentPackageName();
8229 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008230 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8231 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8232 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8233 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8234 }
8235 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8236 Intent intent = new Intent();
8237 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8238 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8239 // Bring up choose default SMS subscription dialog right now
8240 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8241 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8242 mApp.startActivity(intent);
8243 }
chen xud5ca2d52019-05-28 15:20:57 -07008244
8245 @Override
8246 public String getMmsUAProfUrl(int subId) {
8247 //TODO investigate if this API should require proper permission check in R b/133791609
8248 final long identity = Binder.clearCallingIdentity();
8249 try {
8250 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8251 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8252 } finally {
8253 Binder.restoreCallingIdentity(identity);
8254 }
8255 }
8256
8257 @Override
8258 public String getMmsUserAgent(int subId) {
8259 //TODO investigate if this API should require proper permission check in R b/133791609
8260 final long identity = Binder.clearCallingIdentity();
8261 try {
8262 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8263 .getString(com.android.internal.R.string.config_mms_user_agent);
8264 } finally {
8265 Binder.restoreCallingIdentity(identity);
8266 }
8267 }
Jack Yub07d4972019-05-28 16:12:25 -07008268
8269 @Override
8270 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8271 enforceModifyPermission();
8272
8273 // Now that all security checks passes, perform the operation as ourselves.
8274 final long identity = Binder.clearCallingIdentity();
8275 try {
8276 Phone phone = getPhone(subId);
8277 if (phone == null) return false;
8278
8279 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8280 } finally {
8281 Binder.restoreCallingIdentity(identity);
8282 }
8283 }
8284
8285 @Override
8286 public boolean isDataAllowedInVoiceCall(int subId) {
8287 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8288
8289 // Now that all security checks passes, perform the operation as ourselves.
8290 final long identity = Binder.clearCallingIdentity();
8291 try {
8292 Phone phone = getPhone(subId);
8293 if (phone == null) return false;
8294
8295 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8296 } finally {
8297 Binder.restoreCallingIdentity(identity);
8298 }
8299 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008300
changbetty97defcf2019-12-24 15:40:37 +08008301 @Override
8302 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8303 enforceModifyPermission();
8304
8305 // Now that all security checks passes, perform the operation as ourselves.
8306 final long identity = Binder.clearCallingIdentity();
8307 try {
8308 Phone phone = getPhone(subId);
8309 if (phone == null) return false;
8310
8311 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8312 } finally {
8313 Binder.restoreCallingIdentity(identity);
8314 }
8315 }
8316
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008317 /**
8318 * Updates whether conference event pacakge handling is enabled.
8319 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8320 * otherwise.
8321 */
8322 @Override
8323 public void setCepEnabled(boolean isCepEnabled) {
8324 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8325
8326 final long identity = Binder.clearCallingIdentity();
8327 try {
8328 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8329 for (Phone phone : PhoneFactory.getPhones()) {
8330 Phone defaultPhone = phone.getImsPhone();
8331 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8332 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8333 ImsPhoneCallTracker imsPhoneCallTracker =
8334 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8335 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8336 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8337 + imsPhone.getMsisdn());
8338 }
8339 }
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
8342 }
8343 }
allenwtsu46dcc572020-01-08 18:24:03 +08008344
8345 /**
8346 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8347 *
8348 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8349 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8350 * before being read.
8351 */
8352 @Override
8353 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8354 isCompressed) {
8355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8356 mApp, subId, "notifyRcsAutoConfigurationReceived");
8357 try {
8358 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8359 if (configBinder == null) {
8360 Rlog.e(LOG_TAG, "null result for getImsConfig");
8361 } else {
8362 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8363 }
8364 } catch (RemoteException e) {
8365 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8366 }
8367 }
zoey chenf95ca592019-12-30 16:11:23 +08008368
8369 @Override
8370 public boolean isIccLockEnabled(int subId) {
8371 enforceReadPrivilegedPermission("isIccLockEnabled");
8372
8373 // Now that all security checks passes, perform the operation as ourselves.
8374 final long identity = Binder.clearCallingIdentity();
8375 try {
8376 Phone phone = getPhone(subId);
8377 if (phone != null && phone.getIccCard() != null) {
8378 return phone.getIccCard().getIccLockEnabled();
8379 } else {
8380 return false;
8381 }
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
8385 }
8386
8387 /**
8388 * Set the ICC pin lock enabled or disabled..
8389 *
8390 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8391 * 0 or a positive integer as the attempts remaining value.
8392 *
8393 */
8394 @Override
8395 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8396 enforceModifyPermission();
8397
8398 Phone phone = getPhone(subId);
8399 if (phone == null) {
8400 return 0;
8401 }
8402 // Now that all security checks passes, perform the operation as ourselves.
8403 final long identity = Binder.clearCallingIdentity();
8404 try {
8405 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8406 new Pair<Boolean, String>(enabled, password), phone, null);
8407 return attemptsRemaining;
8408
8409 } catch (Exception e) {
8410 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8411 } finally {
8412 Binder.restoreCallingIdentity(identity);
8413 }
8414 return 0;
8415 }
8416
8417 /**
8418 * Change the ICC password used in ICC pin lock.
8419 *
8420 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8421 * 0 or a positive integer as the attempts remaining value.
8422 *
8423 */
8424 @Override
8425 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8426 enforceModifyPermission();
8427
8428 Phone phone = getPhone(subId);
8429 if (phone == null) {
8430 return 0;
8431 }
8432 // Now that all security checks passes, perform the operation as ourselves.
8433 final long identity = Binder.clearCallingIdentity();
8434 try {
8435 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8436 new Pair<String, String>(oldPassword, newPassword), phone, null);
8437 return attemptsRemaining;
8438
8439 } catch (Exception e) {
8440 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8441 } finally {
8442 Binder.restoreCallingIdentity(identity);
8443 }
8444 return 0;
8445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008446}