blob: 283484581dbd9167e603d50a2c0f043796af9438 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080067import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080068import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070069import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080079import android.telephony.DataThrottlingRequest;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070080import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070081import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080082import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070083import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080084import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070085import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080086import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080087import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070088import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080089import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080091import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080092import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080093import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080094import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070095import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070096import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080097import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -080098import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -080099import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000100import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700101import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700102import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800103import android.telephony.data.ApnSetting;
104import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700105import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800106import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700107import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700108import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800109import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700110import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800111import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700112import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700113import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800115import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800117import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700120import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800122import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800123
Andrew Lee312e8172014-10-23 17:01:36 -0700124import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800125import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800126import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700127import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700128import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700129import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800130import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700131import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700132import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800133import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800135import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800136import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700137import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700138import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800139import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800141import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700142import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700143import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700144import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700146import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800147import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700148import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700149import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700150import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700151import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700152import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700153import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700154import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800156import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800157import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800158import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700159import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800160import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700161import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800162import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700163import com.android.internal.telephony.imsphone.ImsPhone;
164import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800165import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900166import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800168import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800170import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700171import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800172import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800174import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000175import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800176import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700177import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700178import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800179import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700180import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700181import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800182import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700183import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700184import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800185import com.android.services.telephony.TelecomAccountRegistry;
186import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800187import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800188
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700189import java.io.FileDescriptor;
190import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800192import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800193import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800194import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800195import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100196import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700198import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800199import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800200import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800201import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700202
203/**
204 * Implementation of the ITelephony interface.
205 */
Santos Cordon117fee72014-05-16 17:56:12 -0700206public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207 private static final String LOG_TAG = "PhoneInterfaceManager";
208 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
209 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800210 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211
212 // Message codes used with mMainThreadHandler
213 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700214 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
215 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700216 private static final int CMD_OPEN_CHANNEL = 9;
217 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
218 private static final int CMD_CLOSE_CHANNEL = 11;
219 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800220 private static final int CMD_NV_READ_ITEM = 13;
221 private static final int EVENT_NV_READ_ITEM_DONE = 14;
222 private static final int CMD_NV_WRITE_ITEM = 15;
223 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
224 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
225 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700226 private static final int CMD_RESET_MODEM_CONFIG = 19;
227 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800228 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
229 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
230 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
231 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800232 private static final int CMD_SEND_ENVELOPE = 25;
233 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000234 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
235 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700236 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
237 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
238 private static final int CMD_EXCHANGE_SIM_IO = 31;
239 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800240 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
241 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700242 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700244 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
245 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700246 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
247 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
248 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
249 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700250 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
251 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
252 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
253 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700254 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800255 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
256 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000257 private static final int CMD_SWITCH_SLOTS = 50;
258 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700259 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
260 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
261 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
262 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
263 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
264 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
265 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
266 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700267 private static final int CMD_GET_ALL_CELL_INFO = 60;
268 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
269 private static final int CMD_GET_CELL_LOCATION = 62;
270 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700271 private static final int CMD_MODEM_REBOOT = 64;
272 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700273 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
274 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800275 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
276 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700277 private static final int CMD_GET_MODEM_STATUS = 70;
278 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700279 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
280 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700281 private static final int CMD_ERASE_MODEM_CONFIG = 74;
282 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800283 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
284 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
285 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
286 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800287 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
288 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800289 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800290 private static final int CMD_GET_CALL_FORWARDING = 83;
291 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
292 private static final int CMD_SET_CALL_FORWARDING = 85;
293 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
294 private static final int CMD_GET_CALL_WAITING = 87;
295 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
296 private static final int CMD_SET_CALL_WAITING = 89;
297 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700298 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
299 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
300 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
301 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700302 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
303 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800304 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
305 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800306 private static final int CMD_SET_DATA_THROTTLING = 99;
307 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800309 // Parameters of select command.
310 private static final int SELECT_COMMAND = 0xA4;
311 private static final int SELECT_P1 = 0x04;
312 private static final int SELECT_P2 = 0;
313 private static final int SELECT_P3 = 0x10;
314
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315 /** The singleton instance. */
316 private static PhoneInterfaceManager sInstance;
317
Wink Saville3ab207e2014-11-20 13:07:20 -0800318 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800319 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800320 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700321 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800322 private AppOpsManager mAppOps;
323 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800324 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800325 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700326 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327
Peter Wangdafb9ac2020-01-15 14:13:38 -0800328 /** User Activity */
329 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800330 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
331
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700332 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
333
Derek Tan97ebb422014-09-05 16:55:38 -0700334 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
335 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800336 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800337 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700338
Michelecea4cf22018-12-21 15:00:11 -0800339 // String to store multi SIM allowed
340 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
341
Derek Tan740e1672017-06-27 14:56:27 -0700342 // The AID of ISD-R.
343 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
344
yinxub1bed742017-04-17 11:45:04 -0700345 private NetworkScanRequestTracker mNetworkScanRequestTracker;
346
David Kelly5e06a7f2018-03-12 14:10:59 +0000347 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
348 private static final int MANUFACTURER_CODE_LENGTH = 8;
349
Jack Nudelman24d51a52020-11-24 12:08:04 -0800350 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
351
Derek Tan89e89d42014-07-08 17:00:10 -0700352 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700353 * Experiment flag to enable erase modem config on reset network, default value is false
354 */
355 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
356 "reset_network_erase_modem_config_enabled";
357
358 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700359 * A request object to use for transmitting data to an ICC.
360 */
361 private static final class IccAPDUArgument {
362 public int channel, cla, command, p1, p2, p3;
363 public String data;
364
365 public IccAPDUArgument(int channel, int cla, int command,
366 int p1, int p2, int p3, String data) {
367 this.channel = channel;
368 this.cla = cla;
369 this.command = command;
370 this.p1 = p1;
371 this.p2 = p2;
372 this.p3 = p3;
373 this.data = data;
374 }
375 }
376
377 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700378 * A request object to use for transmitting data to an ICC.
379 */
380 private static final class ManualNetworkSelectionArgument {
381 public OperatorInfo operatorInfo;
382 public boolean persistSelection;
383
384 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
385 this.operatorInfo = operatorInfo;
386 this.persistSelection = persistSelection;
387 }
388 }
389
390 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
392 * request after sending. The main thread will notify the request when it is complete.
393 */
394 private static final class MainThreadRequest {
395 /** The argument to use for the request */
396 public Object argument;
397 /** The result of the request that is run on the main thread */
398 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800399 // The subscriber id that this request applies to. Defaults to
400 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
401 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
Nathan Harold92bed182018-10-12 18:16:49 -0700403 // In cases where subId is unavailable, the caller needs to specify the phone.
404 public Phone phone;
405
vagdeviaf9a5b92018-08-15 16:01:53 -0700406 public WorkSource workSource;
407
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 public MainThreadRequest(Object argument) {
409 this.argument = argument;
410 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800411
Nathan Harold92bed182018-10-12 18:16:49 -0700412 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
413 this.argument = argument;
414 if (phone != null) {
415 this.phone = phone;
416 }
417 this.workSource = workSource;
418 }
419
vagdeviaf9a5b92018-08-15 16:01:53 -0700420 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800421 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800422 if (subId != null) {
423 this.subId = subId;
424 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700425 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 }
428
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800429 private static final class IncomingThirdPartyCallArgs {
430 public final ComponentName component;
431 public final String callId;
432 public final String callerDisplayName;
433
434 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
435 String callerDisplayName) {
436 this.component = component;
437 this.callId = callId;
438 this.callerDisplayName = callerDisplayName;
439 }
440 }
441
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 /**
443 * A handler that processes messages on the main thread in the phone process. Since many
444 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
445 * inbound binder threads to the main thread in the phone process. The Binder thread
446 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
447 * on, which will be notified when the operation completes and will contain the result of the
448 * request.
449 *
450 * <p>If a MainThreadRequest object is provided in the msg.obj field,
451 * note that request.result must be set to something non-null for the calling thread to
452 * unblock.
453 */
454 private final class MainThreadHandler extends Handler {
455 @Override
456 public void handleMessage(Message msg) {
457 MainThreadRequest request;
458 Message onCompleted;
459 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800460 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800462 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463
464 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 case CMD_HANDLE_USSD_REQUEST: {
466 request = (MainThreadRequest) msg.obj;
467 final Phone phone = getPhoneFromRequest(request);
468 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
469 String ussdRequest = ussdObject.first;
470 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700471
Pengquan Menga1bb6272018-09-06 09:59:22 -0700472 if (!isUssdApiAllowed(request.subId)) {
473 // Carrier does not support use of this API, return failure.
474 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
475 UssdResponse response = new UssdResponse(ussdRequest, null);
476 Bundle returnData = new Bundle();
477 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
478 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700479
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 request.result = true;
481 notifyRequester(request);
482 return;
483 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700484
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 try {
486 request.result = phone != null
487 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
488 } catch (CallStateException cse) {
489 request.result = false;
490 }
491 // Wake up the requesting thread
492 notifyRequester(request);
493 break;
pkanwar32d516d2016-10-14 19:37:38 -0700494 }
495
Yorke Lee716f67e2015-06-17 15:39:16 -0700496 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700497 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700498 final Phone phone = getPhoneFromRequest(request);
499 request.result = phone != null ?
500 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
501 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700502 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700506
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800510 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700511 if (uiccCard == null) {
512 loge("iccTransmitApduLogicalChannel: No UICC");
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700515 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
517 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700518 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 iccArgument.channel, iccArgument.cla, iccArgument.command,
520 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700521 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700523 break;
524
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700526 ar = (AsyncResult) msg.obj;
527 request = (MainThreadRequest) ar.userObj;
528 if (ar.exception == null && ar.result != null) {
529 request.result = ar.result;
530 } else {
531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
532 if (ar.result == null) {
533 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800534 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700535 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800536 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700537 } else {
538 loge("iccTransmitApduLogicalChannel: Unknown exception");
539 }
540 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 break;
543
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
545 request = (MainThreadRequest) msg.obj;
546 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800547 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 if (uiccCard == null) {
549 loge("iccTransmitApduBasicChannel: No UICC");
550 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 } else {
553 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
554 request);
555 uiccCard.iccTransmitApduBasicChannel(
556 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
557 iccArgument.p3, iccArgument.data, onCompleted);
558 }
559 break;
560
561 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
562 ar = (AsyncResult) msg.obj;
563 request = (MainThreadRequest) ar.userObj;
564 if (ar.exception == null && ar.result != null) {
565 request.result = ar.result;
566 } else {
567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
568 if (ar.result == null) {
569 loge("iccTransmitApduBasicChannel: Empty response");
570 } else if (ar.exception instanceof CommandException) {
571 loge("iccTransmitApduBasicChannel: CommandException: " +
572 ar.exception);
573 } else {
574 loge("iccTransmitApduBasicChannel: Unknown exception");
575 }
576 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700577 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700578 break;
579
580 case CMD_EXCHANGE_SIM_IO:
581 request = (MainThreadRequest) msg.obj;
582 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800583 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 if (uiccCard == null) {
585 loge("iccExchangeSimIO: No UICC");
586 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 } else {
589 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
590 request);
591 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
592 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
593 iccArgument.data, onCompleted);
594 }
595 break;
596
597 case EVENT_EXCHANGE_SIM_IO_DONE:
598 ar = (AsyncResult) msg.obj;
599 request = (MainThreadRequest) ar.userObj;
600 if (ar.exception == null && ar.result != null) {
601 request.result = ar.result;
602 } else {
603 request.result = new IccIoResult(0x6f, 0, (byte[])null);
604 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 break;
607
Derek Tan4d5e5c12014-02-04 11:54:58 -0800608 case CMD_SEND_ENVELOPE:
609 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800610 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 if (uiccCard == null) {
612 loge("sendEnvelopeWithStatus: No UICC");
613 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 } else {
616 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
617 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
618 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800619 break;
620
621 case EVENT_SEND_ENVELOPE_DONE:
622 ar = (AsyncResult) msg.obj;
623 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700624 if (ar.exception == null && ar.result != null) {
625 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800626 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700627 request.result = new IccIoResult(0x6F, 0, (byte[])null);
628 if (ar.result == null) {
629 loge("sendEnvelopeWithStatus: Empty response");
630 } else if (ar.exception instanceof CommandException) {
631 loge("sendEnvelopeWithStatus: CommandException: " +
632 ar.exception);
633 } else {
634 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
635 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800636 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800638 break;
639
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 case CMD_OPEN_CHANNEL:
641 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800642 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800643 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 if (uiccCard == null) {
645 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800646 request.result = new IccOpenLogicalChannelResponse(-1,
647 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700648 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700649 } else {
650 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800651 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
652 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 break;
655
656 case EVENT_OPEN_CHANNEL_DONE:
657 ar = (AsyncResult) msg.obj;
658 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700661 int[] result = (int[]) ar.result;
662 int channelId = result[0];
663 byte[] selectResponse = null;
664 if (result.length > 1) {
665 selectResponse = new byte[result.length - 1];
666 for (int i = 1; i < result.length; ++i) {
667 selectResponse[i - 1] = (byte) result[i];
668 }
669 }
670 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700671 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 if (ar.result == null) {
674 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 if (ar.exception != null) {
677 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
678 }
679
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700680 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700681 if (ar.exception instanceof CommandException) {
682 CommandException.Error error =
683 ((CommandException) (ar.exception)).getCommandError();
684 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700685 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700686 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700687 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 }
689 }
690 openChannelResp = new IccOpenLogicalChannelResponse(
691 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700693 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 break;
696
697 case CMD_CLOSE_CHANNEL:
698 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800699 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700700 if (uiccCard == null) {
701 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900702 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700703 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700704 } else {
705 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
706 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
707 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 break;
709
710 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800711 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
712 break;
713
714 case CMD_NV_READ_ITEM:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800717 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
718 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800719 break;
720
721 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 ar = (AsyncResult) msg.obj;
723 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800724 if (ar.exception == null && ar.result != null) {
725 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700726 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800727 request.result = "";
728 if (ar.result == null) {
729 loge("nvReadItem: Empty response");
730 } else if (ar.exception instanceof CommandException) {
731 loge("nvReadItem: CommandException: " +
732 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700733 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800734 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700735 }
736 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700737 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 break;
739
Jake Hambye994d462014-02-03 13:10:13 -0800740 case CMD_NV_WRITE_ITEM:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
743 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800744 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700745 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800746 break;
747
748 case EVENT_NV_WRITE_ITEM_DONE:
749 handleNullReturnEvent(msg, "nvWriteItem");
750 break;
751
752 case CMD_NV_WRITE_CDMA_PRL:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800755 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800756 break;
757
758 case EVENT_NV_WRITE_CDMA_PRL_DONE:
759 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
760 break;
761
chen xu6dac5ab2018-10-26 17:39:23 -0700762 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800763 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700764 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800766 break;
767
chen xu6dac5ab2018-10-26 17:39:23 -0700768 case EVENT_RESET_MODEM_CONFIG_DONE:
769 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800770 break;
771
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700772 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
775 request);
776 Phone phone = getPhoneFromRequest(request);
777 if (phone != null) {
778 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
779 } else {
780 loge("isNRDualConnectivityEnabled: No phone object");
781 request.result = false;
782 notifyRequester(request);
783 }
784 break;
785 }
786
787 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
788 ar = (AsyncResult) msg.obj;
789 request = (MainThreadRequest) ar.userObj;
790 if (ar.exception == null && ar.result != null) {
791 request.result = ar.result;
792 } else {
793 // request.result must be set to something non-null
794 // for the calling thread to unblock
795 if (request.result != null) {
796 request.result = ar.result;
797 } else {
798 request.result = false;
799 }
800 if (ar.result == null) {
801 loge("isNRDualConnectivityEnabled: Empty response");
802 } else if (ar.exception instanceof CommandException) {
803 loge("isNRDualConnectivityEnabled: CommandException: "
804 + ar.exception);
805 } else {
806 loge("isNRDualConnectivityEnabled: Unknown exception");
807 }
808 }
809 notifyRequester(request);
810 break;
811
812 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
815 Phone phone = getPhoneFromRequest(request);
816 if (phone != null) {
817 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
818 request.workSource);
819 } else {
820 loge("enableNrDualConnectivity: No phone object");
821 request.result =
822 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
823 notifyRequester(request);
824 }
825 break;
826 }
827
828 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
829 ar = (AsyncResult) msg.obj;
830 request = (MainThreadRequest) ar.userObj;
831 if (ar.exception == null) {
832 request.result =
833 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
834 } else {
835 request.result =
836 TelephonyManager
837 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
838 if (ar.exception instanceof CommandException) {
839 CommandException.Error error =
840 ((CommandException) (ar.exception)).getCommandError();
841 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
842 request.result =
843 TelephonyManager
844 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
845 }
846 loge("enableNrDualConnectivity" + ": CommandException: "
847 + ar.exception);
848 } else {
849 loge("enableNrDualConnectivity" + ": Unknown exception");
850 }
851 }
852 notifyRequester(request);
853 break;
854 }
855
Jake Hamby7c27be32014-03-03 13:25:59 -0800856 case CMD_GET_PREFERRED_NETWORK_TYPE:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700859 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800860 break;
861
862 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
863 ar = (AsyncResult) msg.obj;
864 request = (MainThreadRequest) ar.userObj;
865 if (ar.exception == null && ar.result != null) {
866 request.result = ar.result; // Integer
867 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530868 // request.result must be set to something non-null
869 // for the calling thread to unblock
870 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800871 if (ar.result == null) {
872 loge("getPreferredNetworkType: Empty response");
873 } else if (ar.exception instanceof CommandException) {
874 loge("getPreferredNetworkType: CommandException: " +
875 ar.exception);
876 } else {
877 loge("getPreferredNetworkType: Unknown exception");
878 }
879 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700880 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800881 break;
882
883 case CMD_SET_PREFERRED_NETWORK_TYPE:
884 request = (MainThreadRequest) msg.obj;
885 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
886 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700887 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800888 break;
889
890 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
891 handleNullReturnEvent(msg, "setPreferredNetworkType");
892 break;
893
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000894 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
895 request = (MainThreadRequest)msg.obj;
896 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800897 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000898 break;
899
900 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
901 ar = (AsyncResult)msg.obj;
902 request = (MainThreadRequest)ar.userObj;
903 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700904 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000905 break;
906
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800907 case CMD_SET_VOICEMAIL_NUMBER:
908 request = (MainThreadRequest) msg.obj;
909 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
910 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800911 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
912 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800913 break;
914
915 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
916 handleNullReturnEvent(msg, "setVoicemailNumber");
917 break;
918
Stuart Scott54788802015-03-30 13:18:01 -0700919 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
920 request = (MainThreadRequest) msg.obj;
921 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
922 request);
923 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
924 break;
925
926 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
927 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
928 break;
929
Shishir Agrawal302c8692015-06-19 13:49:39 -0700930 case CMD_PERFORM_NETWORK_SCAN:
931 request = (MainThreadRequest) msg.obj;
932 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
933 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
934 break;
935
Hall Liua1acea22020-09-18 19:04:59 -0700936 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800937 request = (MainThreadRequest) msg.obj;
938 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700939 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
940 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
941 request.argument;
942 int callForwardingReason = args.first;
943 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800944 break;
Hall Liua1acea22020-09-18 19:04:59 -0700945 }
946 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800947 ar = (AsyncResult) msg.obj;
948 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700949 TelephonyManager.CallForwardingInfoCallback callback =
950 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
951 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800952 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700953 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800954 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
955 for (CallForwardInfo callForwardInfo : callForwardInfos) {
956 // Service Class is a bit mask per 3gpp 27.007. Search for
957 // any service for voice call.
958 if ((callForwardInfo.serviceClass
959 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700960 callForwardingInfo = new CallForwardingInfo(true,
961 callForwardInfo.reason,
962 callForwardInfo.number,
963 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800964 break;
965 }
966 }
967 // Didn't find a call forward info for voice call.
968 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700969 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
970 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800971 }
Hall Liua1acea22020-09-18 19:04:59 -0700972 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800973 } else {
974 if (ar.result == null) {
975 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
976 }
977 if (ar.exception != null) {
978 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
979 }
Hall Liuae527aa2020-09-29 17:10:18 -0700980 int errorCode = TelephonyManager
981 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800982 if (ar.exception instanceof CommandException) {
983 CommandException.Error error =
984 ((CommandException) (ar.exception)).getCommandError();
985 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700986 errorCode = TelephonyManager
987 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800988 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700989 errorCode = TelephonyManager
990 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800991 }
992 }
Hall Liua1acea22020-09-18 19:04:59 -0700993 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -0800994 }
sqian80370722020-01-29 15:02:51 -0800995 break;
Hall Liua1acea22020-09-18 19:04:59 -0700996 }
sqian80370722020-01-29 15:02:51 -0800997
Hall Liua1acea22020-09-18 19:04:59 -0700998 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800999 request = (MainThreadRequest) msg.obj;
1000 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001001 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001002 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001003 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1004 request.argument).first;
1005 request.phone.setCallForwardingOption(
1006 callForwardingInfoToSet.isEnabled()
1007 ? CommandsInterface.CF_ACTION_ENABLE
1008 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001009 callForwardingInfoToSet.getReason(),
1010 callForwardingInfoToSet.getNumber(),
1011 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1012 break;
Hall Liua1acea22020-09-18 19:04:59 -07001013 }
sqian80370722020-01-29 15:02:51 -08001014
Hall Liua1acea22020-09-18 19:04:59 -07001015 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001018 Consumer<Integer> callback =
1019 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1020 request.argument).second;
1021 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001022 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001023 int errorCode = TelephonyManager.CallForwardingInfoCallback
1024 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001025 if (ar.exception instanceof CommandException) {
1026 CommandException.Error error =
1027 ((CommandException) (ar.exception)).getCommandError();
1028 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001029 errorCode = TelephonyManager.CallForwardingInfoCallback
1030 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001031 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001032 errorCode = TelephonyManager.CallForwardingInfoCallback
1033 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001034 }
1035 }
1036 callback.accept(errorCode);
1037 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001038 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001039 }
sqian80370722020-01-29 15:02:51 -08001040 break;
Hall Liua1acea22020-09-18 19:04:59 -07001041 }
sqian80370722020-01-29 15:02:51 -08001042
Hall Liua1acea22020-09-18 19:04:59 -07001043 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001044 request = (MainThreadRequest) msg.obj;
1045 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1046 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1047 break;
Hall Liua1acea22020-09-18 19:04:59 -07001048 }
sqian80370722020-01-29 15:02:51 -08001049
Hall Liua1acea22020-09-18 19:04:59 -07001050 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001051 ar = (AsyncResult) msg.obj;
1052 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001053 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001054 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1055 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001056 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001057 // Service Class is a bit mask per 3gpp 27.007.
1058 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001059 if (callForwardResults.length > 1
1060 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001061 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001062 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001063 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1064 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001065 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001066 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001067 }
1068 } else {
1069 if (ar.result == null) {
1070 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1071 }
1072 if (ar.exception != null) {
1073 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1074 }
1075 if (ar.exception instanceof CommandException) {
1076 CommandException.Error error =
1077 ((CommandException) (ar.exception)).getCommandError();
1078 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1079 callForwardingStatus =
1080 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1081 }
1082 }
1083 }
Hall Liua1acea22020-09-18 19:04:59 -07001084 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001085 break;
Hall Liua1acea22020-09-18 19:04:59 -07001086 }
sqian80370722020-01-29 15:02:51 -08001087
Hall Liua1acea22020-09-18 19:04:59 -07001088 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001089 request = (MainThreadRequest) msg.obj;
1090 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001091 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1092 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001093 break;
Hall Liua1acea22020-09-18 19:04:59 -07001094 }
sqian80370722020-01-29 15:02:51 -08001095
Hall Liua1acea22020-09-18 19:04:59 -07001096 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001099 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1100 Consumer<Integer> callback =
1101 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1102 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001103 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001104 if (ar.exception instanceof CommandException) {
1105 CommandException.Error error =
1106 ((CommandException) (ar.exception)).getCommandError();
1107 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1108 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1109 } else {
1110 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1111 }
1112 } else {
1113 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1114 }
1115 } else {
1116 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1117 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001118 }
sqian80370722020-01-29 15:02:51 -08001119 break;
Hall Liua1acea22020-09-18 19:04:59 -07001120 }
sqian80370722020-01-29 15:02:51 -08001121
Shishir Agrawal302c8692015-06-19 13:49:39 -07001122 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1123 ar = (AsyncResult) msg.obj;
1124 request = (MainThreadRequest) ar.userObj;
1125 CellNetworkScanResult cellScanResult;
1126 if (ar.exception == null && ar.result != null) {
1127 cellScanResult = new CellNetworkScanResult(
1128 CellNetworkScanResult.STATUS_SUCCESS,
1129 (List<OperatorInfo>) ar.result);
1130 } else {
1131 if (ar.result == null) {
1132 loge("getCellNetworkScanResults: Empty response");
1133 }
1134 if (ar.exception != null) {
1135 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1136 }
1137 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1138 if (ar.exception instanceof CommandException) {
1139 CommandException.Error error =
1140 ((CommandException) (ar.exception)).getCommandError();
1141 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1142 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1143 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1144 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1145 }
1146 }
1147 cellScanResult = new CellNetworkScanResult(errorCode, null);
1148 }
1149 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001150 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001151 break;
1152
1153 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1154 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001155 ManualNetworkSelectionArgument selArg =
1156 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001157 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1158 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001159 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1160 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001161 break;
1162
1163 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001164 ar = (AsyncResult) msg.obj;
1165 request = (MainThreadRequest) ar.userObj;
1166 if (ar.exception == null) {
1167 request.result = true;
1168 } else {
1169 request.result = false;
1170 loge("setNetworkSelectionModeManual " + ar.exception);
1171 }
1172 notifyRequester(request);
1173 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001174 break;
1175
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001176 case CMD_GET_MODEM_ACTIVITY_INFO:
1177 request = (MainThreadRequest) msg.obj;
1178 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001179 if (defaultPhone != null) {
1180 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001181 } else {
1182 ResultReceiver result = (ResultReceiver) request.argument;
1183 Bundle bundle = new Bundle();
1184 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1185 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1186 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001187 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001188 break;
1189
1190 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1191 ar = (AsyncResult) msg.obj;
1192 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001193 ResultReceiver result = (ResultReceiver) request.argument;
1194
1195 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001196 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001197 // Update the last modem activity info and the result of the request.
1198 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1199 if (isModemActivityInfoValid(info)) {
1200 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1201 int[] txTimeMs = info.getTransmitTimeMillis();
1202 int[] lastModemTxTimeMs = mLastModemActivityInfo
1203 .getTransmitTimeMillis();
1204 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1205 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1206 }
1207 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1208 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1209 + mLastModemActivityInfo.getSleepTimeMillis());
1210 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1211 + mLastModemActivityInfo.getIdleTimeMillis());
1212 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1213 mLastModemActivityInfo.setReceiveTimeMillis(
1214 info.getReceiveTimeMillis()
1215 + mLastModemActivityInfo.getReceiveTimeMillis());
1216 }
1217 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1218 mLastModemActivityInfo.getSleepTimeMillis(),
1219 mLastModemActivityInfo.getIdleTimeMillis(),
1220 mLastModemActivityInfo.getTransmitTimeMillis(),
1221 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001222 } else {
1223 if (ar.result == null) {
1224 loge("queryModemActivityInfo: Empty response");
1225 } else if (ar.exception instanceof CommandException) {
1226 loge("queryModemActivityInfo: CommandException: " +
1227 ar.exception);
1228 } else {
1229 loge("queryModemActivityInfo: Unknown exception");
1230 }
1231 }
sqian1a1be542020-03-05 11:37:28 -08001232 Bundle bundle = new Bundle();
1233 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1234 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001235 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001236 break;
1237
Meng Wang1a7c35a2016-05-05 20:56:15 -07001238 case CMD_SET_ALLOWED_CARRIERS:
1239 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001240 CarrierRestrictionRules argument =
1241 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001242 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001243 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001244 break;
1245
1246 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1247 ar = (AsyncResult) msg.obj;
1248 request = (MainThreadRequest) ar.userObj;
1249 if (ar.exception == null && ar.result != null) {
1250 request.result = ar.result;
1251 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001252 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1253 if (ar.exception instanceof CommandException) {
1254 loge("setAllowedCarriers: CommandException: " + ar.exception);
1255 CommandException.Error error =
1256 ((CommandException) (ar.exception)).getCommandError();
1257 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1258 request.result =
1259 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1260 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001261 } else {
1262 loge("setAllowedCarriers: Unknown exception");
1263 }
1264 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001265 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001266 break;
1267
1268 case CMD_GET_ALLOWED_CARRIERS:
1269 request = (MainThreadRequest) msg.obj;
1270 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001271 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001272 break;
1273
1274 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1275 ar = (AsyncResult) msg.obj;
1276 request = (MainThreadRequest) ar.userObj;
1277 if (ar.exception == null && ar.result != null) {
1278 request.result = ar.result;
1279 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001280 request.result = new IllegalStateException(
1281 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001282 if (ar.result == null) {
1283 loge("getAllowedCarriers: Empty response");
1284 } else if (ar.exception instanceof CommandException) {
1285 loge("getAllowedCarriers: CommandException: " +
1286 ar.exception);
1287 } else {
1288 loge("getAllowedCarriers: Unknown exception");
1289 }
1290 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001291 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001292 break;
1293
Nathan Haroldb3014052017-01-25 15:57:32 -08001294 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1295 ar = (AsyncResult) msg.obj;
1296 request = (MainThreadRequest) ar.userObj;
1297 if (ar.exception == null && ar.result != null) {
1298 request.result = ar.result;
1299 } else {
1300 request.result = new IllegalArgumentException(
1301 "Failed to retrieve Forbidden Plmns");
1302 if (ar.result == null) {
1303 loge("getForbiddenPlmns: Empty response");
1304 } else {
1305 loge("getForbiddenPlmns: Unknown exception");
1306 }
1307 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001308 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001309 break;
1310
1311 case CMD_GET_FORBIDDEN_PLMNS:
1312 request = (MainThreadRequest) msg.obj;
1313 uiccCard = getUiccCardFromRequest(request);
1314 if (uiccCard == null) {
1315 loge("getForbiddenPlmns() UiccCard is null");
1316 request.result = new IllegalArgumentException(
1317 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001318 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001319 break;
1320 }
1321 Integer appType = (Integer) request.argument;
1322 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1323 if (uiccApp == null) {
1324 loge("getForbiddenPlmns() no app with specified type -- "
1325 + appType);
1326 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001327 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001328 break;
1329 } else {
1330 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1331 + " specified type -- " + appType);
1332 }
1333 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1334 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1335 onCompleted);
1336 break;
1337
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001338 case CMD_SWITCH_SLOTS:
1339 request = (MainThreadRequest) msg.obj;
1340 int[] physicalSlots = (int[]) request.argument;
1341 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1342 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1343 break;
1344
1345 case EVENT_SWITCH_SLOTS_DONE:
1346 ar = (AsyncResult) msg.obj;
1347 request = (MainThreadRequest) ar.userObj;
1348 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001349 notifyRequester(request);
1350 break;
1351 case CMD_GET_NETWORK_SELECTION_MODE:
1352 request = (MainThreadRequest) msg.obj;
1353 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1354 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1355 break;
1356
1357 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1358 ar = (AsyncResult) msg.obj;
1359 request = (MainThreadRequest) ar.userObj;
1360 if (ar.exception != null) {
1361 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1362 } else {
1363 int mode = ((int[]) ar.result)[0];
1364 if (mode == 0) {
1365 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1366 } else {
1367 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1368 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001369 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001370 notifyRequester(request);
1371 break;
1372 case CMD_GET_CDMA_ROAMING_MODE:
1373 request = (MainThreadRequest) msg.obj;
1374 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1375 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1376 break;
1377 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1378 ar = (AsyncResult) msg.obj;
1379 request = (MainThreadRequest) ar.userObj;
1380 if (ar.exception != null) {
1381 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1382 } else {
1383 request.result = ((int[]) ar.result)[0];
1384 }
1385 notifyRequester(request);
1386 break;
1387 case CMD_SET_CDMA_ROAMING_MODE:
1388 request = (MainThreadRequest) msg.obj;
1389 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1390 int mode = (int) request.argument;
1391 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1392 break;
1393 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1394 ar = (AsyncResult) msg.obj;
1395 request = (MainThreadRequest) ar.userObj;
1396 request.result = ar.exception == null;
1397 notifyRequester(request);
1398 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001399 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1400 request = (MainThreadRequest) msg.obj;
1401 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1402 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1403 break;
1404 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1405 ar = (AsyncResult) msg.obj;
1406 request = (MainThreadRequest) ar.userObj;
1407 if (ar.exception != null) {
1408 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1409 } else {
1410 request.result = ((int[]) ar.result)[0];
1411 }
1412 notifyRequester(request);
1413 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001414 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1415 request = (MainThreadRequest) msg.obj;
1416 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1417 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001418 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1419 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001420 break;
1421 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
1424 request.result = ar.exception == null;
1425 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001426 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001427 case CMD_GET_ALL_CELL_INFO:
1428 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001429 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001430 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001431 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001432 case EVENT_GET_ALL_CELL_INFO_DONE:
1433 ar = (AsyncResult) msg.obj;
1434 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001435 // If a timeout occurs, the response will be null
1436 request.result = (ar.exception == null && ar.result != null)
1437 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001438 synchronized (request) {
1439 request.notifyAll();
1440 }
1441 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001442 case CMD_REQUEST_CELL_INFO_UPDATE:
1443 request = (MainThreadRequest) msg.obj;
1444 request.phone.requestCellInfoUpdate(request.workSource,
1445 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1446 break;
1447 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1451 try {
1452 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001453 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001454 cb.onError(
1455 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1456 ar.exception.getClass().getName(),
1457 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001458 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001459 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001460 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001461 } else {
1462 // use the result as returned
1463 cb.onCellInfo((List<CellInfo>) ar.result);
1464 }
1465 } catch (RemoteException re) {
1466 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1467 }
1468 break;
Sarah Chincc055732020-11-18 13:39:35 -08001469 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001470 request = (MainThreadRequest) msg.obj;
1471 WorkSource ws = (WorkSource) request.argument;
1472 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001473 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001474 break;
Sarah Chincc055732020-11-18 13:39:35 -08001475 }
1476 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001477 ar = (AsyncResult) msg.obj;
1478 request = (MainThreadRequest) ar.userObj;
1479 if (ar.exception == null) {
1480 request.result = ar.result;
1481 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001482 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001483 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001484 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001485 }
1486
1487 synchronized (request) {
1488 request.notifyAll();
1489 }
1490 break;
Sarah Chincc055732020-11-18 13:39:35 -08001491 }
chen xu6dac5ab2018-10-26 17:39:23 -07001492 case CMD_MODEM_REBOOT:
1493 request = (MainThreadRequest) msg.obj;
1494 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001495 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001496 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001497 case EVENT_CMD_MODEM_REBOOT_DONE:
1498 handleNullReturnEvent(msg, "rebootModem");
1499 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001500 case CMD_REQUEST_ENABLE_MODEM:
1501 request = (MainThreadRequest) msg.obj;
1502 boolean enable = (boolean) request.argument;
1503 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001504 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001505 PhoneConfigurationManager.getInstance()
1506 .enablePhone(request.phone, enable, onCompleted);
1507 break;
1508 case EVENT_ENABLE_MODEM_DONE:
1509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001512 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001513 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001514 if ((boolean) request.result) {
1515 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1516 updateModemStateMetrics();
1517 } else {
1518 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1519 + ar.exception);
1520 }
1521 notifyRequester(request);
1522 break;
1523 case CMD_GET_MODEM_STATUS:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1526 PhoneConfigurationManager.getInstance()
1527 .getPhoneStatusFromModem(request.phone, onCompleted);
1528 break;
1529 case EVENT_GET_MODEM_STATUS_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 int id = request.phone.getPhoneId();
1533 if (ar.exception == null && ar.result != null) {
1534 request.result = ar.result;
1535 //update the cache as modem status has changed
1536 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1537 (boolean) request.result);
1538 } else {
1539 // Return true if modem status cannot be retrieved. For most cases,
1540 // modem status is on. And for older version modems, GET_MODEM_STATUS
1541 // and disable modem are not supported. Modem is always on.
1542 // TODO: this should be fixed in R to support a third
1543 // status UNKNOWN b/131631629
1544 request.result = true;
1545 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1546 + ar.exception);
1547 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001548 notifyRequester(request);
1549 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001550 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1551 request = (MainThreadRequest) msg.obj;
1552 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1553 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1554 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1555 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1556 break;
1557 }
1558 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1559 ar = (AsyncResult) msg.obj;
1560 request = (MainThreadRequest) ar.userObj;
1561 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1562 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1563 args.second.accept(ar.exception == null);
1564 notifyRequester(request);
1565 break;
1566 }
Sarah Chincc055732020-11-18 13:39:35 -08001567 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1568 request = (MainThreadRequest) msg.obj;
1569 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1570 Phone phone = getPhoneFromRequest(request);
1571 if (phone != null) {
1572 phone.getSystemSelectionChannels(onCompleted);
1573 } else {
1574 loge("getSystemSelectionChannels: No phone object");
1575 request.result = new ArrayList<RadioAccessSpecifier>();
1576 notifyRequester(request);
1577 }
1578 break;
1579 }
1580 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1581 ar = (AsyncResult) msg.obj;
1582 request = (MainThreadRequest) ar.userObj;
1583 if (ar.exception == null && ar.result != null) {
1584 request.result = ar.result;
1585 } else {
1586 request.result = new IllegalArgumentException(
1587 "Failed to retrieve system selection channels");
1588 if (ar.result == null) {
1589 loge("getSystemSelectionChannels: Empty response");
1590 } else {
1591 loge("getSystemSelectionChannels: Unknown exception");
1592 }
1593 }
1594 notifyRequester(request);
1595 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001596 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1597 ar = (AsyncResult) msg.obj;
1598 request = (MainThreadRequest) ar.userObj;
1599 if (ar.exception == null && ar.result != null) {
1600 request.result = ar.result;
1601 } else {
1602 request.result = -1;
1603 loge("Failed to set Forbidden Plmns");
1604 if (ar.result == null) {
1605 loge("setForbidenPlmns: Empty response");
1606 } else if (ar.exception != null) {
1607 loge("setForbiddenPlmns: Exception: " + ar.exception);
1608 request.result = -1;
1609 } else {
1610 loge("setForbiddenPlmns: Unknown exception");
1611 }
1612 }
1613 notifyRequester(request);
1614 break;
1615 case CMD_SET_FORBIDDEN_PLMNS:
1616 request = (MainThreadRequest) msg.obj;
1617 uiccCard = getUiccCardFromRequest(request);
1618 if (uiccCard == null) {
1619 loge("setForbiddenPlmns: UiccCard is null");
1620 request.result = -1;
1621 notifyRequester(request);
1622 break;
1623 }
1624 Pair<Integer, List<String>> setFplmnsArgs =
1625 (Pair<Integer, List<String>>) request.argument;
1626 appType = setFplmnsArgs.first;
1627 List<String> fplmns = setFplmnsArgs.second;
1628 uiccApp = uiccCard.getApplicationByType(appType);
1629 if (uiccApp == null) {
1630 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1631 request.result = -1;
1632 loge("Failed to get UICC App");
1633 notifyRequester(request);
1634 } else {
1635 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1636 ((SIMRecords) uiccApp.getIccRecords())
1637 .setForbiddenPlmns(onCompleted, fplmns);
1638 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001639 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001640 case CMD_ERASE_MODEM_CONFIG:
1641 request = (MainThreadRequest) msg.obj;
1642 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1643 defaultPhone.eraseModemConfig(onCompleted);
1644 break;
1645 case EVENT_ERASE_MODEM_CONFIG_DONE:
1646 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001647 break;
zoey chenf95ca592019-12-30 16:11:23 +08001648
1649 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1650 request = (MainThreadRequest) msg.obj;
1651 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1652 Pair<String, String> changed = (Pair<String, String>) request.argument;
1653 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1654 changed.first, changed.second, onCompleted);
1655 break;
1656 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1657 ar = (AsyncResult) msg.obj;
1658 request = (MainThreadRequest) ar.userObj;
1659 if (ar.exception == null) {
1660 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1661 } else {
1662 request.result = msg.arg1;
1663 }
1664 notifyRequester(request);
1665 break;
1666
1667 case CMD_SET_ICC_LOCK_ENABLED:
1668 request = (MainThreadRequest) msg.obj;
1669 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1670 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1671 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1672 enabled.first, enabled.second, onCompleted);
1673 break;
1674 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1675 ar = (AsyncResult) msg.obj;
1676 request = (MainThreadRequest) ar.userObj;
1677 if (ar.exception == null) {
1678 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1679 } else {
1680 request.result = msg.arg1;
1681 }
1682 notifyRequester(request);
1683 break;
1684
Peter Wangdafb9ac2020-01-15 14:13:38 -08001685 case MSG_NOTIFY_USER_ACTIVITY:
1686 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001687 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001688 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1689 getDefaultPhone().getContext().sendBroadcastAsUser(
1690 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1691 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001692
1693 case CMD_SET_DATA_THROTTLING: {
1694 request = (MainThreadRequest) msg.obj;
1695 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1696 DataThrottlingRequest dataThrottlingRequest =
1697 (DataThrottlingRequest) request.argument;
1698 Phone phone = getPhoneFromRequest(request);
1699 if (phone != null) {
1700 phone.setDataThrottling(onCompleted,
1701 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1702 dataThrottlingRequest.getCompletionDurationMillis());
1703 } else {
1704 loge("setDataThrottling: No phone object");
1705 request.result =
1706 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1707 notifyRequester(request);
1708 }
1709
1710 break;
1711 }
1712 case EVENT_SET_DATA_THROTTLING_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715
1716 if (ar.exception == null) {
1717 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1718 } else if (ar.exception instanceof CommandException) {
1719 loge("setDataThrottling: CommandException: " + ar.exception);
1720 CommandException.Error error =
1721 ((CommandException) (ar.exception)).getCommandError();
1722
1723 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1724 request.result = TelephonyManager
1725 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1726 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1727 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1728 } else {
1729 request.result =
1730 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1731 }
1732 } else {
1733 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1734 }
1735 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1736 notifyRequester(request);
1737 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 default:
1739 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1740 break;
1741 }
1742 }
Jake Hambye994d462014-02-03 13:10:13 -08001743
Pengquan Menga1bb6272018-09-06 09:59:22 -07001744 private void notifyRequester(MainThreadRequest request) {
1745 synchronized (request) {
1746 request.notifyAll();
1747 }
1748 }
1749
Jake Hambye994d462014-02-03 13:10:13 -08001750 private void handleNullReturnEvent(Message msg, String command) {
1751 AsyncResult ar = (AsyncResult) msg.obj;
1752 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1753 if (ar.exception == null) {
1754 request.result = true;
1755 } else {
1756 request.result = false;
1757 if (ar.exception instanceof CommandException) {
1758 loge(command + ": CommandException: " + ar.exception);
1759 } else {
1760 loge(command + ": Unknown exception");
1761 }
1762 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001763 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 }
1766
1767 /**
1768 * Posts the specified command to be executed on the main thread,
1769 * waits for the request to complete, and returns the result.
1770 * @see #sendRequestAsync
1771 */
1772 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001773 return sendRequest(
1774 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001775 }
1776
1777 /**
1778 * Posts the specified command to be executed on the main thread,
1779 * waits for the request to complete, and returns the result.
1780 * @see #sendRequestAsync
1781 */
1782 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1783 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001784 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001785 }
1786
1787 /**
1788 * Posts the specified command to be executed on the main thread,
1789 * waits for the request to complete, and returns the result.
1790 * @see #sendRequestAsync
1791 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001792 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001793 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001794 }
1795
1796 /**
1797 * Posts the specified command to be executed on the main thread,
1798 * waits for the request to complete, and returns the result.
1799 * @see #sendRequestAsync
1800 */
Nathan Harold92bed182018-10-12 18:16:49 -07001801 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1802 return sendRequest(command, argument, subId, null, workSource);
1803 }
1804
1805 /**
1806 * Posts the specified command to be executed on the main thread,
1807 * waits for the request to complete, and returns the result.
1808 * @see #sendRequestAsync
1809 */
1810 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1811 return sendRequest(
1812 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1813 }
1814
1815 /**
1816 * Posts the specified command to be executed on the main thread,
1817 * waits for the request to complete, and returns the result.
1818 * @see #sendRequestAsync
1819 */
1820 private Object sendRequest(
1821 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1823 throw new RuntimeException("This method will deadlock if called from the main thread.");
1824 }
1825
Nathan Harold92bed182018-10-12 18:16:49 -07001826 MainThreadRequest request = null;
1827 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1828 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1829 } else if (phone != null) {
1830 request = new MainThreadRequest(argument, phone, workSource);
1831 } else {
1832 request = new MainThreadRequest(argument, subId, workSource);
1833 }
1834
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 Message msg = mMainThreadHandler.obtainMessage(command, request);
1836 msg.sendToTarget();
1837
1838 // Wait for the request to complete
1839 synchronized (request) {
1840 while (request.result == null) {
1841 try {
1842 request.wait();
1843 } catch (InterruptedException e) {
1844 // Do nothing, go back and wait until the request is complete
1845 }
1846 }
1847 }
1848 return request.result;
1849 }
1850
1851 /**
1852 * Asynchronous ("fire and forget") version of sendRequest():
1853 * Posts the specified command to be executed on the main thread, and
1854 * returns immediately.
1855 * @see #sendRequest
1856 */
1857 private void sendRequestAsync(int command) {
1858 mMainThreadHandler.sendEmptyMessage(command);
1859 }
1860
1861 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001862 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001863 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001864 */
1865 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001866 sendRequestAsync(command, argument, null, null);
1867 }
1868
1869 /**
1870 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1871 * @see {@link #sendRequest(int,Object)}
1872 */
1873 private void sendRequestAsync(
1874 int command, Object argument, Phone phone, WorkSource workSource) {
1875 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001876 Message msg = mMainThreadHandler.obtainMessage(command, request);
1877 msg.sendToTarget();
1878 }
1879
1880 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 * Initialize the singleton PhoneInterfaceManager instance.
1882 * This is only done once, at startup, from PhoneApp.onCreate().
1883 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001884 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 synchronized (PhoneInterfaceManager.class) {
1886 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001887 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 } else {
1889 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1890 }
1891 return sInstance;
1892 }
1893 }
1894
1895 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001896 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001899 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001900 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1902 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001903 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001904 mTelephonySharedPreferences =
1905 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001906 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001907 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001908 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001909
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 publish();
1911 }
1912
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001913 private Phone getDefaultPhone() {
1914 Phone thePhone = getPhone(getDefaultSubscription());
1915 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1916 }
1917
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 private void publish() {
1919 if (DBG) log("publish: " + this);
1920
Peter Wangc035ce42020-01-08 21:00:22 -08001921 TelephonyFrameworkInitializer
1922 .getTelephonyServiceManager()
1923 .getTelephonyServiceRegisterer()
1924 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
Stuart Scott584921c2015-01-15 17:10:34 -08001927 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001928 if (request.phone != null) {
1929 return request.phone;
1930 } else {
1931 return getPhoneFromSubId(request.subId);
1932 }
1933 }
1934
1935 private Phone getPhoneFromSubId(int subId) {
1936 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1937 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001938 }
1939
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001940 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1941 Phone phone = getPhoneFromRequest(request);
1942 return phone == null ? null :
1943 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1944 }
1945
Wink Saville36469e72014-06-11 15:17:00 -07001946 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001947 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001948 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001951 private void sendEraseModemConfig(Phone phone) {
1952 if (phone != null) {
1953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1954 mApp, phone.getSubId(), "eraseModemConfig");
1955 final long identity = Binder.clearCallingIdentity();
1956 try {
1957 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1958 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
1961 }
1962 }
1963 }
1964
Peter Wang050bb052020-01-13 23:33:09 -08001965 private boolean isImsAvailableOnDevice() {
1966 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1967 if (pm == null) {
1968 // For some reason package manger is not available.. This will fail internally anyway,
1969 // so do not throw error and allow.
1970 return true;
1971 }
1972 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1973 }
1974
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001976 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001977 }
1978
Wink Savilleb564aae2014-10-23 10:18:09 -07001979 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001980 if (DBG) log("dial: " + number);
1981 // No permission check needed here: This is just a wrapper around the
1982 // ACTION_DIAL intent, which is available to any app since it puts up
1983 // the UI before it does anything.
1984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
1987 String url = createTelUrl(number);
1988 if (url == null) {
1989 return;
1990 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001992 // PENDING: should we just silently fail if phone is offhook or ringing?
1993 PhoneConstants.State state = mCM.getState(subId);
1994 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1995 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1996 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1997 mApp.startActivity(intent);
1998 }
1999 } finally {
2000 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 }
2002 }
2003
2004 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002005 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002006 }
2007
Wink Savilleb564aae2014-10-23 10:18:09 -07002008 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 if (DBG) log("call: " + number);
2010
2011 // This is just a wrapper around the ACTION_CALL intent, but we still
2012 // need to do a permission check since we're calling startActivity()
2013 // from the context of the phone app.
2014 enforceCallPermission();
2015
Jordan Liu1617b712019-07-10 15:06:26 -07002016 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 != AppOpsManager.MODE_ALLOWED) {
2018 return;
2019 }
2020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 String url = createTelUrl(number);
2024 if (url == null) {
2025 return;
2026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028 boolean isValid = false;
2029 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2030 if (slist != null) {
2031 for (SubscriptionInfo subInfoRecord : slist) {
2032 if (subInfoRecord.getSubscriptionId() == subId) {
2033 isValid = true;
2034 break;
2035 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002036 }
Wink Saville08874612014-08-31 19:19:58 -07002037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 if (!isValid) {
2039 return;
2040 }
Wink Saville08874612014-08-31 19:19:58 -07002041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2043 intent.putExtra(SUBSCRIPTION_KEY, subId);
2044 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2045 mApp.startActivity(intent);
2046 } finally {
2047 Binder.restoreCallingIdentity(identity);
2048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 }
2050
Wink Savilleb564aae2014-10-23 10:18:09 -07002051 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002052 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002053 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2054 }
2055
Wink Savilleb564aae2014-10-23 10:18:09 -07002056 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002057 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002058 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2059 }
2060
Wink Savilleb564aae2014-10-23 10:18:09 -07002061 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002063
2064 final long identity = Binder.clearCallingIdentity();
2065 try {
2066 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2067 checkSimPin.start();
2068 return checkSimPin.unlockSim(null, pin);
2069 } finally {
2070 Binder.restoreCallingIdentity(identity);
2071 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 }
2073
Wink Savilleb564aae2014-10-23 10:18:09 -07002074 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002075 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2080 checkSimPuk.start();
2081 return checkSimPuk.unlockSim(puk, pin);
2082 } finally {
2083 Binder.restoreCallingIdentity(identity);
2084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 }
2086
2087 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002088 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 * a synchronous one.
2090 */
2091 private static class UnlockSim extends Thread {
2092
2093 private final IccCard mSimCard;
2094
2095 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002096 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2097 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098
2099 // For replies from SimCard interface
2100 private Handler mHandler;
2101
2102 // For async handler to identify request type
2103 private static final int SUPPLY_PIN_COMPLETE = 100;
2104
2105 public UnlockSim(IccCard simCard) {
2106 mSimCard = simCard;
2107 }
2108
2109 @Override
2110 public void run() {
2111 Looper.prepare();
2112 synchronized (UnlockSim.this) {
2113 mHandler = new Handler() {
2114 @Override
2115 public void handleMessage(Message msg) {
2116 AsyncResult ar = (AsyncResult) msg.obj;
2117 switch (msg.what) {
2118 case SUPPLY_PIN_COMPLETE:
2119 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2120 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002121 mRetryCount = msg.arg1;
2122 if (ar.exception != null) {
2123 if (ar.exception instanceof CommandException &&
2124 ((CommandException)(ar.exception)).getCommandError()
2125 == CommandException.Error.PASSWORD_INCORRECT) {
2126 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002127 } //When UiccCardApp dispose,handle message and return exception
2128 else if (ar.exception instanceof CommandException &&
2129 ((CommandException) (ar.exception)).getCommandError()
2130 == CommandException.Error.ABORTED) {
2131 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002132 } else {
2133 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2134 }
2135 } else {
2136 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 mDone = true;
2139 UnlockSim.this.notifyAll();
2140 }
2141 break;
2142 }
2143 }
2144 };
2145 UnlockSim.this.notifyAll();
2146 }
2147 Looper.loop();
2148 }
2149
2150 /*
2151 * Use PIN or PUK to unlock SIM card
2152 *
2153 * If PUK is null, unlock SIM card with PIN
2154 *
2155 * If PUK is not null, unlock SIM card with PUK and set PIN code
2156 */
Wink Saville9de0f752013-10-22 19:04:03 -07002157 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158
2159 while (mHandler == null) {
2160 try {
2161 wait();
2162 } catch (InterruptedException e) {
2163 Thread.currentThread().interrupt();
2164 }
2165 }
2166 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2167
2168 if (puk == null) {
2169 mSimCard.supplyPin(pin, callback);
2170 } else {
2171 mSimCard.supplyPuk(puk, pin, callback);
2172 }
2173
2174 while (!mDone) {
2175 try {
2176 Log.d(LOG_TAG, "wait for done");
2177 wait();
2178 } catch (InterruptedException e) {
2179 // Restore the interrupted status
2180 Thread.currentThread().interrupt();
2181 }
2182 }
2183 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002184 int[] resultArray = new int[2];
2185 resultArray[0] = mResult;
2186 resultArray[1] = mRetryCount;
2187 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 }
2189 }
2190
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002191 /**
2192 * This method has been removed due to privacy and stability concerns.
2193 */
2194 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002196 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2197 return;
Wink Saville36469e72014-06-11 15:17:00 -07002198 }
2199
Nathan Harold1f889d82020-06-04 17:05:26 -07002200 @Override
2201 public void updateServiceLocationWithPackageName(String callingPackage) {
2202 mApp.getSystemService(AppOpsManager.class)
2203 .checkPackage(Binder.getCallingUid(), callingPackage);
2204
2205 final int targetSdk = getTargetSdk(callingPackage);
2206 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2207 // Callers targeting S have no business invoking this method.
2208 return;
2209 }
2210
2211 LocationAccessPolicy.LocationPermissionResult locationResult =
2212 LocationAccessPolicy.checkLocationPermission(mApp,
2213 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2214 .setCallingPackage(callingPackage)
2215 .setCallingFeatureId(null)
2216 .setCallingPid(Binder.getCallingPid())
2217 .setCallingUid(Binder.getCallingUid())
2218 .setMethod("updateServiceLocation")
2219 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2220 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2221 .build());
2222 // Apps that lack location permission have no business calling this method;
2223 // however, because no permission was declared in the public API, denials must
2224 // all be "soft".
2225 switch (locationResult) {
2226 case DENIED_HARD: /* fall through */
2227 case DENIED_SOFT:
2228 return;
2229 }
2230
2231 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232 final long identity = Binder.clearCallingIdentity();
2233 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002234 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002236 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002237 }
2238 } finally {
2239 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 }
2242
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002243 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002244 @Override
2245 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002246 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002247 }
2248
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002249
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002250 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002251 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2252 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2253 callingFeatureId);
2254 }
2255
2256 @Deprecated
2257 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002258 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002259 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2260 }
2261
2262 @Override
2263 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2264 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002266 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002267 return false;
2268 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269
2270 final long identity = Binder.clearCallingIdentity();
2271 try {
2272 return isRadioOnForSubscriber(subId);
2273 } finally {
2274 Binder.restoreCallingIdentity(identity);
2275 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002276 }
2277
2278 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279 final long identity = Binder.clearCallingIdentity();
2280 try {
2281 final Phone phone = getPhone(subId);
2282 if (phone != null) {
2283 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2284 } else {
2285 return false;
2286 }
2287 } finally {
2288 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 }
2291
2292 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002293 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
Wink Saville36469e72014-06-11 15:17:00 -07002295
Wink Savilleb564aae2014-10-23 10:18:09 -07002296 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298
2299 final long identity = Binder.clearCallingIdentity();
2300 try {
2301 final Phone phone = getPhone(subId);
2302 if (phone != null) {
2303 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2304 }
2305 } finally {
2306 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 }
Wink Saville36469e72014-06-11 15:17:00 -07002308 }
2309
2310 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002311 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002312 }
2313
Wink Savilleb564aae2014-10-23 10:18:09 -07002314 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002315 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002316
2317 final long identity = Binder.clearCallingIdentity();
2318 try {
2319 final Phone phone = getPhone(subId);
2320 if (phone == null) {
2321 return false;
2322 }
2323 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2324 toggleRadioOnOffForSubscriber(subId);
2325 }
2326 return true;
2327 } finally {
2328 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 }
Wink Saville36469e72014-06-11 15:17:00 -07002331
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002332 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002333 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002334 /*
2335 * If any of the Radios are available, it will need to be
2336 * shutdown. So return true if any Radio is available.
2337 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338 final long identity = Binder.clearCallingIdentity();
2339 try {
2340 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2341 Phone phone = PhoneFactory.getPhone(i);
2342 if (phone != null && phone.isRadioAvailable()) return true;
2343 }
2344 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2345 return false;
2346 } finally {
2347 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002348 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002349 }
2350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002352 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002353 enforceModifyPermission();
2354
2355 final long identity = Binder.clearCallingIdentity();
2356 try {
2357 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2358 logv("Shutting down Phone " + i);
2359 shutdownRadioUsingPhoneId(i);
2360 }
2361 } finally {
2362 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002363 }
2364 }
2365
2366 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002367 Phone phone = PhoneFactory.getPhone(phoneId);
2368 if (phone != null && phone.isRadioAvailable()) {
2369 phone.shutdownRadio();
2370 }
2371 }
2372
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002374 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375
2376 final long identity = Binder.clearCallingIdentity();
2377 try {
2378 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2379 if (defaultPhone != null) {
2380 defaultPhone.setRadioPower(turnOn);
2381 return true;
2382 } else {
2383 loge("There's no default phone.");
2384 return false;
2385 }
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002388 }
Wink Saville36469e72014-06-11 15:17:00 -07002389 }
2390
Wink Savilleb564aae2014-10-23 10:18:09 -07002391 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393
2394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 final Phone phone = getPhone(subId);
2397 if (phone != null) {
2398 phone.setRadioPower(turnOn);
2399 return true;
2400 } else {
2401 return false;
2402 }
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 }
2407
Wink Saville36469e72014-06-11 15:17:00 -07002408 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002409 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 public boolean enableDataConnectivity() {
2411 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002412
2413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 int subId = mSubscriptionController.getDefaultDataSubId();
2416 final Phone phone = getPhone(subId);
2417 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002418 phone.getDataEnabledSettings().setDataEnabled(
2419 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420 return true;
2421 } else {
2422 return false;
2423 }
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 }
2428
Wink Saville36469e72014-06-11 15:17:00 -07002429 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002430 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 public boolean disableDataConnectivity() {
2432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002433
2434 final long identity = Binder.clearCallingIdentity();
2435 try {
2436 int subId = mSubscriptionController.getDefaultDataSubId();
2437 final Phone phone = getPhone(subId);
2438 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002439 phone.getDataEnabledSettings().setDataEnabled(
2440 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002441 return true;
2442 } else {
2443 return false;
2444 }
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002448 }
2449
Sanket Padawe356d7632015-06-22 14:03:32 -07002450 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002451 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002452 final long identity = Binder.clearCallingIdentity();
2453 try {
2454 final Phone phone = getPhone(subId);
2455 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002456 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 } else {
2458 return false;
2459 }
2460 } finally {
2461 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464
2465 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002466 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
2468
pkanwarae03a6b2016-11-06 20:37:09 -08002469 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 enforceCallPermission();
2471
2472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2475 return;
2476 }
2477 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2478 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2479 } finally {
2480 Binder.restoreCallingIdentity(identity);
2481 }
pkanwar32d516d2016-10-14 19:37:38 -07002482 };
2483
Wink Savilleb564aae2014-10-23 10:18:09 -07002484 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486
2487 final long identity = Binder.clearCallingIdentity();
2488 try {
2489 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2490 return false;
2491 }
2492 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2493 } finally {
2494 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 }
2497
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002499 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002500 }
2501
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002502 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 Phone phone = PhoneFactory.getPhone(slotIndex);
2506 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2507 PhoneConstantConversions.convertCallState(phone.getState());
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
2510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
Sanket Padawe356d7632015-06-22 14:03:32 -07002513 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002514 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002515 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2516 }
2517
2518 @Override
2519 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002520 final long identity = Binder.clearCallingIdentity();
2521 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002522 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 if (phone != null) {
2524 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2525 } else {
2526 return PhoneConstantConversions.convertDataState(
2527 PhoneConstants.DataState.DISCONNECTED);
2528 }
2529 } finally {
2530 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532 }
2533
Sanket Padawe356d7632015-06-22 14:03:32 -07002534 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002535 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002536 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2537 }
2538
2539 @Override
2540 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541 final long identity = Binder.clearCallingIdentity();
2542 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002543 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544 if (phone != null) {
2545 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2546 } else {
2547 return TelephonyManager.DATA_ACTIVITY_NONE;
2548 }
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 }
2553
2554 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002555 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002556 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002557 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002558
2559 LocationAccessPolicy.LocationPermissionResult locationResult =
2560 LocationAccessPolicy.checkLocationPermission(mApp,
2561 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2562 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002563 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002564 .setCallingPid(Binder.getCallingPid())
2565 .setCallingUid(Binder.getCallingUid())
2566 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002567 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002568 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2569 .build());
2570 switch (locationResult) {
2571 case DENIED_HARD:
2572 throw new SecurityException("Not allowed to access cell location");
2573 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002574 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2575 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002576 }
2577
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002578 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002582 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002583 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002584 } finally {
2585 Binder.restoreCallingIdentity(identity);
2586 }
Svetoslav64fad262015-04-14 14:35:21 -07002587 }
2588
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 @Override
Jack Yu01425032020-02-22 19:38:58 -08002590 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002591 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2592 // registered cell info, so return a NULL country instead.
2593 final long identity = Binder.clearCallingIdentity();
2594 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002595 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2596 // Get default phone in this case.
2597 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2598 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002599 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002601 if (phone == null) return "";
2602 ServiceStateTracker sst = phone.getServiceStateTracker();
2603 if (sst == null) return "";
2604 LocaleTracker lt = sst.getLocaleTracker();
2605 if (lt == null) return "";
2606 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2607 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2608 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002609 } finally {
2610 Binder.restoreCallingIdentity(identity);
2611 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002612 }
2613
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002614 /**
2615 * This method was removed due to potential issues caused by performing partial
2616 * updates of service state, and lack of a credible use case.
2617 *
2618 * This has the ability to break the telephony implementation by disabling notification of
2619 * changes in device connectivity. DO NOT USE THIS!
2620 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002621 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 public void enableLocationUpdates() {
2623 mApp.enforceCallingOrSelfPermission(
2624 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 }
2626
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002627 /**
2628 * This method was removed due to potential issues caused by performing partial
2629 * updates of service state, and lack of a credible use case.
2630 *
2631 * This has the ability to break the telephony implementation by disabling notification of
2632 * changes in device connectivity. DO NOT USE THIS!
2633 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 @Override
2635 public void disableLocationUpdates() {
2636 mApp.enforceCallingOrSelfPermission(
2637 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 }
2639
Nathan Harold31d7ff32018-10-15 20:20:30 -07002640 /**
2641 * Returns the target SDK version number for a given package name.
2642 *
Nathan Haroldec184742019-07-10 17:04:16 -07002643 * This call MUST be invoked before clearing the calling UID.
2644 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002645 * @return target SDK if the package is found or INT_MAX.
2646 */
2647 private int getTargetSdk(String packageName) {
2648 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002649 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002650 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002651 if (ai != null) return ai.targetSdkVersion;
2652 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002653 loge("Failed to get package info for pkg="
2654 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002655 }
2656 return Integer.MAX_VALUE;
2657 }
2658
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 @Override
2660 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002661 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2662 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002663 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002664 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2665 throw new SecurityException(
2666 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2667 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002668
Jordan Liu1617b712019-07-10 15:06:26 -07002669 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2671 return null;
2672 }
Svetoslav64fad262015-04-14 14:35:21 -07002673
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002674 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002676 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002677 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678
Nathan Haroldf180aac2018-06-01 18:43:55 -07002679 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2680 for (CellInfo ci : info) {
2681 if (ci instanceof CellInfoGsm) {
2682 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2683 } else if (ci instanceof CellInfoWcdma) {
2684 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002687 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 }
2689
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002690 private List<CellInfo> getCachedCellInfo() {
2691 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2692 for (Phone phone : PhoneFactory.getPhones()) {
2693 List<CellInfo> info = phone.getAllCellInfo();
2694 if (info != null) cellInfos.addAll(info);
2695 }
2696 return cellInfos;
2697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698
2699 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002700 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002701 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002702 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002703
2704 LocationAccessPolicy.LocationPermissionResult locationResult =
2705 LocationAccessPolicy.checkLocationPermission(mApp,
2706 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2707 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002708 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002709 .setCallingPid(Binder.getCallingPid())
2710 .setCallingUid(Binder.getCallingUid())
2711 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002712 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002713 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2714 .build());
2715 switch (locationResult) {
2716 case DENIED_HARD:
2717 throw new SecurityException("Not allowed to access cell info");
2718 case DENIED_SOFT:
2719 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 }
2721
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002722 final int targetSdk = getTargetSdk(callingPackage);
2723 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2724 return getCachedCellInfo();
2725 }
2726
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002727 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002728 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729 final long identity = Binder.clearCallingIdentity();
2730 try {
2731 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2732 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002733 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002734 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 if (info != null) cellInfos.addAll(info);
2736 }
2737 return cellInfos;
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 }
2741 }
2742
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002743 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002744 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2745 String callingFeatureId) {
2746 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2747 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002748 }
2749
2750 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002751 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2752 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002753 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002754 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002755 }
2756
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002757 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2758 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002759 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002760 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002761
2762 LocationAccessPolicy.LocationPermissionResult locationResult =
2763 LocationAccessPolicy.checkLocationPermission(mApp,
2764 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2765 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002766 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002767 .setCallingPid(Binder.getCallingPid())
2768 .setCallingUid(Binder.getCallingUid())
2769 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002770 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2771 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002772 .build());
2773 switch (locationResult) {
2774 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002775 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2776 // Safetynet logging for b/154934934
2777 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2778 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002779 throw new SecurityException("Not allowed to access cell info");
2780 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002781 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2782 // Safetynet logging for b/154934934
2783 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2784 }
Nathan Harold5320c422019-05-09 10:26:08 -07002785 try {
2786 cb.onCellInfo(new ArrayList<CellInfo>());
2787 } catch (RemoteException re) {
2788 // Drop without consequences
2789 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002790 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002791 }
2792
Nathan Harolda939a962019-05-09 10:13:47 -07002793
2794 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002795 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2796
2797 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2798 }
2799
2800 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002801 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002802 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002803 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804
2805 final long identity = Binder.clearCallingIdentity();
2806 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002807 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 } finally {
2809 Binder.restoreCallingIdentity(identity);
2810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
Shishir Agrawala9f32182016-04-12 12:00:16 -07002813 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002814 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002815 Phone phone = PhoneFactory.getPhone(slotIndex);
2816 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002817 return null;
2818 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002819 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002820 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002821 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002822 return null;
2823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824
2825 final long identity = Binder.clearCallingIdentity();
2826 try {
2827 return phone.getImei();
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
2830 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002831 }
2832
2833 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002834 public String getTypeAllocationCodeForSlot(int slotIndex) {
2835 Phone phone = PhoneFactory.getPhone(slotIndex);
2836 String tac = null;
2837 if (phone != null) {
2838 String imei = phone.getImei();
2839 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2840 }
2841 return tac;
2842 }
2843
2844 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002845 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002846 Phone phone = PhoneFactory.getPhone(slotIndex);
2847 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002848 return null;
2849 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002850
Jeff Davidson913390f2018-02-23 17:11:49 -08002851 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002852 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002853 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002854 return null;
2855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856
2857 final long identity = Binder.clearCallingIdentity();
2858 try {
2859 return phone.getMeid();
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
2862 }
Jack Yu2af8d712017-03-15 17:14:14 -07002863 }
2864
2865 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002866 public String getManufacturerCodeForSlot(int slotIndex) {
2867 Phone phone = PhoneFactory.getPhone(slotIndex);
2868 String manufacturerCode = null;
2869 if (phone != null) {
2870 String meid = phone.getMeid();
2871 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2872 }
2873 return manufacturerCode;
2874 }
2875
2876 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002877 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2878 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002879 Phone phone = PhoneFactory.getPhone(slotIndex);
2880 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002881 return null;
2882 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002883 int subId = phone.getSubId();
2884 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002885 mApp, subId, callingPackage, callingFeatureId,
2886 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002887 return null;
2888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889
2890 final long identity = Binder.clearCallingIdentity();
2891 try {
2892 return phone.getDeviceSvn();
2893 } finally {
2894 Binder.restoreCallingIdentity(identity);
2895 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002896 }
2897
fionaxu43304da2017-11-27 22:51:16 -08002898 @Override
2899 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 final Phone phone = getPhone(subId);
2903 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
fionaxu43304da2017-11-27 22:51:16 -08002907 }
2908
2909 @Override
2910 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 final Phone phone = getPhone(subId);
2914 return phone == null ? null : phone.getCarrierName();
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
2917 }
fionaxu43304da2017-11-27 22:51:16 -08002918 }
2919
calvinpanffe225e2018-11-01 19:43:06 +08002920 @Override
chen xu0026ca62019-03-06 15:28:50 -08002921 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 final Phone phone = getPhone(subId);
2925 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002926 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002927 } finally {
2928 Binder.restoreCallingIdentity(identity);
2929 }
2930 }
2931
2932 @Override
chen xu0026ca62019-03-06 15:28:50 -08002933 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002937 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
2941 }
2942
chen xu651eec72018-11-11 19:03:44 -08002943 @Override
chen xu864e11c2018-12-06 22:10:03 -08002944 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2945 if (!isSubscriptionMccMnc) {
2946 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2947 }
chen xu651eec72018-11-11 19:03:44 -08002948 final Phone phone = PhoneFactory.getPhone(slotIndex);
2949 if (phone == null) {
2950 return TelephonyManager.UNKNOWN_CARRIER_ID;
2951 }
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2955 } finally {
2956 Binder.restoreCallingIdentity(identity);
2957 }
2958 }
2959
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002960 //
2961 // Internal helper methods.
2962 //
2963
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002964 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2966 *
2967 * @throws SecurityException if the caller does not have the required permission
2968 */
2969 private void enforceModifyPermission() {
2970 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2971 }
2972
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002973 /**
2974 * Make sure the caller is system.
2975 *
2976 * @throws SecurityException if the caller is not system.
2977 */
2978 private void enforceSystemCaller() {
2979 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2980 throw new SecurityException("Caller must be system");
2981 }
2982 }
2983
Shuo Qianf2b2df42019-11-13 17:43:31 -08002984 private void enforceActiveEmergencySessionPermission() {
2985 mApp.enforceCallingOrSelfPermission(
2986 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2987 }
2988
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002989 /**
2990 * Make sure the caller has the CALL_PHONE permission.
2991 *
2992 * @throws SecurityException if the caller does not have the required permission
2993 */
2994 private void enforceCallPermission() {
2995 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2996 }
2997
paulhu423b5f22019-08-23 19:17:33 +08002998 private void enforceSettingsPermission() {
2999 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003000 }
3001
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003002 private String createTelUrl(String number) {
3003 if (TextUtils.isEmpty(number)) {
3004 return null;
3005 }
3006
Jake Hambye994d462014-02-03 13:10:13 -08003007 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003008 }
3009
Ihab Awadf9e92732013-12-05 18:02:52 -08003010 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003011 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3012 }
3013
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003014 private static void logv(String msg) {
3015 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3016 }
3017
Ihab Awadf9e92732013-12-05 18:02:52 -08003018 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3020 }
3021
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003022 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003024 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003025 }
3026
Sanket Padawe356d7632015-06-22 14:03:32 -07003027 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003028 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 final Phone phone = PhoneFactory.getPhone(slotIndex);
3032 if (phone == null) {
3033 return PhoneConstants.PHONE_TYPE_NONE;
3034 } else {
3035 return phone.getPhoneType();
3036 }
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003039 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003040 }
3041
3042 /**
3043 * Returns the CDMA ERI icon index to display
3044 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003045 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003046 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3047 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3048 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003049 }
3050
Sanket Padawe356d7632015-06-22 14:03:32 -07003051 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003052 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3053 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003054 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003055 mApp, subId, callingPackage, callingFeatureId,
3056 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003057 return -1;
3058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059
3060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 final Phone phone = getPhone(subId);
3063 if (phone != null) {
3064 return phone.getCdmaEriIconIndex();
3065 } else {
3066 return -1;
3067 }
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003070 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003071 }
3072
3073 /**
3074 * Returns the CDMA ERI icon mode,
3075 * 0 - ON
3076 * 1 - FLASHING
3077 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003078 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003079 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3080 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3081 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003082 }
3083
Sanket Padawe356d7632015-06-22 14:03:32 -07003084 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003085 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3086 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003088 mApp, subId, callingPackage, callingFeatureId,
3089 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003090 return -1;
3091 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092
3093 final long identity = Binder.clearCallingIdentity();
3094 try {
3095 final Phone phone = getPhone(subId);
3096 if (phone != null) {
3097 return phone.getCdmaEriIconMode();
3098 } else {
3099 return -1;
3100 }
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 }
3105
3106 /**
3107 * Returns the CDMA ERI text,
3108 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003109 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003110 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3111 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3112 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003113 }
3114
Sanket Padawe356d7632015-06-22 14:03:32 -07003115 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003116 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3117 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003119 mApp, subId, callingPackage, callingFeatureId,
3120 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003121 return null;
3122 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003123
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 final Phone phone = getPhone(subId);
3127 if (phone != null) {
3128 return phone.getCdmaEriText();
3129 } else {
3130 return null;
3131 }
3132 } finally {
3133 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003135 }
3136
3137 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003138 * Returns the CDMA MDN.
3139 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003140 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003141 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3143 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144
3145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003148 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149 return phone.getLine1Number();
3150 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003151 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 return null;
3153 }
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003156 }
3157 }
3158
3159 /**
3160 * Returns the CDMA MIN.
3161 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003162 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003163 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3165 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166
3167 final long identity = Binder.clearCallingIdentity();
3168 try {
3169 final Phone phone = getPhone(subId);
3170 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3171 return phone.getCdmaMin();
3172 } else {
3173 return null;
3174 }
3175 } finally {
3176 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003177 }
3178 }
3179
Hall Liud892bec2018-11-30 14:51:45 -08003180 @Override
3181 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3182 INumberVerificationCallback callback, String callingPackage) {
3183 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3184 != PERMISSION_GRANTED) {
3185 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3186 }
3187 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3188
3189 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3190 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3191 throw new SecurityException("Calling package must be configured in the device config");
3192 }
3193
3194 if (range == null) {
3195 throw new NullPointerException("Range must be non-null");
3196 }
3197
3198 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003199 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003200
3201 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3202 }
3203
Junda Liuca05d5d2014-08-14 22:36:34 -07003204 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 * Returns true if CDMA provisioning needs to run.
3206 */
3207 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 final long identity = Binder.clearCallingIdentity();
3209 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003210 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003211 } finally {
3212 Binder.restoreCallingIdentity(identity);
3213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 }
3215
3216 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003217 * Sets the voice mail number of a given subId.
3218 */
3219 @Override
3220 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003221 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3222 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003223
3224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3227 new Pair<String, String>(alphaTag, number), new Integer(subId));
3228 return success;
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003232 }
3233
Ta-wei Yen87c49842016-05-13 21:19:52 -07003234 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003235 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3236 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003237 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3238 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003239 if (!TextUtils.equals(callingPackage, systemDialer)) {
3240 throw new SecurityException("caller must be system dialer");
3241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242
3243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3246 if (phoneAccountHandle == null) {
3247 return null;
3248 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003249 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003250 } finally {
3251 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003252 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003253 }
3254
3255 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003256 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3257 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003258 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003260 mApp, subId, callingPackage, callingFeatureId,
3261 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003262 return null;
3263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003264
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003265 final long identity = Binder.clearCallingIdentity();
3266 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003267 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003268 } finally {
3269 Binder.restoreCallingIdentity(identity);
3270 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003271 }
3272
3273 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003274 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3275 VisualVoicemailSmsFilterSettings settings) {
3276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003281 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003285 }
3286
3287 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003288 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3289 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003290
3291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003294 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003295 } finally {
3296 Binder.restoreCallingIdentity(identity);
3297 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003298 }
3299
3300 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003301 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3302 String callingPackage, int subId) {
3303 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304
3305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003308 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003312 }
3313
3314 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003315 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003316 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003317
3318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003321 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003325 }
3326
3327 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003328 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3329 String callingAttributionTag, int subId, String number, int port, String text,
3330 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003331 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003332 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003333 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003334 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003335 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3336 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003337 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003338
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003339 /**
fionaxu0152e512016-11-14 13:36:14 -08003340 * Sets the voice activation state of a given subId.
3341 */
3342 @Override
3343 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3345 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346
3347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 final Phone phone = getPhone(subId);
3350 if (phone != null) {
3351 phone.setVoiceActivationState(activationState);
3352 } else {
3353 loge("setVoiceActivationState fails with invalid subId: " + subId);
3354 }
3355 } finally {
3356 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003357 }
3358 }
3359
3360 /**
3361 * Sets the data activation state of a given subId.
3362 */
3363 @Override
3364 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3366 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367
3368 final long identity = Binder.clearCallingIdentity();
3369 try {
3370 final Phone phone = getPhone(subId);
3371 if (phone != null) {
3372 phone.setDataActivationState(activationState);
3373 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003374 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003375 }
3376 } finally {
3377 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003378 }
3379 }
3380
3381 /**
3382 * Returns the voice activation state of a given subId.
3383 */
3384 @Override
3385 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003386 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387
fionaxu0152e512016-11-14 13:36:14 -08003388 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003389 final long identity = Binder.clearCallingIdentity();
3390 try {
3391 if (phone != null) {
3392 return phone.getVoiceActivationState();
3393 } else {
3394 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3395 }
3396 } finally {
3397 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003398 }
3399 }
3400
3401 /**
3402 * Returns the data activation state of a given subId.
3403 */
3404 @Override
3405 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003406 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407
fionaxu0152e512016-11-14 13:36:14 -08003408 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 if (phone != null) {
3412 return phone.getDataActivationState();
3413 } else {
3414 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3415 }
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003418 }
3419 }
3420
3421 /**
Wink Saville36469e72014-06-11 15:17:00 -07003422 * Returns the unread count of voicemails for a subId
3423 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003424 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003425 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3426 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003428 mApp, subId, callingPackage, callingFeatureId,
3429 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003430 return 0;
3431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432 final long identity = Binder.clearCallingIdentity();
3433 try {
3434 final Phone phone = getPhone(subId);
3435 if (phone != null) {
3436 return phone.getVoiceMessageCount();
3437 } else {
3438 return 0;
3439 }
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003443 }
3444
3445 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003446 * returns true, if the device is in a state where both voice and data
3447 * are supported simultaneously. This can change based on location or network condition.
3448 */
3449 @Override
3450 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 final Phone phone = getPhone(subId);
3454 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3455 } finally {
3456 Binder.restoreCallingIdentity(identity);
3457 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003458 }
3459
3460 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003461 * Send the dialer code if called from the current default dialer or the caller has
3462 * carrier privilege.
3463 * @param inputCode The dialer code to send
3464 */
3465 @Override
3466 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003467 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003469 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3470 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003471 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003472 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003473 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003475
3476 final long identity = Binder.clearCallingIdentity();
3477 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
fionaxu235cc5e2017-03-06 22:25:57 -08003482 }
3483
Pengquan Menga1bb6272018-09-06 09:59:22 -07003484 @Override
3485 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003486 TelephonyPermissions
3487 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3488 mApp, subId, "getNetworkSelectionMode");
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 if (!isActiveSubscription(subId)) {
3492 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3493 }
3494 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003497 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003498 }
3499
Brad Ebinger35c841c2018-10-01 10:40:55 -07003500 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003501 public boolean isInEmergencySmsMode() {
3502 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3503 final long identity = Binder.clearCallingIdentity();
3504 try {
3505 for (Phone phone : PhoneFactory.getPhones()) {
3506 if (phone.isInEmergencySmsMode()) {
3507 return true;
3508 }
3509 }
3510 } finally {
3511 Binder.restoreCallingIdentity(identity);
3512 }
3513 return false;
3514 }
3515
shilu366312e2019-12-17 09:28:10 -08003516 /**
3517 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3518 * @param subId The subscription to use to check the configuration.
3519 * @param c The callback that will be used to send the result.
3520 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003521 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003522 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3523 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003524 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3525 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003526
Brad Ebinger77b832e2019-10-17 17:03:22 -07003527 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3528 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3529 "IMS not available on device.");
3530 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003531 final long token = Binder.clearCallingIdentity();
3532 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003533 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003534 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003535 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003536 } catch (ImsException e) {
3537 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003538 } finally {
3539 Binder.restoreCallingIdentity(token);
3540 }
3541 }
3542
shilu366312e2019-12-17 09:28:10 -08003543 /**
3544 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3545 * @param subId The subscription to use to check the configuration.
3546 * @param c The callback that will be used to send the result.
3547 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003549 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003550 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3551 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003552 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3553 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3554 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003555 final long token = Binder.clearCallingIdentity();
3556 try {
3557 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3558 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3559 .removeRegistrationCallbackForSubscription(c, subId);
3560 } catch (ImsException e) {
3561 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3562 + "is inactive, ignoring unregister.");
3563 // If the subscription is no longer active, just return, since the callback
3564 // will already have been removed internally.
3565 } finally {
3566 Binder.restoreCallingIdentity(token);
3567 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 }
3569
Brad Ebinger774ba362019-10-22 17:36:18 -07003570 /**
3571 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3572 */
3573 @Override
3574 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3575 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3576 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3577 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3578 "IMS not available on device.");
3579 }
3580 final long token = Binder.clearCallingIdentity();
3581 try {
3582 Phone phone = getPhone(subId);
3583 if (phone == null) {
3584 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3585 + subId + "'");
3586 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3587 }
3588 phone.getImsRegistrationState(regState -> {
3589 try {
3590 consumer.accept((regState == null)
3591 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3592 } catch (RemoteException e) {
3593 // Ignore if the remote process is no longer available to call back.
3594 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3595 }
3596 });
3597 } finally {
3598 Binder.restoreCallingIdentity(token);
3599 }
3600 }
3601
3602 /**
3603 * Get the transport type for the IMS service registration state.
3604 */
3605 @Override
3606 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003607 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3608 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003609 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3610 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3611 "IMS not available on device.");
3612 }
3613 final long token = Binder.clearCallingIdentity();
3614 try {
3615 Phone phone = getPhone(subId);
3616 if (phone == null) {
3617 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3618 + subId + "'");
3619 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3620 }
3621 phone.getImsRegistrationTech(regTech -> {
3622 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3623 int regTechConverted = (regTech == null)
3624 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3625 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3626 regTechConverted);
3627 try {
3628 consumer.accept(regTechConverted);
3629 } catch (RemoteException e) {
3630 // Ignore if the remote process is no longer available to call back.
3631 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3632 }
3633 });
3634 } finally {
3635 Binder.restoreCallingIdentity(token);
3636 }
3637 }
3638
shilu366312e2019-12-17 09:28:10 -08003639 /**
3640 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3641 * @param subId The subscription to use to check the configuration.
3642 * @param c The callback that will be used to send the result.
3643 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003644 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003645 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3646 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003647 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3648 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003649 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3650 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3651 "IMS not available on device.");
3652 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003653 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3654 final long token = Binder.clearCallingIdentity();
3655 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003658 } catch (ImsException e) {
3659 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003660 } finally {
3661 Binder.restoreCallingIdentity(token);
3662 }
3663 }
3664
shilu366312e2019-12-17 09:28:10 -08003665 /**
3666 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3667 * @param subId The subscription to use to check the configuration.
3668 * @param c The callback that will be used to send the result.
3669 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003670 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003671 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003672 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3673 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003674 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3675 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3676 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003677
3678 final long token = Binder.clearCallingIdentity();
3679 try {
3680 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3681 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003682 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003683 } catch (ImsException e) {
3684 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3685 + "is inactive, ignoring unregister.");
3686 // If the subscription is no longer active, just return, since the callback
3687 // will already have been removed internally.
3688 } finally {
3689 Binder.restoreCallingIdentity(token);
3690 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 }
3692
3693 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003694 public boolean isCapable(int subId, int capability, int regTech) {
3695 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3697 final long token = Binder.clearCallingIdentity();
3698 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003699 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003701 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003702 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3703 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003704 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003705 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3706 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 } finally {
3708 Binder.restoreCallingIdentity(token);
3709 }
3710 }
3711
3712 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003713 public boolean isAvailable(int subId, int capability, int regTech) {
3714 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003715 final long token = Binder.clearCallingIdentity();
3716 try {
3717 Phone phone = getPhone(subId);
3718 if (phone == null) return false;
3719 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003720 } catch (com.android.ims.ImsException e) {
3721 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3722 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 } finally {
3724 Binder.restoreCallingIdentity(token);
3725 }
3726 }
3727
Brad Ebinger77b832e2019-10-17 17:03:22 -07003728 /**
3729 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3730 * subscription.
3731 * @param subId The subscription to use to check the configuration.
3732 * @param callback The callback that will be used to send the result.
3733 * @param capability The MmTelFeature capability that will be used to send the result.
3734 * @param transportType The transport type of the MmTelFeature capability.
3735 */
3736 @Override
3737 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3738 int transportType) {
3739 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3740 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3741 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3742 "IMS not available on device.");
3743 }
3744 final long token = Binder.clearCallingIdentity();
3745 try {
3746 int slotId = getSlotIndex(subId);
3747 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3748 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3749 + subId + "'");
3750 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3751 }
3752 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3753 transportType, aBoolean -> {
3754 try {
3755 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3756 } catch (RemoteException e) {
3757 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3758 + "running. Ignore");
3759 }
3760 });
3761 } finally {
3762 Binder.restoreCallingIdentity(token);
3763 }
3764 }
3765
shilu366312e2019-12-17 09:28:10 -08003766 /**
3767 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3768 * @param subId The subscription to use to check the configuration.
3769 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003770 @Override
3771 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003772 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3773 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003774
Brad Ebinger35c841c2018-10-01 10:40:55 -07003775 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3776 final long token = Binder.clearCallingIdentity();
3777 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003778 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003779 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003780 } catch (ImsException e) {
3781 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003782 } finally {
3783 Binder.restoreCallingIdentity(token);
3784 }
3785 }
3786
3787 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003788 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003790 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003794 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003795 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003796 } catch (ImsException e) {
3797 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003798 } finally {
3799 Binder.restoreCallingIdentity(identity);
3800 }
3801 }
3802
shilu366312e2019-12-17 09:28:10 -08003803 /**
3804 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3805 * @param subId The subscription to use to check the configuration.
3806 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003807 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003808 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003809 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3810 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003811 final long identity = Binder.clearCallingIdentity();
3812 try {
3813 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003814 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3815 } catch (ImsException e) {
3816 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003817 } finally {
3818 Binder.restoreCallingIdentity(identity);
3819 }
3820 }
3821
3822 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003823 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003825 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003829 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003830 } catch (ImsException e) {
3831 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003832 } finally {
3833 Binder.restoreCallingIdentity(identity);
3834 }
3835 }
3836
shilu366312e2019-12-17 09:28:10 -08003837 /**
3838 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3839 * @param subId The subscription to use to check the configuration.
3840 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003841 @Override
3842 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003843 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3844 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 final long identity = Binder.clearCallingIdentity();
3846 try {
3847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003848 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003850 } catch (ImsException e) {
3851 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 } finally {
3853 Binder.restoreCallingIdentity(identity);
3854 }
3855 }
3856
3857 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003858 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003860 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003864 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003865 } catch (ImsException e) {
3866 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003867 } finally {
3868 Binder.restoreCallingIdentity(identity);
3869 }
3870 }
3871
shilu366312e2019-12-17 09:28:10 -08003872 /**
3873 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3874 * @param subId The subscription to use to check the configuration.
3875 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003876 @Override
3877 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003878 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3879 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 final long identity = Binder.clearCallingIdentity();
3881 try {
3882 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003883 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003884 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003885 } catch (ImsException e) {
3886 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003887 } finally {
3888 Binder.restoreCallingIdentity(identity);
3889 }
3890 }
3891
3892 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003893 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003895 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003899 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003900 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003901 } catch (ImsException e) {
3902 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003903 } finally {
3904 Binder.restoreCallingIdentity(identity);
3905 }
3906 }
3907
3908 @Override
3909 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3911 "setVoWiFiNonPersistent");
3912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003915 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003916 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003917 } catch (ImsException e) {
3918 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003919 } finally {
3920 Binder.restoreCallingIdentity(identity);
3921 }
3922 }
3923
shilu366312e2019-12-17 09:28:10 -08003924 /**
3925 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3926 * @param subId The subscription to use to check the configuration.
3927 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 @Override
3929 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003930 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3931 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003932 final long identity = Binder.clearCallingIdentity();
3933 try {
3934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003935 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003937 } catch (ImsException e) {
3938 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003939 } finally {
3940 Binder.restoreCallingIdentity(identity);
3941 }
3942 }
3943
3944 @Override
3945 public void setVoWiFiModeSetting(int subId, int mode) {
3946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3947 "setVoWiFiModeSetting");
3948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003951 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003953 } catch (ImsException e) {
3954 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 } finally {
3956 Binder.restoreCallingIdentity(identity);
3957 }
3958 }
3959
3960 @Override
3961 public int getVoWiFiRoamingModeSetting(int subId) {
3962 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3963 final long identity = Binder.clearCallingIdentity();
3964 try {
3965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003966 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003967 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003968 } catch (ImsException e) {
3969 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 } finally {
3971 Binder.restoreCallingIdentity(identity);
3972 }
3973 }
3974
3975 @Override
3976 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3978 "setVoWiFiRoamingModeSetting");
3979 final long identity = Binder.clearCallingIdentity();
3980 try {
3981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003982 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003984 } catch (ImsException e) {
3985 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 } finally {
3987 Binder.restoreCallingIdentity(identity);
3988 }
3989 }
3990
3991 @Override
3992 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3994 "setRttCapabilityEnabled");
3995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003998 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3999 } catch (ImsException e) {
4000 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 } finally {
4002 Binder.restoreCallingIdentity(identity);
4003 }
4004 }
4005
shilu366312e2019-12-17 09:28:10 -08004006 /**
4007 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4008 * @param subId The subscription to use to check the configuration.
4009 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004010 @Override
4011 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004012 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4013 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004017 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004018 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004019 } catch (ImsException e) {
4020 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 } finally {
4022 Binder.restoreCallingIdentity(identity);
4023 }
4024 }
4025
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004026 @Override
4027 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4028 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4029 final long identity = Binder.clearCallingIdentity();
4030 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004031 if (!isImsAvailableOnDevice()) {
4032 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4033 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004034 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004035 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004036 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004037 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004038 } catch (ImsException e) {
4039 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
4043 }
4044
4045 @Override
4046 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4047 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4048 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004049 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4050 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4051 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004052 try {
4053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004054 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004055 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004056 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004057 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4058 + "is inactive, ignoring unregister.");
4059 // If the subscription is no longer active, just return, since the callback will already
4060 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
4064 }
4065
allenwtsu99c623b2020-01-03 18:24:23 +08004066
4067 private void checkModifyPhoneStatePermission(int subId, String message) {
4068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4069 message);
4070 }
4071
4072 private boolean isImsProvisioningRequired(int subId, int capability,
4073 boolean isMmtelCapability) {
4074 Phone phone = getPhone(subId);
4075 if (phone == null) {
4076 loge("phone instance null for subid " + subId);
4077 return false;
4078 }
4079 if (isMmtelCapability) {
4080 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4081 return false;
4082 }
4083 } else {
4084 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4085 return false;
4086 }
4087 }
4088 return true;
4089 }
4090
4091 @Override
4092 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4093 boolean isProvisioned) {
4094 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4095
4096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4099 if (!isImsProvisioningRequired(subId, capability, false)) {
4100 return;
4101 }
4102
4103 // this capability requires provisioning, route to the correct API.
4104 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4105 switch (capability) {
4106 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4107 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4108 ims.setEabProvisioned(isProvisioned);
4109 break;
4110 default: {
4111 throw new IllegalArgumentException("Tried to set provisioning for "
4112 + "rcs capability '" + capability + "', which does not require "
4113 + "provisioning.");
4114 }
4115 }
4116 } finally {
4117 Binder.restoreCallingIdentity(identity);
4118 }
4119
4120 }
4121
4122
4123 @Override
4124 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4125 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4129 if (!isImsProvisioningRequired(subId, capability, false)) {
4130 return true;
4131 }
4132
4133 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4134 switch (capability) {
4135 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4136 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4137 return ims.isEabProvisionedOnDevice();
4138
4139 default: {
4140 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4141 + "capability '" + capability + "', which does not require "
4142 + "provisioning.");
4143 }
4144 }
4145
4146 } finally {
4147 Binder.restoreCallingIdentity(identity);
4148 }
4149 }
4150
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004151 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004152 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4153 boolean isProvisioned) {
4154 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4155 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4156 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4157 }
allenwtsu99c623b2020-01-03 18:24:23 +08004158 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004159 final long identity = Binder.clearCallingIdentity();
4160 try {
4161 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004162 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004163 return;
4164 }
4165
4166 // this capability requires provisioning, route to the correct API.
4167 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4168 switch (capability) {
4169 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4170 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4171 ims.setVolteProvisioned(isProvisioned);
4172 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4173 ims.setWfcProvisioned(isProvisioned);
4174 }
4175 break;
4176 }
4177 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4178 // There is currently no difference in VT provisioning type.
4179 ims.setVtProvisioned(isProvisioned);
4180 break;
4181 }
4182 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4183 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4184 // change the capability of the feature instead if needed.
4185 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4186 == isProvisioned) {
4187 // No change in provisioning.
4188 return;
4189 }
4190 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4191 try {
4192 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004193 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004194 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4195 + ", Exception" + e.getMessage());
4196 }
4197 break;
4198 }
4199 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004200 throw new IllegalArgumentException("Tried to set provisioning for "
4201 + "MmTel capability '" + capability + "', which does not require "
4202 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004203 }
4204 }
4205
4206 } finally {
4207 Binder.restoreCallingIdentity(identity);
4208 }
4209 }
4210
4211 @Override
4212 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4213 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4214 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4215 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4216 }
4217 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4218 final long identity = Binder.clearCallingIdentity();
4219 try {
4220 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004221 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004222 return true;
4223 }
4224
4225 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4226 switch (capability) {
4227 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4228 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4229 return ims.isVolteProvisionedOnDevice();
4230 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4231 return ims.isWfcProvisionedOnDevice();
4232 }
4233 // This should never happen, since we are checking tech above to make sure it
4234 // is either LTE or IWLAN.
4235 throw new IllegalArgumentException("Invalid radio technology for voice "
4236 + "capability.");
4237 }
4238 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4239 // There is currently no difference in VT provisioning type.
4240 return ims.isVtProvisionedOnDevice();
4241 }
4242 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4243 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4244 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4245 }
4246 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004247 throw new IllegalArgumentException(
4248 "Tried to get provisioning for MmTel capability '" + capability
4249 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004250 }
4251 }
4252
4253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
4256 }
4257
4258 @Override
4259 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4260 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4261 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4262 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4263 }
4264 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4265 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4266 return (provisionedBits & capability) > 0;
4267 }
4268
4269 @Override
4270 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4271 boolean isProvisioned) {
4272 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4273 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4274 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4275 }
4276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4277 "setProvisioningStatusForCapability");
4278 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4279 // If the current provisioning status for capability already matches isProvisioned,
4280 // do nothing.
4281 if (((provisionedBits & capability) > 0) == isProvisioned) {
4282 return;
4283 }
4284 if (isProvisioned) {
4285 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4286 } else {
4287 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4288 }
4289 }
4290
4291 /**
4292 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4293 * technology. The bitfield should mirror the bitfield defined by
4294 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4295 */
4296 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4297 String key = getMmTelProvisioningKey(subId, tech);
4298 // Default is no capabilities are provisioned.
4299 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4300 }
4301
4302 /**
4303 * Sets the MmTel capability provisioning bitfield (defined by
4304 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4305 * technology specified.
4306 *
4307 * Note: This is a synchronous command and should not be called on UI thread.
4308 */
4309 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4310 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4311 String key = getMmTelProvisioningKey(subId, tech);
4312 editor.putInt(key, newField);
4313 editor.commit();
4314 }
4315
4316 private static String getMmTelProvisioningKey(int subId, int tech) {
4317 // resulting key is provision_ims_mmtel_{subId}_{tech}
4318 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4319 }
4320
4321 /**
4322 * Query CarrierConfig to see if the specified capability requires provisioning for the
4323 * carrier associated with the subscription id.
4324 */
4325 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4326 int capability) {
4327 CarrierConfigManager configManager = new CarrierConfigManager(context);
4328 PersistableBundle c = configManager.getConfigForSubId(subId);
4329 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004330 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004331 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4332 false);
4333 boolean requireVoiceVtProvisioning = c.getBoolean(
4334 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4335
4336 // First check to make sure that the capability requires provisioning.
4337 switch (capability) {
4338 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4339 // intentional fallthrough
4340 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4341 if (requireVoiceVtProvisioning) {
4342 // Voice and Video requires provisioning
4343 return true;
4344 }
4345 break;
4346 }
4347 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4348 if (requireUtProvisioning) {
4349 // UT requires provisioning
4350 return true;
4351 }
4352 break;
4353 }
4354 }
4355 return false;
4356 }
4357
allenwtsu99c623b2020-01-03 18:24:23 +08004358 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4359 int capability) {
4360 CarrierConfigManager configManager = new CarrierConfigManager(context);
4361 PersistableBundle c = configManager.getConfigForSubId(subId);
4362
4363 boolean requireRcsProvisioning = c.getBoolean(
4364 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4365
4366 // First check to make sure that the capability requires provisioning.
4367 switch (capability) {
4368 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4369 // intentional fallthrough
4370 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4371 if (requireRcsProvisioning) {
4372 // OPTION or PRESENCE requires provisioning
4373 return true;
4374 }
4375 break;
4376 }
4377 }
4378 return false;
4379 }
4380
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004381 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004382 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004383 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4384 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4385 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004386 enforceReadPrivilegedPermission("getImsProvisioningInt");
4387 final long identity = Binder.clearCallingIdentity();
4388 try {
4389 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004390 int slotId = getSlotIndex(subId);
4391 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4392 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4393 + subId + "' for key:" + key);
4394 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4395 }
4396 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004397 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004398 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4399 + subId + "' for key:" + key);
4400 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
4404 }
4405
4406 @Override
4407 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004408 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4409 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4410 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004411 enforceReadPrivilegedPermission("getImsProvisioningString");
4412 final long identity = Binder.clearCallingIdentity();
4413 try {
4414 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004415 int slotId = getSlotIndex(subId);
4416 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4417 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4418 + subId + "' for key:" + key);
4419 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4420 }
4421 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004422 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004423 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4424 + subId + "' for key:" + key);
4425 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004426 } finally {
4427 Binder.restoreCallingIdentity(identity);
4428 }
4429 }
4430
4431 @Override
4432 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004433 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4434 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4435 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4437 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004438 final long identity = Binder.clearCallingIdentity();
4439 try {
4440 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004441 int slotId = getSlotIndex(subId);
4442 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4443 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4444 + subId + "' for key:" + key);
4445 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4446 }
4447 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004448 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004449 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4450 + "' for key:" + key);
4451 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004452 } finally {
4453 Binder.restoreCallingIdentity(identity);
4454 }
4455 }
4456
4457 @Override
4458 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004459 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4460 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4461 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4463 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004464 final long identity = Binder.clearCallingIdentity();
4465 try {
4466 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004467 int slotId = getSlotIndex(subId);
4468 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4469 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4470 + subId + "' for key:" + key);
4471 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4472 }
4473 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004474 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004475 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4476 + "' for key:" + key);
4477 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004478 } finally {
4479 Binder.restoreCallingIdentity(identity);
4480 }
4481 }
4482
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004483 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004484 int slotId = SubscriptionManager.getSlotIndex(subId);
4485 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004486 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4487 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004488 }
4489 return slotId;
4490 }
4491
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004492 private int getSlotIndex(int subId) {
4493 int slotId = SubscriptionManager.getSlotIndex(subId);
4494 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4495 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4496 }
4497 return slotId;
4498 }
4499
Wink Saville36469e72014-06-11 15:17:00 -07004500 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004501 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004502 */
4503 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004504 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4505 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004506 final int targetSdk = getTargetSdk(callingPackage);
4507 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004508 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004509 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004510 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004511 mApp, subId, callingPackage, callingFeatureId,
4512 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004513 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4514 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 final long identity = Binder.clearCallingIdentity();
4517 try {
4518 final Phone phone = getPhone(subId);
4519 if (phone != null) {
4520 return phone.getServiceState().getDataNetworkType();
4521 } else {
4522 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4523 }
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004527 }
4528
4529 /**
4530 * Returns the data network type
4531 */
4532 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004533 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4534 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4535 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004536 }
4537
4538 /**
4539 * Returns the data network type for a subId
4540 */
4541 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004542 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4543 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004545 mApp, subId, callingPackage, callingFeatureId,
4546 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004547 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4548 }
4549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550 final long identity = Binder.clearCallingIdentity();
4551 try {
4552 final Phone phone = getPhone(subId);
4553 if (phone != null) {
4554 return phone.getServiceState().getDataNetworkType();
4555 } else {
4556 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4557 }
4558 } finally {
4559 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004561 }
4562
4563 /**
Wink Saville36469e72014-06-11 15:17:00 -07004564 * Returns the Voice network type for a subId
4565 */
4566 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004567 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4568 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004570 mApp, subId, callingPackage, callingFeatureId,
4571 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004572 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4573 }
4574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 final long identity = Binder.clearCallingIdentity();
4576 try {
4577 final Phone phone = getPhone(subId);
4578 if (phone != null) {
4579 return phone.getServiceState().getVoiceNetworkType();
4580 } else {
4581 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4582 }
4583 } finally {
4584 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004586 }
4587
4588 /**
4589 * @return true if a ICC card is present
4590 */
4591 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004592 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004593 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4594 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004595 }
4596
4597 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004598 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004599 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004600 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004601 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004602 final long identity = Binder.clearCallingIdentity();
4603 try {
4604 final Phone phone = PhoneFactory.getPhone(slotIndex);
4605 if (phone != null) {
4606 return phone.getIccCard().hasIccCard();
4607 } else {
4608 return false;
4609 }
4610 } finally {
4611 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004613 }
4614
4615 /**
4616 * Return if the current radio is LTE on CDMA. This
4617 * is a tri-state return value as for a period of time
4618 * the mode may be unknown.
4619 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004620 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004621 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004622 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004623 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004624 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004625 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4626 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4627 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004628 }
4629
Sanket Padawe356d7632015-06-22 14:03:32 -07004630 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004631 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4632 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004633 try {
4634 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4635 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004636 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4637 }
4638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004639 final long identity = Binder.clearCallingIdentity();
4640 try {
4641 final Phone phone = getPhone(subId);
4642 if (phone == null) {
4643 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4644 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004645 return TelephonyProperties.lte_on_cdma_device()
4646 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004647 }
4648 } finally {
4649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004650 }
Wink Saville36469e72014-06-11 15:17:00 -07004651 }
4652
Wink Saville36469e72014-06-11 15:17:00 -07004653 /**
4654 * {@hide}
4655 * Returns Default subId, 0 in the case of single standby.
4656 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004657 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004658 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004659 }
4660
Shishir Agrawala9f32182016-04-12 12:00:16 -07004661 private int getSlotForDefaultSubscription() {
4662 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4663 }
4664
Wink Savilleb564aae2014-10-23 10:18:09 -07004665 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004666 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004667 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004668
Pengquan Menge92a50d2018-09-21 15:54:48 -07004669 private boolean isActiveSubscription(int subId) {
4670 return mSubscriptionController.isActiveSubId(subId);
4671 }
4672
Ihab Awadf2177b72013-11-25 13:33:23 -08004673 /**
4674 * @see android.telephony.TelephonyManager.WifiCallingChoices
4675 */
4676 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004677 final long identity = Binder.clearCallingIdentity();
4678 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004679 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004680 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4681 getWhenToMakeWifiCallsDefaultPreference());
4682 } finally {
4683 Binder.restoreCallingIdentity(identity);
4684 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004685 }
4686
4687 /**
4688 * @see android.telephony.TelephonyManager.WifiCallingChoices
4689 */
4690 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004694 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4696 } finally {
4697 Binder.restoreCallingIdentity(identity);
4698 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004699 }
4700
Sailesh Nepald1e68152013-12-12 19:08:02 -08004701 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004702 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004703 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004704 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004705
Jordan Liu4c733742019-02-28 12:03:40 -08004706 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4707 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4708 if (phoneId == -1) {
4709 throw new IllegalArgumentException("Given slot index: " + slotIndex
4710 + " does not correspond to an active phone");
4711 }
4712 return PhoneFactory.getPhone(phoneId);
4713 }
4714
Shishir Agrawal566b7612013-10-28 14:41:00 -07004715 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004716 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4717 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4719 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004721 if (DBG) {
4722 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4723 }
4724 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4725 p2);
4726 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004727
Jordan Liu4c733742019-02-28 12:03:40 -08004728
4729 @Override
4730 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4731 int slotIndex, String callingPackage, String aid, int p2) {
4732 enforceModifyPermission();
4733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4734 if (DBG) {
4735 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4736 }
4737 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4738 callingPackage, aid, p2);
4739 }
4740
4741 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4742 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743 final long identity = Binder.clearCallingIdentity();
4744 try {
4745 if (TextUtils.equals(ISDR_AID, aid)) {
4746 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004747 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4748 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004749 if (bestComponent == null
4750 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4751 loge("The calling package is not allowed to access ISD-R.");
4752 throw new SecurityException(
4753 "The calling package is not allowed to access ISD-R.");
4754 }
Derek Tan740e1672017-06-27 14:56:27 -07004755 }
Derek Tan740e1672017-06-27 14:56:27 -07004756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004758 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4759 null /* workSource */);
4760 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 return response;
4762 } finally {
4763 Binder.restoreCallingIdentity(identity);
4764 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004765 }
4766
4767 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004768 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4770 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004771 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4772 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4773 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004774
Jordan Liu4c733742019-02-28 12:03:40 -08004775 @Override
4776 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4777 enforceModifyPermission();
4778 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4779 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4780 channel);
4781 }
4782
4783 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 final long identity = Binder.clearCallingIdentity();
4785 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786 if (channel < 0) {
4787 return false;
4788 }
Jordan Liu4c733742019-02-28 12:03:40 -08004789 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4790 null /* workSource */);
4791 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 return success;
4793 } finally {
4794 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004795 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004796 }
4797
4798 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004799 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004800 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4802 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004803 if (DBG) {
4804 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4805 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4806 + p3 + " data=" + data);
4807 }
4808 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4809 command, p1, p2, p3, data);
4810 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004811
Jordan Liu4c733742019-02-28 12:03:40 -08004812 @Override
4813 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4814 int command, int p1, int p2, int p3, String data) {
4815 enforceModifyPermission();
4816 if (DBG) {
4817 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4818 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4819 + p3 + " data=" + data);
4820 }
4821 return iccTransmitApduLogicalChannelWithPermission(
4822 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4823 data);
4824 }
4825
4826 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4827 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004828 final long identity = Binder.clearCallingIdentity();
4829 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004830 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 return "";
4832 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004833
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004835 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4836 null /* workSource */);
4837 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004839 // Append the returned status code to the end of the response payload.
4840 String s = Integer.toHexString(
4841 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4842 if (response.payload != null) {
4843 s = IccUtils.bytesToHexString(response.payload) + s;
4844 }
4845 return s;
4846 } finally {
4847 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004848 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004849 }
Jake Hambye994d462014-02-03 13:10:13 -08004850
Evan Charltonc66da362014-05-16 14:06:40 -07004851 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004852 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4853 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004854 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4855 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004857 if (DBG) {
4858 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4859 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4860 }
4861 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4862 cla, command, p1, p2, p3, data);
4863 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004864
Jordan Liu4c733742019-02-28 12:03:40 -08004865 @Override
4866 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4867 int command, int p1, int p2, int p3, String data) {
4868 enforceModifyPermission();
4869 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4870 if (DBG) {
4871 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4872 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4873 + " data=" + data);
4874 }
4875
4876 return iccTransmitApduBasicChannelWithPermission(
4877 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4878 p2, p3, data);
4879 }
4880
4881 // open APDU basic channel assuming the caller has sufficient permissions
4882 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4883 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 final long identity = Binder.clearCallingIdentity();
4885 try {
4886 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4887 && TextUtils.equals(ISDR_AID, data)) {
4888 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004889 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4890 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 if (bestComponent == null
4892 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4893 loge("The calling package is not allowed to select ISD-R.");
4894 throw new SecurityException(
4895 "The calling package is not allowed to select ISD-R.");
4896 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004897 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004900 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4901 null /* workSource */);
4902 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 // Append the returned status code to the end of the response payload.
4905 String s = Integer.toHexString(
4906 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4907 if (response.payload != null) {
4908 s = IccUtils.bytesToHexString(response.payload) + s;
4909 }
4910 return s;
4911 } finally {
4912 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004913 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004914 }
4915
4916 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004917 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004918 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4920 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004922 final long identity = Binder.clearCallingIdentity();
4923 try {
4924 if (DBG) {
4925 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4926 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4927 }
4928
4929 IccIoResult response =
4930 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4931 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4932 subId);
4933
4934 if (DBG) {
4935 log("Exchange SIM_IO [R]" + response);
4936 }
4937
4938 byte[] result = null;
4939 int length = 2;
4940 if (response.payload != null) {
4941 length = 2 + response.payload.length;
4942 result = new byte[length];
4943 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4944 } else {
4945 result = new byte[length];
4946 }
4947
4948 result[length - 1] = (byte) response.sw2;
4949 result[length - 2] = (byte) response.sw1;
4950 return result;
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004953 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004954 }
4955
Nathan Haroldb3014052017-01-25 15:57:32 -08004956 /**
4957 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4958 * on a particular subscription
4959 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004960 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4961 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004962 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004963 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004964 return null;
4965 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966
4967 final long identity = Binder.clearCallingIdentity();
4968 try {
4969 if (appType != TelephonyManager.APPTYPE_USIM
4970 && appType != TelephonyManager.APPTYPE_SIM) {
4971 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4972 return null;
4973 }
4974 Object response = sendRequest(
4975 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4976 if (response instanceof String[]) {
4977 return (String[]) response;
4978 }
yincheng zhaod698b842019-09-06 17:06:54 -07004979 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004980 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004981 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 } finally {
4983 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004984 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004985 }
4986
yincheng zhaod698b842019-09-06 17:06:54 -07004987 /**
4988 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4989 * subscription.
4990 *
4991 * @param subId the id of the subscription.
4992 * @param appType the uicc app type, must be USIM or SIM.
4993 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4994 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004995 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004996 * @return number of fplmns that is successfully written to the SIM.
4997 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004998 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4999 String callingFeatureId) {
5000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5001 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005002 if (DBG) logv("no permissions for setForbiddenplmns");
5003 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5004 }
5005 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5006 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5007 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5008 }
5009 if (fplmns == null) {
5010 throw new IllegalArgumentException("Fplmn List provided is null");
5011 }
5012 for (String fplmn : fplmns) {
5013 if (!CellIdentity.isValidPlmn(fplmn)) {
5014 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5015 }
5016 }
5017 final long identity = Binder.clearCallingIdentity();
5018 try {
5019 Object response = sendRequest(
5020 CMD_SET_FORBIDDEN_PLMNS,
5021 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5022 subId);
5023 return (int) response;
5024 } finally {
5025 Binder.restoreCallingIdentity(identity);
5026 }
5027 }
5028
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005029 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005030 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5032 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005033
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034 final long identity = Binder.clearCallingIdentity();
5035 try {
5036 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5037 if (response.payload == null) {
5038 return "";
5039 }
Evan Charltonc66da362014-05-16 14:06:40 -07005040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 // Append the returned status code to the end of the response payload.
5042 String s = Integer.toHexString(
5043 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5044 s = IccUtils.bytesToHexString(response.payload) + s;
5045 return s;
5046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
Evan Charltonc66da362014-05-16 14:06:40 -07005049 }
5050
Jake Hambye994d462014-02-03 13:10:13 -08005051 /**
5052 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5053 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5054 *
5055 * @param itemID the ID of the item to read
5056 * @return the NV item as a String, or null on error.
5057 */
5058 @Override
5059 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5062 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063
5064 final long identity = Binder.clearCallingIdentity();
5065 try {
5066 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005067 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5069 return value;
5070 } finally {
5071 Binder.restoreCallingIdentity(identity);
5072 }
Jake Hambye994d462014-02-03 13:10:13 -08005073 }
5074
5075 /**
5076 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5077 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5078 *
5079 * @param itemID the ID of the item to read
5080 * @param itemValue the value to write, as a String
5081 * @return true on success; false on any failure
5082 */
5083 @Override
5084 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005085 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5087 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088
5089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5092 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005093 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5095 return success;
5096 } finally {
5097 Binder.restoreCallingIdentity(identity);
5098 }
Jake Hambye994d462014-02-03 13:10:13 -08005099 }
5100
5101 /**
5102 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5103 * Used for device configuration by some CDMA operators.
5104 *
5105 * @param preferredRoamingList byte array containing the new PRL
5106 * @return true on success; false on any failure
5107 */
5108 @Override
5109 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5111 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112
5113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5116 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5117 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5118 return success;
5119 } finally {
5120 Binder.restoreCallingIdentity(identity);
5121 }
Jake Hambye994d462014-02-03 13:10:13 -08005122 }
5123
5124 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005125 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005126 * Used for device configuration by some CDMA operators.
5127 *
chen xu6dac5ab2018-10-26 17:39:23 -07005128 * @param slotIndex - device slot.
5129 *
Jake Hambye994d462014-02-03 13:10:13 -08005130 * @return true on success; false on any failure
5131 */
5132 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005133 public boolean resetModemConfig(int slotIndex) {
5134 Phone phone = PhoneFactory.getPhone(slotIndex);
5135 if (phone != null) {
5136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5137 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138
chen xu6dac5ab2018-10-26 17:39:23 -07005139 final long identity = Binder.clearCallingIdentity();
5140 try {
5141 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5142 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5143 return success;
5144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 }
chen xu6dac5ab2018-10-26 17:39:23 -07005148 return false;
5149 }
5150
5151 /**
5152 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5153 *
5154 * @param slotIndex - device slot.
5155 *
5156 * @return true on success; false on any failure
5157 */
5158 @Override
5159 public boolean rebootModem(int slotIndex) {
5160 Phone phone = PhoneFactory.getPhone(slotIndex);
5161 if (phone != null) {
5162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5163 mApp, phone.getSubId(), "rebootModem");
5164
5165 final long identity = Binder.clearCallingIdentity();
5166 try {
5167 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5168 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5169 return success;
5170 } finally {
5171 Binder.restoreCallingIdentity(identity);
5172 }
5173 }
5174 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005175 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005176
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005177 public String[] getPcscfAddress(String apnType, String callingPackage,
5178 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005179 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5181 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005182 return new String[0];
5183 }
5184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005187 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 } finally {
5189 Binder.restoreCallingIdentity(identity);
5190 }
Wink Saville36469e72014-06-11 15:17:00 -07005191 }
5192
Brad Ebinger51f743a2017-01-23 13:50:20 -08005193 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005194 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5195 * {@link #disableIms(int)}.
5196 * @param slotIndex device slot.
5197 */
5198 public void resetIms(int slotIndex) {
5199 enforceModifyPermission();
5200
5201 final long identity = Binder.clearCallingIdentity();
5202 try {
5203 if (mImsResolver == null) {
5204 // may happen if the does not support IMS.
5205 return;
5206 }
5207 mImsResolver.disableIms(slotIndex);
5208 mImsResolver.enableIms(slotIndex);
5209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
5212 }
5213
5214 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005215 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5216 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005217 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005218 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005219 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220
5221 final long identity = Binder.clearCallingIdentity();
5222 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005223 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005224 // may happen if the device does not support IMS.
5225 return;
5226 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005227 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005231 }
5232
5233 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005234 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5235 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005236 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005237 public void disableIms(int slotId) {
5238 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239
5240 final long identity = Binder.clearCallingIdentity();
5241 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005242 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005243 // may happen if the device does not support IMS.
5244 return;
5245 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005246 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005250 }
5251
5252 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005253 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5254 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005255 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005256 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005257 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005258 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259
5260 final long identity = Binder.clearCallingIdentity();
5261 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005262 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005263 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5264 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005265 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005266 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267 } finally {
5268 Binder.restoreCallingIdentity(identity);
5269 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005270 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005271 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005272 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5273 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005274 @Override
5275 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005276 enforceModifyPermission();
5277
5278 final long identity = Binder.clearCallingIdentity();
5279 try {
5280 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005281 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005282 } finally {
5283 Binder.restoreCallingIdentity(identity);
5284 }
5285 }
5286
5287 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005288 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005289 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005290 */
5291 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5292 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293
5294 final long identity = Binder.clearCallingIdentity();
5295 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005296 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005297 // may happen if the device does not support IMS.
5298 return null;
5299 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005300 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 } finally {
5302 Binder.restoreCallingIdentity(identity);
5303 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005304 }
5305
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005306 /**
5307 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005308 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005309 */
5310 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5311 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312
5313 final long identity = Binder.clearCallingIdentity();
5314 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005315 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005316 // may happen if the device does not support IMS.
5317 return null;
5318 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005319 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 } finally {
5321 Binder.restoreCallingIdentity(identity);
5322 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005323 }
5324
Brad Ebinger884c07b2018-02-15 16:17:40 -08005325 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005326 * Sets the ImsService Package Name that Telephony will bind to.
5327 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005328 * @param slotIndex the slot ID that the ImsService should bind for.
5329 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005330 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005331 * @param featureTypes An integer array of feature types associated with a packageName.
5332 * @param packageName The name of the package that the current configuration will be replaced
5333 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005334 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005335 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005336 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5337 int[] featureTypes, String packageName) {
5338 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5339 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5341 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005342 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344 final long identity = Binder.clearCallingIdentity();
5345 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005346 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005347 // may happen if the device does not support IMS.
5348 return false;
5349 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005350 Map<Integer, String> featureConfig = new HashMap<>();
5351 for (int featureType : featureTypes) {
5352 featureConfig.put(featureType, packageName);
5353 }
5354 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5355 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 } finally {
5357 Binder.restoreCallingIdentity(identity);
5358 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005359 }
5360
5361 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005362 * Clears any carrier ImsService overrides for the slot index specified that were previously
5363 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5364 *
5365 * This should only be used for testing.
5366 *
5367 * @param slotIndex the slot ID that the ImsService should bind for.
5368 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5369 */
5370 @Override
5371 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5372 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5373 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5374 "clearCarrierImsServiceOverride");
5375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5376 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5377 "clearCarrierImsServiceOverride");
5378
5379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 if (mImsResolver == null) {
5382 // may happen if the device does not support IMS.
5383 return false;
5384 }
5385 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388 }
5389 }
5390
5391 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005392 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005393 *
5394 * @param slotId The slot that the ImsService is associated with.
5395 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5396 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005397 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005398 * @return the package name of the ImsService configuration.
5399 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005400 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5401 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005402 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005403 TelephonyPermissions
5404 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5405 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5406 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 final long identity = Binder.clearCallingIdentity();
5409 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005410 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005411 // may happen if the device does not support IMS.
5412 return "";
5413 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005414 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005415 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5416 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 } finally {
5418 Binder.restoreCallingIdentity(identity);
5419 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005420 }
5421
Brad Ebinger77b832e2019-10-17 17:03:22 -07005422 /**
5423 * Get the MmTelFeature state associated with the requested subscription id.
5424 * @param subId The subscription that the MmTelFeature is associated with.
5425 * @param callback A callback with an integer containing the
5426 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5427 */
5428 @Override
5429 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5430 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5431 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5432 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5433 "IMS not available on device.");
5434 }
5435 final long token = Binder.clearCallingIdentity();
5436 try {
5437 int slotId = getSlotIndex(subId);
5438 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5439 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5440 + subId + "'");
5441 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5442 }
5443 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5444 try {
5445 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5446 } catch (RemoteException e) {
5447 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5448 + "Ignore");
5449 }
5450 });
5451 } finally {
5452 Binder.restoreCallingIdentity(token);
5453 }
5454 }
5455
Wink Saville36469e72014-06-11 15:17:00 -07005456 public void setImsRegistrationState(boolean registered) {
5457 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458
5459 final long identity = Binder.clearCallingIdentity();
5460 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005461 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462 } finally {
5463 Binder.restoreCallingIdentity(identity);
5464 }
Wink Saville36469e72014-06-11 15:17:00 -07005465 }
5466
5467 /**
Stuart Scott54788802015-03-30 13:18:01 -07005468 * Set the network selection mode to automatic.
5469 *
5470 */
5471 @Override
5472 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5474 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475
5476 final long identity = Binder.clearCallingIdentity();
5477 try {
shilufc958392020-01-20 11:36:01 -08005478 if (!isActiveSubscription(subId)) {
5479 return;
5480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5482 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
Stuart Scott54788802015-03-30 13:18:01 -07005486 }
5487
Jack Yud10cdd42020-09-28 20:28:01 -07005488 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005489 * Ask the radio to connect to the input network and change selection mode to manual.
5490 *
5491 * @param subId the id of the subscription.
5492 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5493 * the operator to attach to.
5494 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5495 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5496 * normal network selection next time.
5497 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005498 */
5499 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005500 public boolean setNetworkSelectionModeManual(
5501 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5503 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005504
5505 if (!isActiveSubscription(subId)) {
5506 return false;
5507 }
5508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509 final long identity = Binder.clearCallingIdentity();
5510 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005511 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005513 if (DBG) {
5514 log("setNetworkSelectionModeManual: subId: " + subId
5515 + " operator: " + operatorInfo);
5516 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
5520 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005521 }
shilu84f6e8b2019-12-19 13:58:01 -08005522 /**
5523 * Get the manual network selection
5524 *
5525 * @param subId the id of the subscription.
5526 *
5527 * @return the previously saved user selected PLMN
5528 */
5529 @Override
5530 public String getManualNetworkSelectionPlmn(int subId) {
5531 TelephonyPermissions
5532 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5533 mApp, subId, "getManualNetworkSelectionPlmn");
5534
5535 final long identity = Binder.clearCallingIdentity();
5536 try {
5537 if (!isActiveSubscription(subId)) {
5538 return "";
5539 }
5540
5541 final Phone phone = getPhone(subId);
5542 if (phone == null) {
5543 return "";
5544 }
5545 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5546 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5547 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
5551 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005552
5553 /**
5554 * Scans for available networks.
5555 */
5556 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005557 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5558 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5560 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005561 LocationAccessPolicy.LocationPermissionResult locationResult =
5562 LocationAccessPolicy.checkLocationPermission(mApp,
5563 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5564 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005565 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005566 .setCallingPid(Binder.getCallingPid())
5567 .setCallingUid(Binder.getCallingUid())
5568 .setMethod("getCellNetworkScanResults")
5569 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5570 .build());
5571 switch (locationResult) {
5572 case DENIED_HARD:
5573 throw new SecurityException("Not allowed to access scan results -- location");
5574 case DENIED_SOFT:
5575 return null;
5576 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577
Pengquan Menga1bb6272018-09-06 09:59:22 -07005578 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 try {
5580 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005581 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005586 }
5587
5588 /**
sqian80370722020-01-29 15:02:51 -08005589 * Get the call forwarding info, given the call forwarding reason.
5590 */
5591 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005592 public void getCallForwarding(int subId, int callForwardingReason,
5593 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005594 enforceReadPrivilegedPermission("getCallForwarding");
5595 long identity = Binder.clearCallingIdentity();
5596 try {
5597 if (DBG) {
5598 log("getCallForwarding: subId " + subId
5599 + " callForwardingReason" + callForwardingReason);
5600 }
Hall Liua1acea22020-09-18 19:04:59 -07005601
5602 Phone phone = getPhone(subId);
5603 if (phone == null) {
5604 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005605 callback.onError(
5606 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005607 } catch (RemoteException e) {
5608 // ignore
5609 }
5610 return;
5611 }
5612
5613 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5614 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5615 @Override
5616 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5617 try {
5618 callback.onCallForwardingInfoAvailable(info);
5619 } catch (RemoteException e) {
5620 // ignore
5621 }
5622 }
5623
5624 @Override
5625 public void onError(int error) {
5626 try {
5627 callback.onError(error);
5628 } catch (RemoteException e) {
5629 // ignore
5630 }
5631 }
5632 });
5633 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
5637 }
5638
5639 /**
5640 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5641 * reason, the number to forward, and the timeout before the forwarding is attempted.
5642 */
5643 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005644 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5645 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005646 enforceModifyPermission();
5647 long identity = Binder.clearCallingIdentity();
5648 try {
5649 if (DBG) {
5650 log("setCallForwarding: subId " + subId
5651 + " callForwardingInfo" + callForwardingInfo);
5652 }
Hall Liua1acea22020-09-18 19:04:59 -07005653
5654 Phone phone = getPhone(subId);
5655 if (phone == null) {
5656 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005657 callback.accept(
5658 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005659 } catch (RemoteException e) {
5660 // ignore
5661 }
5662 return;
5663 }
5664
5665 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5666 FunctionalUtils.ignoreRemoteException(callback::accept));
5667
5668 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005669 } finally {
5670 Binder.restoreCallingIdentity(identity);
5671 }
5672 }
5673
5674 /**
Hall Liua1acea22020-09-18 19:04:59 -07005675 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005676 */
5677 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005678 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005679 enforceReadPrivilegedPermission("getCallForwarding");
5680 long identity = Binder.clearCallingIdentity();
5681 try {
Hall Liua1acea22020-09-18 19:04:59 -07005682
5683 Phone phone = getPhone(subId);
5684 if (phone == null) {
5685 try {
5686 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5687 } catch (RemoteException e) {
5688 // ignore
5689 }
5690 return;
5691 }
5692
5693 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5694
sqian80370722020-01-29 15:02:51 -08005695 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005696 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
5700 }
5701
5702 /**
Hall Liua1acea22020-09-18 19:04:59 -07005703 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005704 */
5705 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005706 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005707 enforceModifyPermission();
5708 long identity = Binder.clearCallingIdentity();
5709 try {
Hall Liua1acea22020-09-18 19:04:59 -07005710 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5711
5712 Phone phone = getPhone(subId);
5713 if (phone == null) {
5714 try {
5715 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5716 } catch (RemoteException e) {
5717 // ignore
5718 }
5719 return;
5720 }
5721
5722 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5723 FunctionalUtils.ignoreRemoteException(callback::accept));
5724
5725 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
5729 }
5730
5731 /**
yinxub1bed742017-04-17 11:45:04 -07005732 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005733 *
yinxub1bed742017-04-17 11:45:04 -07005734 * @param subId id of the subscription
5735 * @param request contains the radio access networks with bands/channels to scan
5736 * @param messenger callback messenger for scan results or errors
5737 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005738 * @return the id of the requested scan which can be used to stop the scan.
5739 */
5740 @Override
5741 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005742 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5744 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005745 LocationAccessPolicy.LocationPermissionResult locationResult =
5746 LocationAccessPolicy.checkLocationPermission(mApp,
5747 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5748 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005749 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005750 .setCallingPid(Binder.getCallingPid())
5751 .setCallingUid(Binder.getCallingUid())
5752 .setMethod("requestNetworkScan")
5753 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5754 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005755 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005756 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5757 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005758 if (e != null) {
5759 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5760 throw e;
5761 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005762 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005763 return TelephonyScanManager.INVALID_SCAN_ID;
5764 }
5765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 }
Hall Liu912dfd32019-04-25 14:02:26 -07005767 int callingUid = Binder.getCallingUid();
5768 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005769 final long identity = Binder.clearCallingIdentity();
5770 try {
5771 return mNetworkScanRequestTracker.startNetworkScan(
5772 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005773 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
yinxu504e1392017-04-12 16:03:22 -07005777 }
5778
Hall Liub2ac8ef2019-02-28 15:56:23 -08005779 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005780 NetworkScanRequest request, int subId, String callingPackage) {
5781 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005782 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5783 boolean hasNetworkScanPermission =
5784 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5785 == PERMISSION_GRANTED;
5786
5787 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5788 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5789 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005790 }
5791
5792 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5793 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005794 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5795 return new SecurityException("Specific channels must not be"
5796 + " scanned without location access.");
5797 }
5798 }
5799 }
5800
Hall Liub2ac8ef2019-02-28 15:56:23 -08005801 return null;
5802 }
5803
yinxu504e1392017-04-12 16:03:22 -07005804 /**
5805 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005806 *
5807 * @param subId id of the subscription
5808 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005809 */
5810 @Override
5811 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5813 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814
Hall Liu912dfd32019-04-25 14:02:26 -07005815 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 final long identity = Binder.clearCallingIdentity();
5817 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005818 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819 } finally {
5820 Binder.restoreCallingIdentity(identity);
5821 }
yinxu504e1392017-04-12 16:03:22 -07005822 }
5823
5824 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005825 * Get the calculated preferred network type.
5826 * Used for debugging incorrect network type.
5827 *
5828 * @return the preferred network type, defined in RILConstants.java.
5829 */
5830 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005831 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005832 final Phone defaultPhone = getDefaultPhone();
5833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005834 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005835 return RILConstants.PREFERRED_NETWORK_MODE;
5836 }
5837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838 final long identity = Binder.clearCallingIdentity();
5839 try {
5840 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005841 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 } finally {
5843 Binder.restoreCallingIdentity(identity);
5844 }
Junda Liu84d15a22014-07-02 11:21:04 -07005845 }
5846
5847 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005848 * Get the preferred network type.
5849 * Used for device configuration by some CDMA operators.
5850 *
5851 * @return the preferred network type, defined in RILConstants.java.
5852 */
5853 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005854 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005855 TelephonyPermissions
5856 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5857 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858
5859 final long identity = Binder.clearCallingIdentity();
5860 try {
5861 if (DBG) log("getPreferredNetworkType");
5862 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5863 int networkType = (result != null ? result[0] : -1);
5864 if (DBG) log("getPreferredNetworkType: " + networkType);
5865 return networkType;
5866 } finally {
5867 Binder.restoreCallingIdentity(identity);
5868 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005869 }
5870
5871 /**
5872 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005873 *
5874 * @param networkType the preferred network type, defined in RILConstants.java.
5875 * @return true on success; false on any failure.
5876 */
5877 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005878 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5880 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881
5882 final long identity = Binder.clearCallingIdentity();
5883 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005884 Settings.Global.putInt(mApp.getContentResolver(),
5885 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005886
5887 Boolean success = (Boolean) sendRequest(
5888 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5889 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5890 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 } finally {
5892 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005893 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005894 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005895
5896 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005897 * Get the allowed network types that store in the telephony provider.
5898 *
5899 * @param subId the id of the subscription.
5900 * @return allowedNetworkTypes the allowed network types.
5901 */
5902 @Override
5903 public long getAllowedNetworkTypes(int subId) {
5904 TelephonyPermissions
5905 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5906 mApp, subId, "getAllowedNetworkTypes");
5907
5908 final long identity = Binder.clearCallingIdentity();
5909 try {
5910 return SubscriptionManager.getLongSubscriptionProperty(
5911 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5912 } finally {
5913 Binder.restoreCallingIdentity(identity);
5914 }
5915 }
5916
5917 /**
5918 * Set the allowed network types.
5919 *
5920 * @param subId the id of the subscription.
5921 * @param allowedNetworkTypes the allowed network types.
5922 * @return true on success; false on any failure.
5923 */
5924 @Override
5925 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5927 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005928
calvinpan089c2a62020-03-12 14:17:55 +08005929 SubscriptionManager.setSubscriptionProperty(subId,
5930 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5931 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005932
calvinpan089c2a62020-03-12 14:17:55 +08005933 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5934 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5935 RILConstants.PREFERRED_NETWORK_MODE);
5936 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005937 }
5938
5939 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005940 * Get the allowed network types for certain reason.
5941 *
5942 * @param subId the id of the subscription.
5943 * @param reason the reason the allowed network type change is taking place
5944 * @return the allowed network types.
5945 */
5946 @Override
5947 public long getAllowedNetworkTypesForReason(int subId,
5948 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5949 TelephonyPermissions
5950 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5951 mApp, subId, "getAllowedNetworkTypesForReason");
5952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
5958 }
5959
5960 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07005961 * Enable/Disable E-UTRA-NR Dual Connectivity
5962 * @param subId subscription id of the sim card
5963 * @param nrDualConnectivityState expected NR dual connectivity state
5964 * This can be passed following states
5965 * <ol>
5966 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5967 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5968 * <li>Disable NR dual connectivity and force secondary cell to be released
5969 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5970 * </ol>
5971 * @return operation result.
5972 */
5973 @Override
5974 public int setNrDualConnectivityState(int subId,
5975 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5977 mApp, subId, "enableNRDualConnectivity");
5978 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5979 final long identity = Binder.clearCallingIdentity();
5980 try {
5981 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5982 nrDualConnectivityState, subId,
5983 workSource);
5984 if (DBG) log("enableNRDualConnectivity result: " + result);
5985 return result;
5986 } finally {
5987 Binder.restoreCallingIdentity(identity);
5988 }
5989 }
5990
5991 /**
5992 * Is E-UTRA-NR Dual Connectivity enabled
5993 * @return true if dual connectivity is enabled else false
5994 */
5995 @Override
5996 public boolean isNrDualConnectivityEnabled(int subId) {
5997 TelephonyPermissions
5998 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5999 mApp, subId, "isNRDualConnectivityEnabled");
6000 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6001 final long identity = Binder.clearCallingIdentity();
6002 try {
6003 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6004 null, subId, workSource);
6005 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6006 return isEnabled;
6007 } finally {
6008 Binder.restoreCallingIdentity(identity);
6009 }
6010 }
6011
6012 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006013 * get carrier bandwidth per primary and secondary carrier
6014 * @param subId subscription id of the sim card
6015 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6016 */
6017 @Override
6018 public CarrierBandwidth getCarrierBandwidth(int subId) {
6019 TelephonyPermissions
6020 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6021 mApp, subId, "isNRDualConnectivityEnabled");
6022 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6023 final long identity = Binder.clearCallingIdentity();
6024 try {
6025 CarrierBandwidth carrierBandwidth =
6026 getPhoneFromSubId(subId).getCarrierBandwidth();
6027 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6028 return carrierBandwidth;
6029 } finally {
6030 Binder.restoreCallingIdentity(identity);
6031 }
6032 }
6033
6034 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006035 * Get the effective allowed network types on the device.
6036 * This API will return an intersection of allowed network types for all reasons,
6037 * including the configuration done through setAllowedNetworkTypes
6038 *
6039 * @param subId the id of the subscription.
6040 * @return the allowed network types
6041 */
6042 @Override
6043 public long getEffectiveAllowedNetworkTypes(int subId) {
6044 TelephonyPermissions
6045 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6046 mApp, subId, "getEffectiveAllowedNetworkTypes");
6047 final long identity = Binder.clearCallingIdentity();
6048 try {
6049 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6050 } finally {
6051 Binder.restoreCallingIdentity(identity);
6052 }
6053 }
6054
6055 /**
6056 * Set the allowed network types of the device and
6057 * provide the reason triggering the allowed network change.
6058 *
6059 * @param subId the id of the subscription.
6060 * @param reason the reason the allowed network type change is taking place
6061 * @param allowedNetworkTypes the allowed network types.
6062 * @return true on success; false on any failure.
6063 */
6064 @Override
6065 public boolean setAllowedNetworkTypesForReason(int subId,
6066 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6068 mApp, subId, "setAllowedNetworkTypesForReason");
6069 final long identity = Binder.clearCallingIdentity();
6070 try {
6071 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6072 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6073 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6074 RILConstants.PREFERRED_NETWORK_MODE);
6075 return setPreferredNetworkType(subId, preferredNetworkMode);
6076 } finally {
6077 Binder.restoreCallingIdentity(identity);
6078 }
6079 }
6080
6081 /**
Miaoa84611c2019-03-15 09:21:10 +08006082 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006083 *
Miaoa84611c2019-03-15 09:21:10 +08006084 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006085 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006086 * @hide
6087 */
6088 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006089 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006090 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006092 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 try {
Miaoa84611c2019-03-15 09:21:10 +08006094 if (phone != null) {
6095 return phone.hasMatchedTetherApnSetting();
6096 } else {
6097 return false;
6098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006099 } finally {
6100 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006101 }
Junda Liu475951f2014-11-07 16:45:03 -08006102 }
6103
6104 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006105 * Enable or disable always reporting signal strength changes from radio.
6106 *
6107 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6108 */
6109 @Override
6110 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6111 enforceModifyPermission();
6112 enforceSystemCaller();
6113
6114 final long identity = Binder.clearCallingIdentity();
6115 final Phone phone = getPhone(subId);
6116 try {
6117 if (phone != null) {
6118 if (DBG) {
6119 log("setAlwaysReportSignalStrength: subId=" + subId
6120 + " isEnable=" + isEnable);
6121 }
6122 phone.setAlwaysReportSignalStrength(isEnable);
6123 } else {
6124 loge("setAlwaysReportSignalStrength: no phone found for subId="
6125 + subId);
6126 }
6127 } finally {
6128 Binder.restoreCallingIdentity(identity);
6129 }
6130 }
6131
6132 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006133 * Get the user enabled state of Mobile Data.
6134 *
6135 * TODO: remove and use isUserDataEnabled.
6136 * This can't be removed now because some vendor codes
6137 * calls through ITelephony directly while they should
6138 * use TelephonyManager.
6139 *
6140 * @return true on enabled
6141 */
6142 @Override
6143 public boolean getDataEnabled(int subId) {
6144 return isUserDataEnabled(subId);
6145 }
6146
6147 /**
6148 * Get whether mobile data is enabled per user setting.
6149 *
6150 * There are other factors deciding whether mobile data is actually enabled, but they are
6151 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006152 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006153 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006154 *
6155 * @return {@code true} if data is enabled else {@code false}
6156 */
6157 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006158 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006159 try {
6160 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6161 null);
6162 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6164 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006165 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166
6167 final long identity = Binder.clearCallingIdentity();
6168 try {
6169 int phoneId = mSubscriptionController.getPhoneId(subId);
6170 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6171 Phone phone = PhoneFactory.getPhone(phoneId);
6172 if (phone != null) {
6173 boolean retVal = phone.isUserDataEnabled();
6174 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6175 return retVal;
6176 } else {
6177 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6178 return false;
6179 }
6180 } finally {
6181 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006182 }
6183 }
6184
6185 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006186 * Checks if the device is capable of mobile data by considering whether whether the
6187 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6188 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006189 *
Shuo Qian985d1232020-01-08 14:30:06 -08006190 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006191 */
6192 @Override
6193 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006194 try {
6195 try {
6196 mApp.enforceCallingOrSelfPermission(
6197 android.Manifest.permission.ACCESS_NETWORK_STATE,
6198 null);
6199 } catch (Exception e) {
6200 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6201 "isDataEnabled");
6202 }
6203 } catch (Exception e) {
6204 enforceReadPrivilegedPermission("isDataEnabled");
6205 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006206
6207 final long identity = Binder.clearCallingIdentity();
6208 try {
6209 int phoneId = mSubscriptionController.getPhoneId(subId);
6210 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6211 Phone phone = PhoneFactory.getPhone(phoneId);
6212 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006213 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6215 return retVal;
6216 } else {
6217 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6218 return false;
6219 }
6220 } finally {
6221 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006222 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006223 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006224
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006225 /**
6226 * Check if data is enabled for a specific reason
6227 * @param subId Subscription index
6228 * @param reason the reason the data enable change is taking place
6229 * @return {@code true} if the overall data is enabled; {@code false} if not.
6230 */
6231 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006232 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006233 @TelephonyManager.DataEnabledReason int reason) {
6234 try {
6235 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6236 null);
6237 } catch (Exception e) {
6238 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006239 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006240 }
6241
6242
6243 final long identity = Binder.clearCallingIdentity();
6244 try {
6245 int phoneId = mSubscriptionController.getPhoneId(subId);
6246 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006247 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006248 + " reason=" + reason);
6249 }
6250 Phone phone = PhoneFactory.getPhone(phoneId);
6251 if (phone != null) {
6252 boolean retVal;
6253 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6254 retVal = phone.isUserDataEnabled();
6255 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006256 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006257 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006258 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006259 return retVal;
6260 } else {
6261 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006262 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006263 + subId + " retVal=false");
6264 }
6265 return false;
6266 }
6267 } finally {
6268 Binder.restoreCallingIdentity(identity);
6269 }
6270 }
6271
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006272 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006273 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006274 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6275 // Skip the check if it's one of these special uids
6276 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6277 }
6278
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006279 //load access rules from carrier configs, and check those as well: b/139133814
6280 SubscriptionController subController = SubscriptionController.getInstance();
6281 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6282 || subController == null) return privilegeFromSim;
6283
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006284 PackageManager pkgMgr = phone.getContext().getPackageManager();
6285 String[] packages = pkgMgr.getPackagesForUid(uid);
6286
6287 final long identity = Binder.clearCallingIdentity();
6288 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006289 int subId = phone.getSubId();
6290 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6291 // A test override is in place for the privileges for this subId, so don't try to
6292 // read the subscription privileges.
6293 return privilegeFromSim;
6294 }
6295 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006296 SubscriptionManager subManager = (SubscriptionManager)
6297 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6298 for (String pkg : packages) {
6299 if (subManager.canManageSubscription(subInfo, pkg)) {
6300 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6301 }
6302 }
6303 return privilegeFromSim;
6304 } finally {
6305 Binder.restoreCallingIdentity(identity);
6306 }
6307 }
6308
6309 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6310 String pkgName) {
6311 //load access rules from carrier configs, and check those as well: b/139133814
6312 SubscriptionController subController = SubscriptionController.getInstance();
6313 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6314 || subController == null) return privilegeFromSim;
6315
6316 final long identity = Binder.clearCallingIdentity();
6317 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006318 int subId = phone.getSubId();
6319 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6320 // A test override is in place for the privileges for this subId, so don't try to
6321 // read the subscription privileges.
6322 return privilegeFromSim;
6323 }
6324 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006325 SubscriptionManager subManager = (SubscriptionManager)
6326 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6327 return subManager.canManageSubscription(subInfo, pkgName)
6328 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
6332 }
6333
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006334 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006335 public int getCarrierPrivilegeStatus(int subId) {
6336 final Phone phone = getPhone(subId);
6337 if (phone == null) {
6338 loge("getCarrierPrivilegeStatus: Invalid subId");
6339 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6340 }
6341 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006342 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006343 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006344 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6345 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006346
6347 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6348 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006349 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006350 }
Junda Liu29340342014-07-10 15:23:27 -07006351
6352 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006353 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006354 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006355 final Phone phone = getPhone(subId);
6356 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006357 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006358 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6359 }
6360 UiccProfile profile =
6361 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6362 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006363 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006364 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6365 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006366 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006367 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006368 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006369 }
6370
6371 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006372 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6373 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006374 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006375 }
6376
6377 int phoneId = SubscriptionManager.getPhoneId(subId);
6378 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006379 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006380 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006381 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6382 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006383 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6384 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6385 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006386 }
6387
6388 @Override
6389 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006390 if (TextUtils.isEmpty(pkgName))
6391 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006392 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6393 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6394 UiccCard card = UiccController.getInstance().getUiccCard(i);
6395 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006396 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006397 continue;
6398 }
6399
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006400 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6401 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6402 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006403 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6404 break;
6405 }
6406 }
6407
6408 return result;
Junda Liu29340342014-07-10 15:23:27 -07006409 }
Derek Tan89e89d42014-07-08 17:00:10 -07006410
6411 @Override
Junda Liue64de782015-04-16 17:19:16 -07006412 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6413 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6414 loge("phoneId " + phoneId + " is not valid.");
6415 return null;
6416 }
6417 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006418 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006419 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006420 return null ;
6421 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006422 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006423 }
6424
Amith Yamasani6e118872016-02-19 12:53:51 -08006425 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006426 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006427 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006428 List<String> privilegedPackages = new ArrayList<>();
6429 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006430 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6431 // has UICC in that slot.
6432 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006433 if (card.hasCarrierPrivilegeRules()) {
6434 if (packages == null) {
6435 // Only check packages in user 0 for now
6436 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006437 PackageManager.MATCH_DISABLED_COMPONENTS
6438 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006439 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006440 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006441 }
6442 for (int p = packages.size() - 1; p >= 0; p--) {
6443 PackageInfo pkgInfo = packages.get(p);
6444 if (pkgInfo != null && pkgInfo.packageName != null
6445 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006446 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006447 privilegedPackages.add(pkgInfo.packageName);
6448 }
6449 }
6450 }
6451 }
6452 return privilegedPackages;
6453 }
6454
chen xuf7e9fe82019-05-09 19:31:02 -07006455 @Override
6456 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006457 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6458
6459 final long identity = Binder.clearCallingIdentity();
6460
chen xuf7e9fe82019-05-09 19:31:02 -07006461 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006462 try {
6463 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6464 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6465 }
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006468 }
6469 return privilegedPackages;
6470 }
6471
Wink Savilleb564aae2014-10-23 10:18:09 -07006472 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006473 final Phone phone = getPhone(subId);
6474 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006475 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006476 return null;
6477 }
6478 String iccId = card.getIccId();
6479 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006480 return null;
6481 }
6482 return iccId;
6483 }
6484
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006485 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006486 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6487 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006488 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006489 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491 final long identity = Binder.clearCallingIdentity();
6492 try {
6493 final String iccId = getIccId(subId);
6494 final Phone phone = getPhone(subId);
6495 if (phone == null) {
6496 return false;
6497 }
6498 final String subscriberId = phone.getSubscriberId();
6499
6500 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006501 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502 + subscriberId + " to " + number);
6503 }
6504
6505 if (TextUtils.isEmpty(iccId)) {
6506 return false;
6507 }
6508
6509 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6510
6511 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6512 if (alphaTag == null) {
6513 editor.remove(alphaTagPrefKey);
6514 } else {
6515 editor.putString(alphaTagPrefKey, alphaTag);
6516 }
6517
6518 // Record both the line number and IMSI for this ICCID, since we need to
6519 // track all merged IMSIs based on line number
6520 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6521 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6522 if (number == null) {
6523 editor.remove(numberPrefKey);
6524 editor.remove(subscriberPrefKey);
6525 } else {
6526 editor.putString(numberPrefKey, number);
6527 editor.putString(subscriberPrefKey, subscriberId);
6528 }
6529
6530 editor.commit();
6531 return true;
6532 } finally {
6533 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006534 }
Derek Tan7226c842014-07-02 17:42:23 -07006535 }
6536
6537 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006538 public String getLine1NumberForDisplay(int subId, String callingPackage,
6539 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006540 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006542 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006543 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006544 return null;
6545 }
Derek Tan97ebb422014-09-05 16:55:38 -07006546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 final long identity = Binder.clearCallingIdentity();
6548 try {
6549 String iccId = getIccId(subId);
6550 if (iccId != null) {
6551 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6552 if (DBG_MERGE) {
6553 log("getLine1NumberForDisplay returning "
6554 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6555 }
6556 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6559 return null;
6560 } finally {
6561 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006562 }
Derek Tan7226c842014-07-02 17:42:23 -07006563 }
6564
6565 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006566 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6567 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006569 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006570 return null;
6571 }
Derek Tan97ebb422014-09-05 16:55:38 -07006572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006573 final long identity = Binder.clearCallingIdentity();
6574 try {
6575 String iccId = getIccId(subId);
6576 if (iccId != null) {
6577 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6578 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6579 }
6580 return null;
6581 } finally {
6582 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006583 }
Derek Tan7226c842014-07-02 17:42:23 -07006584 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006585
6586 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006587 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6588 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006589 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6590 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006591 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006592 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006593 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006594 return null;
6595 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006596
Jordan Liub49b04b2019-05-06 14:45:15 -07006597 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6598 // the process, where TelephonyManager was instantiated.
6599 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006600 final long identity = Binder.clearCallingIdentity();
6601 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006602 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603 final TelephonyManager tele = TelephonyManager.from(context);
6604 final SubscriptionManager sub = SubscriptionManager.from(context);
6605
6606 // Figure out what subscribers are currently active
6607 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006608
Jordan Liub49b04b2019-05-06 14:45:15 -07006609 // Only consider subs which match the current subId
6610 // This logic can be simplified. See b/131189269 for progress.
6611 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006612 activeSubscriberIds.add(tele.getSubscriberId(subId));
6613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006614
6615 // First pass, find a number override for an active subscriber
6616 String mergeNumber = null;
6617 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6618 for (String key : prefs.keySet()) {
6619 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6620 final String subscriberId = (String) prefs.get(key);
6621 if (activeSubscriberIds.contains(subscriberId)) {
6622 final String iccId = key.substring(
6623 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6624 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6625 mergeNumber = (String) prefs.get(numberKey);
6626 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006627 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 + " for active subscriber " + subscriberId);
6629 }
6630 if (!TextUtils.isEmpty(mergeNumber)) {
6631 break;
6632 }
6633 }
6634 }
6635 }
6636
6637 // Shortcut when no active merged subscribers
6638 if (TextUtils.isEmpty(mergeNumber)) {
6639 return null;
6640 }
6641
6642 // Second pass, find all subscribers under that line override
6643 final ArraySet<String> result = new ArraySet<>();
6644 for (String key : prefs.keySet()) {
6645 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6646 final String number = (String) prefs.get(key);
6647 if (mergeNumber.equals(number)) {
6648 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6649 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6650 final String subscriberId = (String) prefs.get(subscriberKey);
6651 if (!TextUtils.isEmpty(subscriberId)) {
6652 result.add(subscriberId);
6653 }
6654 }
6655 }
6656 }
6657
6658 final String[] resultArray = result.toArray(new String[result.size()]);
6659 Arrays.sort(resultArray);
6660 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006661 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6663 }
6664 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006665 } finally {
6666 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006667 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006668 }
6669
6670 @Override
zoey chen38003472019-12-13 17:16:31 +08006671 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6672 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006673
6674 final long identity = Binder.clearCallingIdentity();
6675 try {
6676 final TelephonyManager telephonyManager = mApp.getSystemService(
6677 TelephonyManager.class);
6678 String subscriberId = telephonyManager.getSubscriberId(subId);
6679 if (subscriberId == null) {
6680 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006681 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006682 + subId);
6683 }
6684 return null;
6685 }
6686
6687 final SubscriptionInfo info = SubscriptionController.getInstance()
6688 .getSubscriptionInfo(subId);
6689 final ParcelUuid groupUuid = info.getGroupUuid();
6690 // If it doesn't belong to any group, return just subscriberId of itself.
6691 if (groupUuid == null) {
6692 return new String[]{subscriberId};
6693 }
6694
6695 // Get all subscriberIds from the group.
6696 final List<String> mergedSubscriberIds = new ArrayList<>();
6697 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006698 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006699 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006700 for (SubscriptionInfo subInfo : groupInfos) {
6701 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6702 if (subscriberId != null) {
6703 mergedSubscriberIds.add(subscriberId);
6704 }
6705 }
6706
6707 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6708 } finally {
6709 Binder.restoreCallingIdentity(identity);
6710
6711 }
6712 }
6713
6714 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006715 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006716 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006717 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718
6719 final long identity = Binder.clearCallingIdentity();
6720 try {
6721 final Phone phone = getPhone(subId);
6722 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6723 } finally {
6724 Binder.restoreCallingIdentity(identity);
6725 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006726 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006727
6728 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006729 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006730 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6731 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006732 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6733 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006734
6735 final long identity = Binder.clearCallingIdentity();
6736 try {
6737 final Phone phone = getPhone(subId);
6738 if (phone == null) {
6739 return false;
6740 }
6741 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6742 cdmaNonRoamingList);
6743 } finally {
6744 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006745 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006746 }
6747
6748 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006749 @Deprecated
6750 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6751 enforceModifyPermission();
6752
6753 int returnValue = 0;
6754 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006755 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006756 if(result.exception == null) {
6757 if (result.result != null) {
6758 byte[] responseData = (byte[])(result.result);
6759 if(responseData.length > oemResp.length) {
6760 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6761 responseData.length + "bytes. Buffer Size is " +
6762 oemResp.length + "bytes.");
6763 }
6764 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6765 returnValue = responseData.length;
6766 }
6767 } else {
6768 CommandException ex = (CommandException) result.exception;
6769 returnValue = ex.getCommandError().ordinal();
6770 if(returnValue > 0) returnValue *= -1;
6771 }
6772 } catch (RuntimeException e) {
6773 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6774 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6775 if(returnValue > 0) returnValue *= -1;
6776 }
6777
6778 return returnValue;
6779 }
6780
6781 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006782 public void setRadioCapability(RadioAccessFamily[] rafs) {
6783 try {
6784 ProxyController.getInstance().setRadioCapability(rafs);
6785 } catch (RuntimeException e) {
6786 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6787 }
6788 }
6789
6790 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006791 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006792 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006793 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006794 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006795 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 final long identity = Binder.clearCallingIdentity();
6798 try {
chen xub97461a2018-10-26 14:17:57 -07006799 TelephonyPermissions
6800 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6801 mApp, phone.getSubId(), "getRadioAccessFamily");
6802 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 } finally {
6804 Binder.restoreCallingIdentity(identity);
6805 }
chen xub97461a2018-10-26 14:17:57 -07006806 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006807 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006808
6809 @Override
6810 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006811 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006812 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813
6814 final long identity = Binder.clearCallingIdentity();
6815 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006816 ImsManager.getInstance(defaultPhone.getContext(),
6817 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006818 } finally {
6819 Binder.restoreCallingIdentity(identity);
6820 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006821 }
6822
6823 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006824 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006825 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6827 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006828 return false;
6829 }
Svet Ganovb320e182015-04-16 12:30:10 -07006830
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831 final long identity = Binder.clearCallingIdentity();
6832 try {
6833 // Check the user preference and the system-level IMS setting. Even if the user has
6834 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6835 // In the long run, we may instead need to check if there exists a connection service
6836 // which can support video calling.
6837 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006838 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 return imsManager.isVtEnabledByPlatform()
6840 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6841 && imsManager.isVtEnabledByUser();
6842 } finally {
6843 Binder.restoreCallingIdentity(identity);
6844 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006845 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006846
Andrew Leea1239f22015-03-02 17:44:07 -08006847 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006848 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6849 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006851 mApp, subId, callingPackage, callingFeatureId,
6852 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853 return false;
6854 }
6855
6856 final long identity = Binder.clearCallingIdentity();
6857 try {
6858 CarrierConfigManager configManager =
6859 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006860 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6862 } finally {
6863 Binder.restoreCallingIdentity(identity);
6864 }
Andrew Leea1239f22015-03-02 17:44:07 -08006865 }
6866
6867 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006868 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006870 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 return false;
6872 }
6873
6874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 CarrierConfigManager configManager =
6877 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006878 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6880 } finally {
6881 Binder.restoreCallingIdentity(identity);
6882 }
Andrew Leea1239f22015-03-02 17:44:07 -08006883 }
6884
Andrew Lee9431b832015-03-09 18:46:45 -07006885 @Override
6886 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006887 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006888 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006889 }
6890
6891 @Override
6892 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006893 final long identity = Binder.clearCallingIdentity();
6894 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006895 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896 } finally {
6897 Binder.restoreCallingIdentity(identity);
6898 }
Andrew Lee9431b832015-03-09 18:46:45 -07006899 }
6900
Hall Liuf6668912018-10-31 17:05:23 -07006901 /**
6902 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6903 * support for the feature and device firmware support.
6904 *
6905 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6906 */
6907 @Override
6908 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006910 final Phone phone = getPhone(subscriptionId);
6911 if (phone == null) {
6912 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6913 return false;
6914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006915 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006916 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006917 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6918 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006919 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006920 return isCarrierSupported && isDeviceSupported;
6921 } finally {
6922 Binder.restoreCallingIdentity(identity);
6923 }
Hall Liu98187582018-01-22 19:15:32 -08006924 }
6925
Hall Liuf6668912018-10-31 17:05:23 -07006926 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006927 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6928 * RTT setting, will return true if the device and carrier both support RTT.
6929 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006930 */
6931 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006932 final long identity = Binder.clearCallingIdentity();
6933 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006934 boolean isRttSupported = isRttSupported(subscriptionId);
6935 boolean isUserRttSettingOn = Settings.Secure.getInt(
6936 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6937 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6938 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6939 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006940 } finally {
6941 Binder.restoreCallingIdentity(identity);
6942 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006943 }
6944
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006945 @Deprecated
6946 @Override
6947 public String getDeviceId(String callingPackage) {
6948 return getDeviceIdWithFeature(callingPackage, null);
6949 }
6950
Sanket Padawe7310cc72015-01-14 09:53:20 -08006951 /**
6952 * Returns the unique device ID of phone, for example, the IMEI for
6953 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6954 *
6955 * <p>Requires Permission:
6956 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6957 */
6958 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006959 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006960 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006961 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006962 return null;
6963 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006964 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006965 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006966 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006967 return null;
6968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969
6970 final long identity = Binder.clearCallingIdentity();
6971 try {
6972 return phone.getDeviceId();
6973 } finally {
6974 Binder.restoreCallingIdentity(identity);
6975 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006976 }
6977
Ping Sunc67b7c22016-03-02 19:16:45 +08006978 /**
6979 * {@hide}
6980 * Returns the IMS Registration Status on a particular subid
6981 *
6982 * @param subId
6983 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006984 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006985 Phone phone = getPhone(subId);
6986 if (phone != null) {
6987 return phone.isImsRegistered();
6988 } else {
6989 return false;
6990 }
6991 }
6992
Santos Cordon7a1885b2015-02-03 11:15:19 -08006993 @Override
6994 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 final long identity = Binder.clearCallingIdentity();
6996 try {
6997 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6998 } finally {
6999 Binder.restoreCallingIdentity(identity);
7000 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007001 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007002
Tyler Gunnf70ed162019-04-03 15:28:53 -07007003 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007004 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007005 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007007 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007008 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7009 }
7010 final long identity = Binder.clearCallingIdentity();
7011 try {
7012 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7013 } finally {
7014 Binder.restoreCallingIdentity(identity);
7015 }
7016 }
7017
7018 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007019 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007020 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7021 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007022 final long identity = Binder.clearCallingIdentity();
7023 try {
7024 Phone phone = getPhone(subscriptionId);
7025 if (phone == null) {
7026 return null;
7027 }
7028 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
7032 }
7033
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007034 /**
7035 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007036 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007037 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007038 final long identity = Binder.clearCallingIdentity();
7039 try {
7040 Phone phone = getPhone(subId);
7041 if (phone != null) {
7042 return phone.isWifiCallingEnabled();
7043 } else {
7044 return false;
7045 }
7046 } finally {
7047 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007048 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007049 }
7050
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007051 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007052 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007053 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007054 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 final long identity = Binder.clearCallingIdentity();
7056 try {
7057 Phone phone = getPhone(subId);
7058 if (phone != null) {
7059 return phone.isVideoEnabled();
7060 } else {
7061 return false;
7062 }
7063 } finally {
7064 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007065 }
7066 }
7067
7068 /**
7069 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7070 * defined in {@link ImsRegistrationImplBase}.
7071 */
7072 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 final long identity = Binder.clearCallingIdentity();
7074 try {
7075 Phone phone = getPhone(subId);
7076 if (phone != null) {
7077 return phone.getImsRegistrationTech();
7078 } else {
7079 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7080 }
7081 } finally {
7082 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007083 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007084 }
7085
Stuart Scott8eef64f2015-04-08 15:13:54 -07007086 @Override
7087 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007088 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007089 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7090 return;
7091 }
7092
Svet Ganovcc087f82015-05-12 20:35:54 -07007093 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007094
Svet Ganovcc087f82015-05-12 20:35:54 -07007095 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007096 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7097 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007098 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007099 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007100 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007101 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007102 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7103 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007104 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007105 // There has been issues when Sms raw table somehow stores orphan
7106 // fragments. They lead to garbled message when new fragments come
7107 // in and combined with those stale ones. In case this happens again,
7108 // user can reset all network settings which will clean up this table.
7109 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007110 // Clean up IMS settings as well here.
7111 int slotId = getSlotIndex(subId);
7112 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7113 ImsManager.getInstance(mApp, slotId).factoryReset();
7114 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007115
7116 // Erase modem config if erase modem on network setting is enabled.
7117 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7118 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7119 if (configValue != null && Boolean.parseBoolean(configValue)) {
7120 sendEraseModemConfig(getDefaultPhone());
7121 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007122 } finally {
7123 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007124 }
7125 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007126
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007127 private void cleanUpSmsRawTable(Context context) {
7128 ContentResolver resolver = context.getContentResolver();
7129 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7130 resolver.delete(uri, null, null);
7131 }
7132
Narayan Kamath1c496c22015-04-16 14:40:19 +01007133 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007134 public String getSimLocaleForSubscriber(int subId) {
7135 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7136 final Phone phone = getPhone(subId);
7137 if (phone == null) {
7138 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007139 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 final long identity = Binder.clearCallingIdentity();
7142 try {
chen xu5d3637b2019-01-21 23:31:38 -08007143 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007144 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007145 if (info == null) {
7146 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7147 return null;
7148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 // Try and fetch the locale from the carrier properties or from the SIM language
7150 // preferences (EF-PL and EF-LI)...
7151 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007152 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007153 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7154 if (localeFromDefaultSim != null) {
7155 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7156 if (DBG) log("Using locale from subId: " + subId + " locale: "
7157 + localeFromDefaultSim);
7158 return localeFromDefaultSim.toLanguageTag();
7159 } else {
7160 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 }
7162 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164 // The SIM language preferences only store a language (e.g. fr = French), not an
7165 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7166 // the SIM and carrier preferences does not include a country we add the country
7167 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007168 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007170 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 return mccLocale.toLanguageTag();
7172 }
7173
7174 if (DBG) log("No locale found - returning null");
7175 return null;
7176 } finally {
7177 Binder.restoreCallingIdentity(identity);
7178 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007179 }
7180
7181 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007182 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007183 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007184 }
7185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007186 /**
7187 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7188 */
7189 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007190 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007191 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007192 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007193
Chenjie Yu1ba97252018-01-11 18:16:20 -08007194 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007195 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007196
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007197 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007198 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7199 * representing the state of the modem.
7200 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007201 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7202 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007203 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007204 */
7205 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007206 public void requestModemActivityInfo(ResultReceiver result) {
7207 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209
7210 final long identity = Binder.clearCallingIdentity();
7211 try {
sqian1a1be542020-03-05 11:37:28 -08007212 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007213 } finally {
7214 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007215 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007216 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007217
Siddharth Rayb8114062018-06-17 15:02:38 -07007218 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7219 // less than total activity duration.
7220 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7221 if (info == null) {
7222 return false;
7223 }
7224 int activityDurationMs =
7225 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7226 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007227 int[] txTimeMs = info.getTransmitTimeMillis();
7228 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7229 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007230 }
7231 return (info.isValid()
7232 && (info.getSleepTimeMillis() <= activityDurationMs)
7233 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007234 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007235 && (totalTxTimeMs <= activityDurationMs));
7236 }
7237
Jack Yu85bd38a2015-11-09 11:34:32 -08007238 /**
7239 * {@hide}
7240 * Returns the service state information on specified subscription.
7241 */
7242 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007243 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7244 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007246 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007247 return null;
7248 }
7249
Hall Liuf19c44f2018-11-27 14:38:17 -08007250 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7251 LocationAccessPolicy.checkLocationPermission(mApp,
7252 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7253 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007254 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007255 .setCallingPid(Binder.getCallingPid())
7256 .setCallingUid(Binder.getCallingUid())
7257 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007258 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007259 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7260 .build());
7261
7262 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7263 LocationAccessPolicy.checkLocationPermission(mApp,
7264 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7265 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007266 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007267 .setCallingPid(Binder.getCallingPid())
7268 .setCallingUid(Binder.getCallingUid())
7269 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007270 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007271 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7272 .build());
7273 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7274 boolean hasFinePermission =
7275 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7276 boolean hasCoarsePermission =
7277 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007279 final long identity = Binder.clearCallingIdentity();
7280 try {
7281 final Phone phone = getPhone(subId);
7282 if (phone == null) {
7283 return null;
7284 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007285
Hall Liuf19c44f2018-11-27 14:38:17 -08007286 ServiceState ss = phone.getServiceState();
7287
7288 // Scrub out the location info in ServiceState depending on what level of access
7289 // the caller has.
7290 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007291 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7292 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007293 } finally {
7294 Binder.restoreCallingIdentity(identity);
7295 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007296 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007297
7298 /**
7299 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7300 *
7301 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7302 * voicemail ringtone.
7303 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7304 * PhoneAccount.
7305 */
7306 @Override
7307 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 final long identity = Binder.clearCallingIdentity();
7309 try {
7310 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7311 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007312 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7316 } finally {
7317 Binder.restoreCallingIdentity(identity);
7318 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007319 }
7320
7321 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007322 * Sets the per-account voicemail ringtone.
7323 *
7324 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7325 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7326 *
7327 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7328 * voicemail ringtone.
7329 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7330 * PhoneAccount.
7331 */
7332 @Override
7333 public void setVoicemailRingtoneUri(String callingPackage,
7334 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007335 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007336 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007337 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7338 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7340 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7341 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007343
7344 final long identity = Binder.clearCallingIdentity();
7345 try {
7346 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7347 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007348 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007349 }
7350 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7351 } finally {
7352 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007353 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007354 }
7355
7356 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007357 * Returns whether vibration is set for voicemail notification in Phone settings.
7358 *
7359 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7360 * voicemail vibration setting.
7361 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7362 */
7363 @Override
7364 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 final long identity = Binder.clearCallingIdentity();
7366 try {
7367 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7368 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007369 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7373 } finally {
7374 Binder.restoreCallingIdentity(identity);
7375 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007376 }
7377
Youhan Wange64578a2016-05-02 15:32:42 -07007378 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007379 * Sets the per-account voicemail vibration.
7380 *
7381 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7382 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7383 *
7384 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7385 * voicemail vibration setting.
7386 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7387 * specific PhoneAccount.
7388 */
7389 @Override
7390 public void setVoicemailVibrationEnabled(String callingPackage,
7391 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007392 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007394 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7395 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7397 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7398 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007399 }
7400
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007401 final long identity = Binder.clearCallingIdentity();
7402 try {
7403 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7404 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007405 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 }
7407 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7408 } finally {
7409 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007410 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007411 }
7412
7413 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007414 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7415 *
7416 * @throws SecurityException if the caller does not have the required permission
7417 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007418 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007419 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007420 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007421 }
7422
7423 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007424 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7425 * permission.
7426 *
7427 * @throws SecurityException if the caller does not have the required permission
7428 */
7429 private void enforceSendSmsPermission() {
7430 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7431 }
7432
7433 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007434 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007435 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007436 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007437 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007438 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 final long identity = Binder.clearCallingIdentity();
7440 try {
7441 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007442 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 if (componentName == null) {
7444 throw new SecurityException(
7445 "Caller not current active visual voicemail package[null]");
7446 }
7447 String vvmPackage = componentName.getPackageName();
7448 if (!callingPackage.equals(vvmPackage)) {
7449 throw new SecurityException("Caller not current active visual voicemail package["
7450 + vvmPackage + "]");
7451 }
7452 } finally {
7453 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007454 }
7455 }
7456
7457 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007458 * Return the application ID for the app type.
7459 *
7460 * @param subId the subscription ID that this request applies to.
7461 * @param appType the uicc app type.
7462 * @return Application ID for specificied app type, or null if no uicc.
7463 */
7464 @Override
7465 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007466 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007467 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468
7469 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007470 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471 if (phone == null) {
7472 return null;
7473 }
7474 String aid = null;
7475 try {
7476 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7477 .getApplicationByType(appType).getAid();
7478 } catch (Exception e) {
7479 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7480 }
7481 return aid;
7482 } finally {
7483 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007484 }
Youhan Wange64578a2016-05-02 15:32:42 -07007485 }
7486
Youhan Wang4001d252016-05-11 10:29:41 -07007487 /**
7488 * Return the Electronic Serial Number.
7489 *
7490 * @param subId the subscription ID that this request applies to.
7491 * @return ESN or null if error.
7492 */
7493 @Override
7494 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007495 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007496 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497
7498 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007499 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 if (phone == null) {
7501 return null;
7502 }
7503 String esn = null;
7504 try {
7505 esn = phone.getEsn();
7506 } catch (Exception e) {
7507 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7508 }
7509 return esn;
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007512 }
Youhan Wang4001d252016-05-11 10:29:41 -07007513 }
7514
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007515 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007516 * Return the Preferred Roaming List Version.
7517 *
7518 * @param subId the subscription ID that this request applies to.
7519 * @return PRLVersion or null if error.
7520 */
7521 @Override
7522 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007523 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007524 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525
7526 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007527 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 if (phone == null) {
7529 return null;
7530 }
7531 String cdmaPrlVersion = null;
7532 try {
7533 cdmaPrlVersion = phone.getCdmaPrlVersion();
7534 } catch (Exception e) {
7535 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7536 }
7537 return cdmaPrlVersion;
7538 } finally {
7539 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007540 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007541 }
7542
7543 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007544 * Get snapshot of Telephony histograms
7545 * @return List of Telephony histograms
7546 * @hide
7547 */
7548 @Override
7549 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7551 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552
7553 final long identity = Binder.clearCallingIdentity();
7554 try {
7555 return RIL.getTelephonyRILTimingHistograms();
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
7558 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007559 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007560
7561 /**
7562 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007563 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7564 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007565 * Require system privileges. In the future we may add this to carrier APIs.
7566 *
Michele Berionne482f8202018-11-27 18:57:59 -08007567 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007568 */
7569 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007570 @TelephonyManager.SetCarrierRestrictionResult
7571 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007572 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007573 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007574
Michele Berionne482f8202018-11-27 18:57:59 -08007575 if (carrierRestrictionRules == null) {
7576 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007577 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 final long identity = Binder.clearCallingIdentity();
7580 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007581 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007582 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 } finally {
7584 Binder.restoreCallingIdentity(identity);
7585 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007586 }
7587
7588 /**
7589 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007590 * Get the allowed carrier list and the excluded carrier list, including the priority between
7591 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007592 * Require system privileges. In the future we may add this to carrier APIs.
7593 *
Michele Berionne482f8202018-11-27 18:57:59 -08007594 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007595 */
7596 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007597 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007598 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007599 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600
7601 final long identity = Binder.clearCallingIdentity();
7602 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007603 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7604 if (response instanceof CarrierRestrictionRules) {
7605 return (CarrierRestrictionRules) response;
7606 }
7607 // Response is an Exception of some kind,
7608 // which is signalled to the user as a NULL retval
7609 return null;
7610 } catch (Exception e) {
7611 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7612 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007616 }
7617
fionaxu59545b42016-05-25 15:53:37 -07007618 /**
fionaxu59545b42016-05-25 15:53:37 -07007619 * Action set from carrier signalling broadcast receivers to enable/disable radio
7620 * @param subId the subscription ID that this action applies to.
7621 * @param enabled control enable or disable radio.
7622 * {@hide}
7623 */
7624 @Override
7625 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7626 enforceModifyPermission();
7627 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007628
7629 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007630 if (phone == null) {
7631 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7632 return;
7633 }
7634 try {
7635 phone.carrierActionSetRadioEnabled(enabled);
7636 } catch (Exception e) {
7637 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007638 } finally {
7639 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007640 }
7641 }
7642
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007643 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007644 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7645 * network status based on which carrier apps could apply actions accordingly,
7646 * enable/disable default url handler for example.
7647 *
7648 * @param subId the subscription ID that this action applies to.
7649 * @param report control start/stop reporting the default network status.
7650 * {@hide}
7651 */
7652 @Override
7653 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7654 enforceModifyPermission();
7655 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656
7657 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007658 if (phone == null) {
7659 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7660 return;
7661 }
7662 try {
7663 phone.carrierActionReportDefaultNetworkStatus(report);
7664 } catch (Exception e) {
7665 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 } finally {
7667 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007668 }
7669 }
7670
7671 /**
fionaxud9622282017-07-17 17:51:30 -07007672 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7673 * @param subId the subscription ID that this action applies to.
7674 * {@hide}
7675 */
7676 @Override
7677 public void carrierActionResetAll(int subId) {
7678 enforceModifyPermission();
7679 final Phone phone = getPhone(subId);
7680 if (phone == null) {
7681 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7682 return;
7683 }
7684 try {
7685 phone.carrierActionResetAll();
7686 } catch (Exception e) {
7687 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7688 }
7689 }
7690
7691 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007692 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7693 * bug report is being generated.
7694 */
7695 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007696 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007697 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7698 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007699 writer.println("Permission Denial: can't dump Phone from pid="
7700 + Binder.getCallingPid()
7701 + ", uid=" + Binder.getCallingUid()
7702 + "without permission "
7703 + android.Manifest.permission.DUMP);
7704 return;
7705 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007706 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007707 }
Jack Yueb89b242016-06-22 13:27:47 -07007708
Brad Ebingerdac2f002018-04-03 15:17:52 -07007709 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007710 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7711 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7712 @NonNull String[] args) {
7713 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7714 this, in.getFileDescriptor(), out.getFileDescriptor(),
7715 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007716 }
7717
Jack Yueb89b242016-06-22 13:27:47 -07007718 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007719 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007720 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007721 * @param reason the reason the data enable change is taking place
7722 * @param enabled True if enabling the data, otherwise disabling.
7723 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007724 */
7725 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007726 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007727 boolean enabled) {
7728 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7729 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7730 try {
7731 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007732 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007733 } catch (SecurityException se) {
7734 enforceModifyPermission();
7735 }
7736 } else {
7737 enforceModifyPermission();
7738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739
7740 final long identity = Binder.clearCallingIdentity();
7741 try {
7742 Phone phone = getPhone(subId);
7743 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007744 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7745 phone.carrierActionSetMeteredApnsEnabled(enabled);
7746 } else {
7747 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007749 }
7750 } finally {
7751 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007752 }
7753 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007754
7755 /**
7756 * Get Client request stats
7757 * @return List of Client Request Stats
7758 * @hide
7759 */
7760 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007761 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7762 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007764 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007765 return null;
7766 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007767 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 final long identity = Binder.clearCallingIdentity();
7770 try {
7771 if (phone != null) {
7772 return phone.getClientRequestStats();
7773 }
7774
7775 return null;
7776 } finally {
7777 Binder.restoreCallingIdentity(identity);
7778 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007779 }
7780
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007781 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007782 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007783 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007784 }
Jack Yueb4124c2017-02-16 15:32:43 -08007785
7786 /**
Grace Chen70990072017-03-24 17:21:30 -07007787 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007788 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007789 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007790 * @param state State of SIM (power down, power up, pass through)
7791 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7792 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7793 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007794 *
7795 **/
7796 @Override
Grace Chen70990072017-03-24 17:21:30 -07007797 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007798 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007799 Phone phone = PhoneFactory.getPhone(slotIndex);
7800
vagdeviaf9a5b92018-08-15 16:01:53 -07007801 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7802
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 final long identity = Binder.clearCallingIdentity();
7804 try {
7805 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007806 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007807 }
7808 } finally {
7809 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007810 }
7811 }
Shuo Qiandd210312017-04-12 22:11:33 +00007812
Tyler Gunn65d45c22017-06-05 11:22:26 -07007813 private boolean isUssdApiAllowed(int subId) {
7814 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007815 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007816 if (configManager == null) {
7817 return false;
7818 }
7819 PersistableBundle pb = configManager.getConfigForSubId(subId);
7820 if (pb == null) {
7821 return false;
7822 }
7823 return pb.getBoolean(
7824 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7825 }
7826
Shuo Qiandd210312017-04-12 22:11:33 +00007827 /**
7828 * Check if phone is in emergency callback mode
7829 * @return true if phone is in emergency callback mode
7830 * @param subId sub id
7831 */
goneil9c5f4872017-12-05 14:07:56 -08007832 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007833 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007834 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007835 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836
7837 final long identity = Binder.clearCallingIdentity();
7838 try {
7839 if (phone != null) {
7840 return phone.isInEcm();
7841 } else {
7842 return false;
7843 }
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007846 }
7847 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007848
7849 /**
7850 * Get the current signal strength information for the given subscription.
7851 * Because this information is not updated when the device is in a low power state
7852 * it should not be relied-upon to be current.
7853 * @param subId Subscription index
7854 * @return the most recent cached signal strength info from the modem
7855 */
7856 @Override
7857 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858 final long identity = Binder.clearCallingIdentity();
7859 try {
7860 Phone p = getPhone(subId);
7861 if (p == null) {
7862 return null;
7863 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865 return p.getSignalStrength();
7866 } finally {
7867 Binder.restoreCallingIdentity(identity);
7868 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007869 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007870
Pengquan Meng77b7f132018-08-22 14:49:57 -07007871 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007872 * Get the current modem radio state for the given slot.
7873 * @param slotIndex slot index.
7874 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007875 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007876 * @return the current radio power state from the modem
7877 */
7878 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007879 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007880 Phone phone = PhoneFactory.getPhone(slotIndex);
7881 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007882 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7883 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007884 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7885 }
7886
7887 final long identity = Binder.clearCallingIdentity();
7888 try {
7889 return phone.getRadioPowerState();
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
7892 }
7893 }
7894 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7895 }
7896
7897 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007898 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7899 *
7900 * <p>Requires one of the following permissions:
7901 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7902 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7903 * privileges.
7904 *
7905 * @param subId subscription id
7906 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7907 * {@code false}.
7908 */
7909 @Override
7910 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007911 try {
7912 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7913 null);
7914 } catch (Exception e) {
7915 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7916 mApp, subId, "isDataRoamingEnabled");
7917 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007918
Pengquan Menga1bb6272018-09-06 09:59:22 -07007919 boolean isEnabled = false;
7920 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007921 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007922 Phone phone = getPhone(subId);
7923 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007924 } finally {
7925 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007926 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007927 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007928 }
7929
7930
7931 /**
7932 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7933 *
7934 * <p> Requires permission:
7935 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7936 * privileges.
7937 *
7938 * @param subId subscription id
7939 * @param isEnabled {@code true} means enable, {@code false} means disable.
7940 */
7941 @Override
7942 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7944 mApp, subId, "setDataRoamingEnabled");
7945
Pengquan Menga1bb6272018-09-06 09:59:22 -07007946 final long identity = Binder.clearCallingIdentity();
7947 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007948 Phone phone = getPhone(subId);
7949 if (phone != null) {
7950 phone.setDataRoamingEnabled(isEnabled);
7951 }
7952 } finally {
7953 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007954 }
7955 }
7956
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007957 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007958 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007959 TelephonyPermissions
7960 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007961 mApp, subId, "isManualNetworkSelectionAllowed");
7962
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007963 boolean isAllowed = true;
7964 final long identity = Binder.clearCallingIdentity();
7965 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007966 Phone phone = getPhone(subId);
7967 if (phone != null) {
7968 isAllowed = phone.isCspPlmnEnabled();
7969 }
7970 } finally {
7971 Binder.restoreCallingIdentity(identity);
7972 }
7973 return isAllowed;
7974 }
7975
7976 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007977 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007978 // Verify that tha callingPackage belongs to the calling UID
7979 mApp.getSystemService(AppOpsManager.class)
7980 .checkPackage(Binder.getCallingUid(), callingPackage);
7981
Jordan Liu1e142fc2019-04-22 15:10:43 -07007982 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007983 try {
7984 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007985 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007986 } catch (SecurityException e) {
7987 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7988 // has carrier privileges on an active UICC
7989 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7990 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007991 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007992 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007993 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007994
7995 final long identity = Binder.clearCallingIdentity();
7996 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007997 UiccController uiccController = UiccController.getInstance();
7998 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007999 if (hasReadPermission) {
8000 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008001 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008002
8003 // Remove private info if the caller doesn't have access
8004 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8005 for (UiccCardInfo cardInfo : cardInfos) {
8006 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8007 // is available
8008 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8009 if (card == null || card.getUiccProfile() == null) {
8010 // assume no access if the card or profile is unavailable
8011 filteredInfos.add(cardInfo.getUnprivileged());
8012 continue;
8013 }
8014 UiccProfile profile = card.getUiccProfile();
8015 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8016 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8017 filteredInfos.add(cardInfo);
8018 } else {
8019 filteredInfos.add(cardInfo.getUnprivileged());
8020 }
8021 }
8022 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008023 } finally {
8024 Binder.restoreCallingIdentity(identity);
8025 }
8026 }
8027
8028 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008029 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008030 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008031
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032 final long identity = Binder.clearCallingIdentity();
8033 try {
8034 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8035 if (slots == null) {
8036 Rlog.i(LOG_TAG, "slots is null.");
8037 return null;
8038 }
8039
8040 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8041 for (int i = 0; i < slots.length; i++) {
8042 UiccSlot slot = slots[i];
8043 if (slot == null) {
8044 continue;
8045 }
8046
Jordan Liu7be7e652019-05-06 18:55:02 +00008047 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008048 UiccCard card = slot.getUiccCard();
8049 if (card != null) {
8050 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008051 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008052 cardId = slot.getEid();
8053 if (TextUtils.isEmpty(cardId)) {
8054 cardId = slot.getIccId();
8055 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 }
8057
Jordan Liu857451f2019-05-09 16:35:35 -07008058 if (cardId != null) {
8059 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8060 // if cardId is an EID, it's all digits so this is fine
8061 cardId = IccUtils.stripTrailingFs(cardId);
8062 }
8063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008064 int cardState = 0;
8065 switch (slot.getCardState()) {
8066 case CARDSTATE_ABSENT:
8067 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8068 break;
8069 case CARDSTATE_PRESENT:
8070 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8071 break;
8072 case CARDSTATE_ERROR:
8073 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8074 break;
8075 case CARDSTATE_RESTRICTED:
8076 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8077 break;
8078 default:
8079 break;
8080
8081 }
8082
8083 infos[i] = new UiccSlotInfo(
8084 slot.isActive(),
8085 slot.isEuicc(),
8086 cardId,
8087 cardState,
8088 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008089 slot.isExtendedApduSupported(),
8090 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091 }
8092 return infos;
8093 } finally {
8094 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008095 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008096 }
8097
8098 @Override
8099 public boolean switchSlots(int[] physicalSlots) {
8100 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008101
8102 final long identity = Binder.clearCallingIdentity();
8103 try {
8104 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8105 } finally {
8106 Binder.restoreCallingIdentity(identity);
8107 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008108 }
Jack Yu4c988042018-02-27 15:30:01 -08008109
8110 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008111 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008112 final long identity = Binder.clearCallingIdentity();
8113 try {
8114 return UiccController.getInstance().getCardIdForDefaultEuicc();
8115 } finally {
8116 Binder.restoreCallingIdentity(identity);
8117 }
8118 }
8119
Pengquan Meng85728fb2018-03-12 16:31:21 -07008120 /**
goneil47ffb6e2018-04-06 15:40:58 -07008121 * A test API to reload the UICC profile.
8122 *
8123 * <p>Requires that the calling app has permission
8124 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8125 * @hide
8126 */
8127 @Override
8128 public void refreshUiccProfile(int subId) {
8129 enforceModifyPermission();
8130
8131 final long identity = Binder.clearCallingIdentity();
8132 try {
8133 Phone phone = getPhone(subId);
8134 if (phone == null) {
8135 return;
8136 }
8137 UiccCard uiccCard = phone.getUiccCard();
8138 if (uiccCard == null) {
8139 return;
8140 }
8141 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8142 if (uiccProfile == null) {
8143 return;
8144 }
8145 uiccProfile.refresh();
8146 } finally {
8147 Binder.restoreCallingIdentity(identity);
8148 }
8149 }
8150
8151 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008152 * Returns false if the mobile data is disabled by default, otherwise return true.
8153 */
8154 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008155 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008156 }
8157
8158 /**
8159 * Returns true if the data roaming is enabled by default, i.e the system property
8160 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8161 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8162 */
8163 private boolean getDefaultDataRoamingEnabled(int subId) {
8164 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008165 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008166 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008167 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8168 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8169 return isDataRoamingEnabled;
8170 }
8171
8172 /**
8173 * Returns the default network type for the given {@code subId}, if the default network type is
8174 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8175 */
8176 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008177 List<Integer> list = TelephonyProperties.default_network();
8178 int phoneId = mSubscriptionController.getPhoneId(subId);
8179 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8180 return list.get(phoneId);
8181 }
8182 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008183 }
fionaxua13278b2018-03-21 00:08:13 -07008184
8185 @Override
8186 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008187 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008188 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189
8190 final long identity = Binder.clearCallingIdentity();
8191 try {
8192 final Phone phone = getPhone(subId);
8193 if (phone == null) {
8194 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8195 return;
8196 }
chen xueaba88a2019-03-15 13:15:10 -07008197 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8198 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008199 if (carrierPrivilegeRules == null) {
8200 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8201 } else {
8202 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008204 } finally {
8205 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008206 }
fionaxua13278b2018-03-21 00:08:13 -07008207 }
8208
8209 @Override
8210 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008211 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212
8213 final long identity = Binder.clearCallingIdentity();
8214 try {
8215 final Phone phone = getPhone(subId);
8216 if (phone == null) {
8217 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8218 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8219 }
8220 return phone.getCarrierIdListVersion();
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008223 }
fionaxua13278b2018-03-21 00:08:13 -07008224 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008225
8226 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008227 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8228 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008230 mApp, subId, callingPackage, callingFeatureId,
8231 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008232 return -1;
8233 }
8234
8235 final long identity = Binder.clearCallingIdentity();
8236 try {
8237 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8238 } finally {
8239 Binder.restoreCallingIdentity(identity);
8240 }
8241 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008242
8243 @Override
8244 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008245 TelephonyPermissions
8246 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008247 mApp, subId, "getCdmaRoamingMode");
8248
8249 final long identity = Binder.clearCallingIdentity();
8250 try {
8251 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8252 } finally {
8253 Binder.restoreCallingIdentity(identity);
8254 }
8255 }
8256
8257 @Override
8258 public boolean setCdmaRoamingMode(int subId, int mode) {
8259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8260 mApp, subId, "setCdmaRoamingMode");
8261
8262 final long identity = Binder.clearCallingIdentity();
8263 try {
8264 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8265 } finally {
8266 Binder.restoreCallingIdentity(identity);
8267 }
8268 }
8269
8270 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008271 public int getCdmaSubscriptionMode(int subId) {
8272 TelephonyPermissions
8273 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8274 mApp, subId, "getCdmaSubscriptionMode");
8275
8276 final long identity = Binder.clearCallingIdentity();
8277 try {
8278 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
8282 }
8283
8284 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008285 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8287 mApp, subId, "setCdmaSubscriptionMode");
8288
8289 final long identity = Binder.clearCallingIdentity();
8290 try {
8291 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8292 } finally {
8293 Binder.restoreCallingIdentity(identity);
8294 }
8295 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008296
sqianc5eccab2018-10-19 18:46:41 -07008297 @Override
sqian8c685422019-02-22 15:55:18 -08008298 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008299 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008301 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8302 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008303 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8304 }
8305 final long identity = Binder.clearCallingIdentity();
8306 try {
sqian854d44b2018-12-12 16:48:18 -08008307 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8308 for (Phone phone: PhoneFactory.getPhones()) {
8309 if (phone.getEmergencyNumberTracker() != null
8310 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8311 emergencyNumberListInternal.put(
8312 phone.getSubId(),
8313 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8314 }
sqian11b7a0e2018-12-05 18:48:28 -08008315 }
sqian854d44b2018-12-12 16:48:18 -08008316 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
sqianc5eccab2018-10-19 18:46:41 -07008320 }
8321
8322 @Override
sqian8c685422019-02-22 15:55:18 -08008323 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008324 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008325 if (!exactMatch) {
8326 TelephonyPermissions
8327 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008328 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008329 }
8330 final long identity = Binder.clearCallingIdentity();
8331 try {
sqian854d44b2018-12-12 16:48:18 -08008332 for (Phone phone: PhoneFactory.getPhones()) {
8333 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008334 && phone.getEmergencyNumberTracker()
8335 .isEmergencyNumber(number, exactMatch)) {
8336 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008337 }
sqian11b7a0e2018-12-05 18:48:28 -08008338 }
8339 return false;
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
8342 }
8343 }
8344
sqianf4ca7ed2019-01-15 18:32:07 -08008345 /**
8346 * Update emergency number list for test mode.
8347 */
8348 @Override
8349 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8350 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8351 "updateEmergencyNumberListTestMode");
8352
8353 final long identity = Binder.clearCallingIdentity();
8354 try {
8355 for (Phone phone: PhoneFactory.getPhones()) {
8356 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8357 if (tracker != null) {
8358 tracker.executeEmergencyNumberTestModeCommand(action, num);
8359 }
8360 }
8361 } finally {
8362 Binder.restoreCallingIdentity(identity);
8363 }
8364 }
8365
8366 /**
8367 * Get the full emergency number list for test mode.
8368 */
8369 @Override
8370 public List<String> getEmergencyNumberListTestMode() {
8371 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8372 "getEmergencyNumberListTestMode");
8373
8374 final long identity = Binder.clearCallingIdentity();
8375 try {
8376 Set<String> emergencyNumbers = new HashSet<>();
8377 for (Phone phone: PhoneFactory.getPhones()) {
8378 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8379 if (tracker != null) {
8380 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8381 emergencyNumbers.add(num.getNumber());
8382 }
8383 }
8384 }
8385 return new ArrayList<>(emergencyNumbers);
8386 } finally {
8387 Binder.restoreCallingIdentity(identity);
8388 }
8389 }
8390
chen xud6b45bd2018-10-30 22:27:10 -07008391 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008392 public int getEmergencyNumberDbVersion(int subId) {
8393 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8394
8395 final long identity = Binder.clearCallingIdentity();
8396 try {
8397 final Phone phone = getPhone(subId);
8398 if (phone == null) {
8399 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8400 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8401 }
8402 return phone.getEmergencyNumberDbVersion();
8403 } finally {
8404 Binder.restoreCallingIdentity(identity);
8405 }
8406 }
8407
8408 @Override
8409 public void notifyOtaEmergencyNumberDbInstalled() {
8410 enforceModifyPermission();
8411
8412 final long identity = Binder.clearCallingIdentity();
8413 try {
8414 for (Phone phone: PhoneFactory.getPhones()) {
8415 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8416 if (tracker != null) {
8417 tracker.updateOtaEmergencyNumberDatabase();
8418 }
8419 }
8420 } finally {
8421 Binder.restoreCallingIdentity(identity);
8422 }
8423 }
8424
8425 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008426 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008427 enforceActiveEmergencySessionPermission();
8428
8429 final long identity = Binder.clearCallingIdentity();
8430 try {
8431 for (Phone phone: PhoneFactory.getPhones()) {
8432 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8433 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008434 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8435 }
8436 }
8437 } finally {
8438 Binder.restoreCallingIdentity(identity);
8439 }
8440 }
8441
8442 @Override
8443 public void resetOtaEmergencyNumberDbFilePath() {
8444 enforceActiveEmergencySessionPermission();
8445
8446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 for (Phone phone: PhoneFactory.getPhones()) {
8449 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8450 if (tracker != null) {
8451 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008452 }
8453 }
8454 } finally {
8455 Binder.restoreCallingIdentity(identity);
8456 }
8457 }
8458
8459 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008460 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8461 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8462 Phone phone = getPhone(subId);
8463 if (phone == null) {
8464 return null;
8465 }
8466 final long identity = Binder.clearCallingIdentity();
8467 try {
8468 UiccProfile profile = UiccController.getInstance()
8469 .getUiccProfileForPhone(phone.getPhoneId());
8470 if (profile != null) {
8471 return profile.getCertsFromCarrierPrivilegeAccessRules();
8472 }
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
8475 }
8476 return null;
8477 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008478
8479 /**
8480 * Enable or disable a modem stack.
8481 */
8482 @Override
8483 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8484 enforceModifyPermission();
8485
8486 final long identity = Binder.clearCallingIdentity();
8487 try {
8488 Phone phone = PhoneFactory.getPhone(slotIndex);
8489 if (phone == null) {
8490 return false;
8491 } else {
8492 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8493 }
8494 } finally {
8495 Binder.restoreCallingIdentity(identity);
8496 }
8497 }
Michelecea4cf22018-12-21 15:00:11 -08008498
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008499 /**
8500 * Whether a modem stack is enabled or not.
8501 */
8502 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008503 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8504 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008505 Phone phone = PhoneFactory.getPhone(slotIndex);
8506 if (phone == null) return false;
8507
8508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008509 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8510 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008511 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8512 }
8513
8514 final long identity = Binder.clearCallingIdentity();
8515 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008516 try {
8517 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8518 } catch (NoSuchElementException ex) {
8519 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8520 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008521 } finally {
8522 Binder.restoreCallingIdentity(identity);
8523 }
8524 }
8525
Michelecea4cf22018-12-21 15:00:11 -08008526 @Override
Michele0ea7d782019-03-19 14:58:42 -07008527 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008528 enforceModifyPermission();
8529
8530 final long identity = Binder.clearCallingIdentity();
8531 try {
8532 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008533 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008534 .commit();
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
8537 }
8538 }
8539
8540 @Override
Michele0ea7d782019-03-19 14:58:42 -07008541 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008542 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008544 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8545 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008546 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008547 }
Michelecea4cf22018-12-21 15:00:11 -08008548
8549 final long identity = Binder.clearCallingIdentity();
8550 try {
Michele0ea7d782019-03-19 14:58:42 -07008551 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008552 } finally {
8553 Binder.restoreCallingIdentity(identity);
8554 }
8555 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008556
Michele0ea7d782019-03-19 14:58:42 -07008557 @TelephonyManager.IsMultiSimSupportedResult
8558 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008559 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8560 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8561 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008562 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8563 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008564 }
8565 // Check if the hardware supports multisim functionality. If usage of multisim is not
8566 // supported by the modem, indicate that it is restricted.
8567 PhoneCapability staticCapability =
8568 mPhoneConfigurationManager.getStaticPhoneCapability();
8569 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008570 loge("isMultiSimSupportedInternal: no static configuration available");
8571 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008572 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008573 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008574 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8575 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008576 }
8577 // Check if support of multiple SIMs is restricted by carrier
8578 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008579 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008580 }
8581
Michele0ea7d782019-03-19 14:58:42 -07008582 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008583 }
8584
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008585 /**
8586 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008587 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8588 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8589 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008590 * @param numOfSims number of active sims we want to switch to
8591 */
8592 @Override
8593 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008594 if (numOfSims == 1) {
8595 enforceModifyPermission();
8596 } else {
8597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8598 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8599 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008600 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008601
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008602 try {
Michele30b57b22019-03-01 12:01:14 -08008603 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008604 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008605 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8606 return;
8607 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008608 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8609 } finally {
8610 Binder.restoreCallingIdentity(identity);
8611 }
8612 }
8613
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008614 @Override
8615 public boolean isApplicationOnUicc(int subId, int appType) {
8616 enforceReadPrivilegedPermission("isApplicationOnUicc");
8617 Phone phone = getPhone(subId);
8618 if (phone == null) {
8619 return false;
8620 }
8621 final long identity = Binder.clearCallingIdentity();
8622 try {
8623 UiccCard uiccCard = phone.getUiccCard();
8624 if (uiccCard == null) {
8625 return false;
8626 }
8627 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8628 if (uiccProfile == null) {
8629 return false;
8630 }
8631 if (TelephonyManager.APPTYPE_SIM <= appType
8632 && appType <= TelephonyManager.APPTYPE_ISIM) {
8633 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8634 }
8635 return false;
8636 } finally {
8637 Binder.restoreCallingIdentity(identity);
8638 }
8639 }
8640
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008641 /**
chen xub4baa772019-04-03 10:23:41 -07008642 * Get whether making changes to modem configurations will trigger reboot.
8643 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008644 */
8645 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008646 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8647 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008649 mApp, subId, callingPackage, callingFeatureId,
8650 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008651 return false;
8652 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008653 final long identity = Binder.clearCallingIdentity();
8654 try {
8655 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8656 } finally {
8657 Binder.restoreCallingIdentity(identity);
8658 }
8659 }
8660
Nathan Harold29f5f052019-02-15 13:41:57 -08008661 private void updateModemStateMetrics() {
8662 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8663 // TODO: check the state for each modem if the api is ready.
8664 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8665 }
8666
Pengquan Meng3889a572019-01-23 11:16:29 -08008667 @Override
8668 public int[] getSlotsMapping() {
8669 enforceReadPrivilegedPermission("getSlotsMapping");
8670
8671 final long identity = Binder.clearCallingIdentity();
8672 try {
8673 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8674 // All logical slots should have a mapping to a physical slot.
8675 int[] logicalSlotsMapping = new int[phoneCount];
8676 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8677 for (int i = 0; i < slotInfos.length; i++) {
8678 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8679 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8680 }
8681 }
8682 return logicalSlotsMapping;
8683 } finally {
8684 Binder.restoreCallingIdentity(identity);
8685 }
8686 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008687
8688 /**
8689 * Get the IRadio HAL Version
8690 */
8691 @Override
8692 public int getRadioHalVersion() {
8693 Phone phone = getDefaultPhone();
8694 if (phone == null) return -1;
8695 HalVersion hv = phone.getHalVersion();
8696 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8697 return hv.major * 100 + hv.minor;
8698 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008699
8700 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008701 * Get the current calling package name.
8702 * @return the current calling package name
8703 */
8704 @Override
8705 public String getCurrentPackageName() {
8706 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8707 }
8708
8709 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008710 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8711 * corresponding network requests on a subId.
8712 *
8713 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008714 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008715 * 2) APN is un-metered for this subscription, or
8716 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008717 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008718 *
8719 * @return whether data is allowed for a apn type.
8720 *
8721 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008722 */
8723 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008724 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008725 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8726 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008727
8728 // Now that all security checks passes, perform the operation as ourselves.
8729 final long identity = Binder.clearCallingIdentity();
8730 try {
8731 Phone phone = getPhone(subId);
8732 if (phone == null) return false;
8733
Jack Yu41407ee2019-05-13 16:54:09 -07008734 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008735 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8736 } finally {
8737 Binder.restoreCallingIdentity(identity);
8738 }
8739 }
8740
8741 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008742 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008743 enforceReadPrivilegedPermission("isApnMetered");
8744
8745 // Now that all security checks passes, perform the operation as ourselves.
8746 final long identity = Binder.clearCallingIdentity();
8747 try {
8748 Phone phone = getPhone(subId);
8749 if (phone == null) return true; // By default return true.
8750
Jack Yu41407ee2019-05-13 16:54:09 -07008751 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008752 } finally {
8753 Binder.restoreCallingIdentity(identity);
8754 }
8755 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008756
8757 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008758 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8759 int subscriptionId, IBooleanConsumer resultCallback) {
8760 enforceModifyPermission();
8761 long token = Binder.clearCallingIdentity();
8762 try {
8763 Phone phone = getPhone(subscriptionId);
8764 if (phone == null) {
8765 try {
8766 if (resultCallback != null) {
8767 resultCallback.accept(false);
8768 }
8769 } catch (RemoteException e) {
8770 // ignore
8771 }
8772 return;
8773 }
8774 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8775 Pair.create(specifiers, (x) -> {
8776 try {
8777 if (resultCallback != null) {
8778 resultCallback.accept(x);
8779 }
8780 } catch (RemoteException e) {
8781 // ignore
8782 }
8783 });
8784 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8785 } finally {
8786 Binder.restoreCallingIdentity(token);
8787 }
8788 }
8789
8790 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008791 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8792 TelephonyPermissions
8793 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8794 mApp, subId, "getSystemSelectionChannels");
8795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8796 final long identity = Binder.clearCallingIdentity();
8797 try {
8798 List<RadioAccessSpecifier> specifiers =
8799 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8800 null, subId, workSource);
8801 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8802 return specifiers;
8803 } finally {
8804 Binder.restoreCallingIdentity(identity);
8805 }
8806 }
8807
8808 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008809 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008810 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008811 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8812 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8813 if (iccRecords == null) {
8814 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8815 return false;
8816 }
8817 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8818 }
8819
8820 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008821 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8822 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008823 if (callingPackage == null) {
8824 callingPackage = getCurrentPackageName();
8825 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008826 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8827 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008828 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8829 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008830 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8831 }
8832 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8833 Intent intent = new Intent();
8834 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8835 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8836 // Bring up choose default SMS subscription dialog right now
8837 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8838 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8839 mApp.startActivity(intent);
8840 }
chen xud5ca2d52019-05-28 15:20:57 -07008841
8842 @Override
8843 public String getMmsUAProfUrl(int subId) {
8844 //TODO investigate if this API should require proper permission check in R b/133791609
8845 final long identity = Binder.clearCallingIdentity();
8846 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008847 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8848 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8849 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8850 return carrierUAProfUrl;
8851 }
chen xud5ca2d52019-05-28 15:20:57 -07008852 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8853 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8854 } finally {
8855 Binder.restoreCallingIdentity(identity);
8856 }
8857 }
8858
8859 @Override
8860 public String getMmsUserAgent(int subId) {
8861 //TODO investigate if this API should require proper permission check in R b/133791609
8862 final long identity = Binder.clearCallingIdentity();
8863 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008864 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8865 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8866 if (!TextUtils.isEmpty(carrierUserAgent)) {
8867 return carrierUserAgent;
8868 }
chen xud5ca2d52019-05-28 15:20:57 -07008869 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8870 .getString(com.android.internal.R.string.config_mms_user_agent);
8871 } finally {
8872 Binder.restoreCallingIdentity(identity);
8873 }
8874 }
Jack Yub07d4972019-05-28 16:12:25 -07008875
8876 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008877 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8878 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8879
8880 final long identity = Binder.clearCallingIdentity();
8881 try {
8882 Phone phone = getPhone(subscriptionId);
8883 if (phone == null) return false;
8884
8885 switch (policy) {
8886 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8887 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8888 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8889 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8890 default:
8891 throw new IllegalArgumentException(policy + " is not a valid policy");
8892 }
8893 } finally {
8894 Binder.restoreCallingIdentity(identity);
8895 }
8896 }
8897
8898 @Override
8899 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8900 boolean enabled) {
8901 enforceModifyPermission();
8902
8903 final long identity = Binder.clearCallingIdentity();
8904 try {
8905 Phone phone = getPhone(subscriptionId);
8906 if (phone == null) return;
8907
8908 switch (policy) {
8909 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8910 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8911 break;
8912 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8913 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8914 break;
8915 default:
8916 throw new IllegalArgumentException(policy + " is not a valid policy");
8917 }
8918 } finally {
8919 Binder.restoreCallingIdentity(identity);
8920 }
8921 }
8922
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008923 /**
Hall Liub48cf452020-09-25 11:13:49 -07008924 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008925 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8926 * otherwise.
8927 */
8928 @Override
8929 public void setCepEnabled(boolean isCepEnabled) {
8930 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8931
8932 final long identity = Binder.clearCallingIdentity();
8933 try {
8934 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8935 for (Phone phone : PhoneFactory.getPhones()) {
8936 Phone defaultPhone = phone.getImsPhone();
8937 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8938 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8939 ImsPhoneCallTracker imsPhoneCallTracker =
8940 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8941 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8942 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8943 + imsPhone.getMsisdn());
8944 }
8945 }
8946 } finally {
8947 Binder.restoreCallingIdentity(identity);
8948 }
8949 }
allenwtsu46dcc572020-01-08 18:24:03 +08008950
8951 /**
8952 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8953 *
8954 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8955 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8956 * before being read.
8957 */
8958 @Override
8959 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8960 isCompressed) {
8961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8962 mApp, subId, "notifyRcsAutoConfigurationReceived");
8963 try {
8964 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8965 if (configBinder == null) {
8966 Rlog.e(LOG_TAG, "null result for getImsConfig");
8967 } else {
8968 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8969 }
8970 } catch (RemoteException e) {
8971 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8972 }
8973 }
zoey chenf95ca592019-12-30 16:11:23 +08008974
8975 @Override
8976 public boolean isIccLockEnabled(int subId) {
8977 enforceReadPrivilegedPermission("isIccLockEnabled");
8978
8979 // Now that all security checks passes, perform the operation as ourselves.
8980 final long identity = Binder.clearCallingIdentity();
8981 try {
8982 Phone phone = getPhone(subId);
8983 if (phone != null && phone.getIccCard() != null) {
8984 return phone.getIccCard().getIccLockEnabled();
8985 } else {
8986 return false;
8987 }
8988 } finally {
8989 Binder.restoreCallingIdentity(identity);
8990 }
8991 }
8992
8993 /**
zoey chene02881a2019-12-30 16:11:23 +08008994 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008995 *
zoey chene02881a2019-12-30 16:11:23 +08008996 * @return an integer representing the status of IccLock enabled or disabled in the following
8997 * three cases:
8998 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8999 * successfully.
9000 * - Positive number and zero for remaining password attempts.
9001 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009002 *
9003 */
9004 @Override
9005 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9006 enforceModifyPermission();
9007
9008 Phone phone = getPhone(subId);
9009 if (phone == null) {
9010 return 0;
9011 }
9012 // Now that all security checks passes, perform the operation as ourselves.
9013 final long identity = Binder.clearCallingIdentity();
9014 try {
9015 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9016 new Pair<Boolean, String>(enabled, password), phone, null);
9017 return attemptsRemaining;
9018
9019 } catch (Exception e) {
9020 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 return 0;
9025 }
9026
9027 /**
9028 * Change the ICC password used in ICC pin lock.
9029 *
zoey chene02881a2019-12-30 16:11:23 +08009030 * @return an integer representing the status of IccLock changed in the following three cases:
9031 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9032 * - Positive number and zero for remaining password attempts.
9033 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009034 *
9035 */
9036 @Override
9037 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9038 enforceModifyPermission();
9039
9040 Phone phone = getPhone(subId);
9041 if (phone == null) {
9042 return 0;
9043 }
9044 // Now that all security checks passes, perform the operation as ourselves.
9045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9048 new Pair<String, String>(oldPassword, newPassword), phone, null);
9049 return attemptsRemaining;
9050
9051 } catch (Exception e) {
9052 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9053 } finally {
9054 Binder.restoreCallingIdentity(identity);
9055 }
9056 return 0;
9057 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009058
Peter Wangdafb9ac2020-01-15 14:13:38 -08009059 /**
9060 * Request for receiving user activity notification
9061 */
9062 @Override
9063 public void requestUserActivityNotification() {
9064 if (!mNotifyUserActivity.get()
9065 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9066 mNotifyUserActivity.set(true);
9067 }
9068 }
9069
9070 /**
9071 * Called when userActivity is signalled in the power manager.
9072 * This is safe to call from any thread, with any window manager locks held or not.
9073 */
9074 @Override
9075 public void userActivity() {
9076 // ***************************************
9077 // * Inherited from PhoneWindowManager *
9078 // ***************************************
9079 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9080 // WITH ITS LOCKS HELD.
9081 //
9082 // This code must be VERY careful about the locks
9083 // it acquires.
9084 // In fact, the current code acquires way too many,
9085 // and probably has lurking deadlocks.
9086
9087 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9088 throw new SecurityException("Only the OS may call notifyUserActivity()");
9089 }
9090
9091 if (mNotifyUserActivity.getAndSet(false)) {
9092 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9093 USER_ACTIVITY_NOTIFICATION_DELAY);
9094 }
9095 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009096
Malcolm Chen884180b2020-04-13 11:59:40 -07009097 @Override
9098 public boolean canConnectTo5GInDsdsMode() {
9099 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9100 }
Jack Yud10cdd42020-09-28 20:28:01 -07009101
9102 @Override
9103 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9104 String callingFeatureId) {
9105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9106 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9107 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9108 }
9109
9110 Phone phone = getPhone(subId);
9111 if (phone == null) {
9112 throw new RuntimeException("phone is not available");
9113 }
9114 // Now that all security checks passes, perform the operation as ourselves.
9115 final long identity = Binder.clearCallingIdentity();
9116 try {
9117 return phone.getEquivalentHomePlmns();
9118 } finally {
9119 Binder.restoreCallingIdentity(identity);
9120 }
9121 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009122
9123 /**
9124 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9125 * requested radio power state will actually be set. See {@link
9126 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9127 *
9128 * @param subId the subscription ID of the phone requesting to set the radio power state.
9129 * @param enable {@code true} if trying to turn radio on.
9130 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9131 * false}.
9132 */
9133 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9134 Phone phone = getPhone(subId);
9135 if (phone != null) {
9136 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9137 return true;
9138 }
9139 return false;
9140 }
9141
9142 private int handleDataThrottlingRequest(int subId,
9143 DataThrottlingRequest dataThrottlingRequest) {
9144 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9145 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9146 if (!setRadioPowerForThermal(subId, true)) {
9147 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9148 }
9149
9150 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9151
9152 int thermalMitigationResult =
9153 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9154 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9155 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9156 }
9157 return thermalMitigationResult;
9158 }
9159
9160 /**
9161 * Thermal mitigation request to control functionalities at modem.
9162 *
9163 * @param subId the id of the subscription.
9164 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9165 *
9166 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9167 */
9168 @Override
9169 @ThermalMitigationResult
9170 public int sendThermalMitigationRequest(
9171 int subId,
9172 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9173 enforceModifyPermission();
9174
9175 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9176 final long identity = Binder.clearCallingIdentity();
9177
9178 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9179 try {
9180 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9181 switch (thermalMitigationAction) {
9182 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9183 thermalMitigationResult =
9184 handleDataThrottlingRequest(subId,
9185 thermalMitigationRequest.getDataThrottlingRequest());
9186 break;
9187 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9188 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9189 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9190 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9191 }
9192
9193 // Ensure that radio is on. If not able to power on due to phone being
9194 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9195 if (!setRadioPowerForThermal(subId, true)) {
9196 thermalMitigationResult =
9197 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9198 break;
9199 }
9200
9201 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9202 false);
9203 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9204 break;
9205 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9206 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9207 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9208 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9209 }
9210
9211 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9212 if (registry != null) {
9213 TelephonyConnectionService service =
9214 registry.getTelephonyConnectionService();
9215 Phone phone = getPhone(subId);
9216 if (phone == null) {
9217 thermalMitigationResult =
9218 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9219 break;
9220 }
9221
9222 if (PhoneConstantConversions.convertCallState(phone.getState())
9223 != TelephonyManager.CALL_STATE_IDLE
9224 || phone.isInEmergencySmsMode() || phone.isInEcm()
9225 || (service != null && service.isEmergencyCallPending())) {
9226 String errorMessage = "Phone state is not valid. call state = "
9227 + PhoneConstantConversions.convertCallState(phone.getState())
9228 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9229 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9230 errorMessage += service == null
9231 ? " TelephonyConnectionService is null"
9232 : " isEmergencyCallPending = "
9233 + service.isEmergencyCallPending();
9234 Log.e(LOG_TAG, errorMessage);
9235 thermalMitigationResult =
9236 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9237 break;
9238 }
9239 } else {
9240 thermalMitigationResult =
9241 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9242 break;
9243 }
9244
9245 // Turn radio off. If not able to power off due to phone being unavailable,
9246 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9247 if (!setRadioPowerForThermal(subId, false)) {
9248 thermalMitigationResult =
9249 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9250 break;
9251 }
9252 thermalMitigationResult =
9253 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9254 break;
9255 default:
9256 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9257 + "not exist. Requested action: " + thermalMitigationAction);
9258 }
9259 } catch (IllegalArgumentException e) {
9260 throw e;
9261 } catch (Exception e) {
9262 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9263 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9264 } finally {
9265 Binder.restoreCallingIdentity(identity);
9266 }
9267
9268 if (DBG) {
9269 log("thermalMitigationRequest returning with thermalMitigationResult: "
9270 + thermalMitigationResult);
9271 }
9272
9273 return thermalMitigationResult;
9274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009275}