blob: 49108844ecf2383270367e7418d5941c36ce3d11 [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 {
calvinpan089c2a62020-03-12 14:17:55 +08005884 Boolean success = (Boolean) sendRequest(
5885 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005886
5887 if (success) {
5888 Settings.Global.putInt(mApp.getContentResolver(),
5889 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5890 }
calvinpan089c2a62020-03-12 14:17:55 +08005891 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5892 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 } finally {
5894 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005895 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005896 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005897
5898 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005899 * Get the allowed network types that store in the telephony provider.
5900 *
5901 * @param subId the id of the subscription.
5902 * @return allowedNetworkTypes the allowed network types.
5903 */
5904 @Override
5905 public long getAllowedNetworkTypes(int subId) {
5906 TelephonyPermissions
5907 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5908 mApp, subId, "getAllowedNetworkTypes");
5909
5910 final long identity = Binder.clearCallingIdentity();
5911 try {
5912 return SubscriptionManager.getLongSubscriptionProperty(
5913 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5914 } finally {
5915 Binder.restoreCallingIdentity(identity);
5916 }
5917 }
5918
5919 /**
5920 * Set the allowed network types.
5921 *
5922 * @param subId the id of the subscription.
5923 * @param allowedNetworkTypes the allowed network types.
5924 * @return true on success; false on any failure.
5925 */
5926 @Override
5927 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5929 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005930
calvinpan089c2a62020-03-12 14:17:55 +08005931 SubscriptionManager.setSubscriptionProperty(subId,
5932 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5933 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005934
calvinpan089c2a62020-03-12 14:17:55 +08005935 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5936 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5937 RILConstants.PREFERRED_NETWORK_MODE);
5938 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005939 }
5940
5941 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005942 * Get the allowed network types for certain reason.
5943 *
5944 * @param subId the id of the subscription.
5945 * @param reason the reason the allowed network type change is taking place
5946 * @return the allowed network types.
5947 */
5948 @Override
5949 public long getAllowedNetworkTypesForReason(int subId,
5950 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5951 TelephonyPermissions
5952 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5953 mApp, subId, "getAllowedNetworkTypesForReason");
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
5960 }
5961
5962 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07005963 * Enable/Disable E-UTRA-NR Dual Connectivity
5964 * @param subId subscription id of the sim card
5965 * @param nrDualConnectivityState expected NR dual connectivity state
5966 * This can be passed following states
5967 * <ol>
5968 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
5969 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
5970 * <li>Disable NR dual connectivity and force secondary cell to be released
5971 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
5972 * </ol>
5973 * @return operation result.
5974 */
5975 @Override
5976 public int setNrDualConnectivityState(int subId,
5977 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
5978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5979 mApp, subId, "enableNRDualConnectivity");
5980 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5981 final long identity = Binder.clearCallingIdentity();
5982 try {
5983 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
5984 nrDualConnectivityState, subId,
5985 workSource);
5986 if (DBG) log("enableNRDualConnectivity result: " + result);
5987 return result;
5988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
5991 }
5992
5993 /**
5994 * Is E-UTRA-NR Dual Connectivity enabled
5995 * @return true if dual connectivity is enabled else false
5996 */
5997 @Override
5998 public boolean isNrDualConnectivityEnabled(int subId) {
5999 TelephonyPermissions
6000 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6001 mApp, subId, "isNRDualConnectivityEnabled");
6002 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6003 final long identity = Binder.clearCallingIdentity();
6004 try {
6005 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6006 null, subId, workSource);
6007 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6008 return isEnabled;
6009 } finally {
6010 Binder.restoreCallingIdentity(identity);
6011 }
6012 }
6013
6014 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006015 * get carrier bandwidth per primary and secondary carrier
6016 * @param subId subscription id of the sim card
6017 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6018 */
6019 @Override
6020 public CarrierBandwidth getCarrierBandwidth(int subId) {
6021 TelephonyPermissions
6022 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6023 mApp, subId, "isNRDualConnectivityEnabled");
6024 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6025 final long identity = Binder.clearCallingIdentity();
6026 try {
6027 CarrierBandwidth carrierBandwidth =
6028 getPhoneFromSubId(subId).getCarrierBandwidth();
6029 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6030 return carrierBandwidth;
6031 } finally {
6032 Binder.restoreCallingIdentity(identity);
6033 }
6034 }
6035
6036 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006037 * Get the effective allowed network types on the device.
6038 * This API will return an intersection of allowed network types for all reasons,
6039 * including the configuration done through setAllowedNetworkTypes
6040 *
6041 * @param subId the id of the subscription.
6042 * @return the allowed network types
6043 */
6044 @Override
6045 public long getEffectiveAllowedNetworkTypes(int subId) {
6046 TelephonyPermissions
6047 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6048 mApp, subId, "getEffectiveAllowedNetworkTypes");
6049 final long identity = Binder.clearCallingIdentity();
6050 try {
6051 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6052 } finally {
6053 Binder.restoreCallingIdentity(identity);
6054 }
6055 }
6056
6057 /**
6058 * Set the allowed network types of the device and
6059 * provide the reason triggering the allowed network change.
6060 *
6061 * @param subId the id of the subscription.
6062 * @param reason the reason the allowed network type change is taking place
6063 * @param allowedNetworkTypes the allowed network types.
6064 * @return true on success; false on any failure.
6065 */
6066 @Override
6067 public boolean setAllowedNetworkTypesForReason(int subId,
6068 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6070 mApp, subId, "setAllowedNetworkTypesForReason");
6071 final long identity = Binder.clearCallingIdentity();
6072 try {
6073 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6074 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6075 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6076 RILConstants.PREFERRED_NETWORK_MODE);
6077 return setPreferredNetworkType(subId, preferredNetworkMode);
6078 } finally {
6079 Binder.restoreCallingIdentity(identity);
6080 }
6081 }
6082
6083 /**
Miaoa84611c2019-03-15 09:21:10 +08006084 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006085 *
Miaoa84611c2019-03-15 09:21:10 +08006086 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006087 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006088 * @hide
6089 */
6090 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006091 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006092 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006094 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095 try {
Miaoa84611c2019-03-15 09:21:10 +08006096 if (phone != null) {
6097 return phone.hasMatchedTetherApnSetting();
6098 } else {
6099 return false;
6100 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101 } finally {
6102 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006103 }
Junda Liu475951f2014-11-07 16:45:03 -08006104 }
6105
6106 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006107 * Enable or disable always reporting signal strength changes from radio.
6108 *
6109 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6110 */
6111 @Override
6112 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6113 enforceModifyPermission();
6114 enforceSystemCaller();
6115
6116 final long identity = Binder.clearCallingIdentity();
6117 final Phone phone = getPhone(subId);
6118 try {
6119 if (phone != null) {
6120 if (DBG) {
6121 log("setAlwaysReportSignalStrength: subId=" + subId
6122 + " isEnable=" + isEnable);
6123 }
6124 phone.setAlwaysReportSignalStrength(isEnable);
6125 } else {
6126 loge("setAlwaysReportSignalStrength: no phone found for subId="
6127 + subId);
6128 }
6129 } finally {
6130 Binder.restoreCallingIdentity(identity);
6131 }
6132 }
6133
6134 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006135 * Get the user enabled state of Mobile Data.
6136 *
6137 * TODO: remove and use isUserDataEnabled.
6138 * This can't be removed now because some vendor codes
6139 * calls through ITelephony directly while they should
6140 * use TelephonyManager.
6141 *
6142 * @return true on enabled
6143 */
6144 @Override
6145 public boolean getDataEnabled(int subId) {
6146 return isUserDataEnabled(subId);
6147 }
6148
6149 /**
6150 * Get whether mobile data is enabled per user setting.
6151 *
6152 * There are other factors deciding whether mobile data is actually enabled, but they are
6153 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006154 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006155 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006156 *
6157 * @return {@code true} if data is enabled else {@code false}
6158 */
6159 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006160 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006161 try {
6162 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6163 null);
6164 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6166 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006167 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168
6169 final long identity = Binder.clearCallingIdentity();
6170 try {
6171 int phoneId = mSubscriptionController.getPhoneId(subId);
6172 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6173 Phone phone = PhoneFactory.getPhone(phoneId);
6174 if (phone != null) {
6175 boolean retVal = phone.isUserDataEnabled();
6176 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6177 return retVal;
6178 } else {
6179 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6180 return false;
6181 }
6182 } finally {
6183 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006184 }
6185 }
6186
6187 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006188 * Checks if the device is capable of mobile data by considering whether whether the
6189 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6190 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006191 *
Shuo Qian985d1232020-01-08 14:30:06 -08006192 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006193 */
6194 @Override
6195 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006196 try {
6197 try {
6198 mApp.enforceCallingOrSelfPermission(
6199 android.Manifest.permission.ACCESS_NETWORK_STATE,
6200 null);
6201 } catch (Exception e) {
6202 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6203 "isDataEnabled");
6204 }
6205 } catch (Exception e) {
6206 enforceReadPrivilegedPermission("isDataEnabled");
6207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208
6209 final long identity = Binder.clearCallingIdentity();
6210 try {
6211 int phoneId = mSubscriptionController.getPhoneId(subId);
6212 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6213 Phone phone = PhoneFactory.getPhone(phoneId);
6214 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006215 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6217 return retVal;
6218 } else {
6219 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6220 return false;
6221 }
6222 } finally {
6223 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006224 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006225 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006226
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006227 /**
6228 * Check if data is enabled for a specific reason
6229 * @param subId Subscription index
6230 * @param reason the reason the data enable change is taking place
6231 * @return {@code true} if the overall data is enabled; {@code false} if not.
6232 */
6233 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006234 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006235 @TelephonyManager.DataEnabledReason int reason) {
6236 try {
6237 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6238 null);
6239 } catch (Exception e) {
6240 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006241 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006242 }
6243
6244
6245 final long identity = Binder.clearCallingIdentity();
6246 try {
6247 int phoneId = mSubscriptionController.getPhoneId(subId);
6248 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006249 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006250 + " reason=" + reason);
6251 }
6252 Phone phone = PhoneFactory.getPhone(phoneId);
6253 if (phone != null) {
6254 boolean retVal;
6255 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6256 retVal = phone.isUserDataEnabled();
6257 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006258 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006259 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006260 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006261 return retVal;
6262 } else {
6263 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006264 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006265 + subId + " retVal=false");
6266 }
6267 return false;
6268 }
6269 } finally {
6270 Binder.restoreCallingIdentity(identity);
6271 }
6272 }
6273
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006274 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006275 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006276 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6277 // Skip the check if it's one of these special uids
6278 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6279 }
6280
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006281 //load access rules from carrier configs, and check those as well: b/139133814
6282 SubscriptionController subController = SubscriptionController.getInstance();
6283 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6284 || subController == null) return privilegeFromSim;
6285
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006286 PackageManager pkgMgr = phone.getContext().getPackageManager();
6287 String[] packages = pkgMgr.getPackagesForUid(uid);
6288
6289 final long identity = Binder.clearCallingIdentity();
6290 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006291 int subId = phone.getSubId();
6292 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6293 // A test override is in place for the privileges for this subId, so don't try to
6294 // read the subscription privileges.
6295 return privilegeFromSim;
6296 }
6297 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006298 SubscriptionManager subManager = (SubscriptionManager)
6299 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6300 for (String pkg : packages) {
6301 if (subManager.canManageSubscription(subInfo, pkg)) {
6302 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6303 }
6304 }
6305 return privilegeFromSim;
6306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
6309 }
6310
6311 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6312 String pkgName) {
6313 //load access rules from carrier configs, and check those as well: b/139133814
6314 SubscriptionController subController = SubscriptionController.getInstance();
6315 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6316 || subController == null) return privilegeFromSim;
6317
6318 final long identity = Binder.clearCallingIdentity();
6319 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006320 int subId = phone.getSubId();
6321 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6322 // A test override is in place for the privileges for this subId, so don't try to
6323 // read the subscription privileges.
6324 return privilegeFromSim;
6325 }
6326 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006327 SubscriptionManager subManager = (SubscriptionManager)
6328 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6329 return subManager.canManageSubscription(subInfo, pkgName)
6330 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6331 } finally {
6332 Binder.restoreCallingIdentity(identity);
6333 }
6334 }
6335
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006336 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006337 public int getCarrierPrivilegeStatus(int subId) {
6338 final Phone phone = getPhone(subId);
6339 if (phone == null) {
6340 loge("getCarrierPrivilegeStatus: Invalid subId");
6341 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6342 }
6343 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006344 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006345 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006346 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6347 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006348
6349 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6350 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006351 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006352 }
Junda Liu29340342014-07-10 15:23:27 -07006353
6354 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006355 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006356 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006357 final Phone phone = getPhone(subId);
6358 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006359 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006360 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6361 }
6362 UiccProfile profile =
6363 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6364 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006365 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006366 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6367 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006368 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006369 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006370 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006371 }
6372
6373 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006374 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6375 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006376 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006377 }
6378
6379 int phoneId = SubscriptionManager.getPhoneId(subId);
6380 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006381 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006382 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006383 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6384 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006385 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6386 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6387 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006388 }
6389
6390 @Override
6391 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006392 if (TextUtils.isEmpty(pkgName))
6393 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006394 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6395 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6396 UiccCard card = UiccController.getInstance().getUiccCard(i);
6397 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006398 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006399 continue;
6400 }
6401
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006402 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6403 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6404 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006405 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6406 break;
6407 }
6408 }
6409
6410 return result;
Junda Liu29340342014-07-10 15:23:27 -07006411 }
Derek Tan89e89d42014-07-08 17:00:10 -07006412
6413 @Override
Junda Liue64de782015-04-16 17:19:16 -07006414 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6415 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6416 loge("phoneId " + phoneId + " is not valid.");
6417 return null;
6418 }
6419 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006420 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006421 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006422 return null ;
6423 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006424 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006425 }
6426
Amith Yamasani6e118872016-02-19 12:53:51 -08006427 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006428 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006429 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006430 List<String> privilegedPackages = new ArrayList<>();
6431 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006432 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6433 // has UICC in that slot.
6434 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006435 if (card.hasCarrierPrivilegeRules()) {
6436 if (packages == null) {
6437 // Only check packages in user 0 for now
6438 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006439 PackageManager.MATCH_DISABLED_COMPONENTS
6440 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006441 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006442 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006443 }
6444 for (int p = packages.size() - 1; p >= 0; p--) {
6445 PackageInfo pkgInfo = packages.get(p);
6446 if (pkgInfo != null && pkgInfo.packageName != null
6447 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006448 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006449 privilegedPackages.add(pkgInfo.packageName);
6450 }
6451 }
6452 }
6453 }
6454 return privilegedPackages;
6455 }
6456
chen xuf7e9fe82019-05-09 19:31:02 -07006457 @Override
6458 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006459 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6460
6461 final long identity = Binder.clearCallingIdentity();
6462
chen xuf7e9fe82019-05-09 19:31:02 -07006463 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006464 try {
6465 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6466 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6467 }
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006470 }
6471 return privilegedPackages;
6472 }
6473
Wink Savilleb564aae2014-10-23 10:18:09 -07006474 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006475 final Phone phone = getPhone(subId);
6476 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006477 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006478 return null;
6479 }
6480 String iccId = card.getIccId();
6481 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006482 return null;
6483 }
6484 return iccId;
6485 }
6486
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006487 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006488 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6489 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006490 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006491 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 final String iccId = getIccId(subId);
6496 final Phone phone = getPhone(subId);
6497 if (phone == null) {
6498 return false;
6499 }
6500 final String subscriberId = phone.getSubscriberId();
6501
6502 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006503 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006504 + subscriberId + " to " + number);
6505 }
6506
6507 if (TextUtils.isEmpty(iccId)) {
6508 return false;
6509 }
6510
6511 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6512
6513 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6514 if (alphaTag == null) {
6515 editor.remove(alphaTagPrefKey);
6516 } else {
6517 editor.putString(alphaTagPrefKey, alphaTag);
6518 }
6519
6520 // Record both the line number and IMSI for this ICCID, since we need to
6521 // track all merged IMSIs based on line number
6522 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6523 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6524 if (number == null) {
6525 editor.remove(numberPrefKey);
6526 editor.remove(subscriberPrefKey);
6527 } else {
6528 editor.putString(numberPrefKey, number);
6529 editor.putString(subscriberPrefKey, subscriberId);
6530 }
6531
6532 editor.commit();
6533 return true;
6534 } finally {
6535 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006536 }
Derek Tan7226c842014-07-02 17:42:23 -07006537 }
6538
6539 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006540 public String getLine1NumberForDisplay(int subId, String callingPackage,
6541 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006542 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006544 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006545 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006546 return null;
6547 }
Derek Tan97ebb422014-09-05 16:55:38 -07006548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 final long identity = Binder.clearCallingIdentity();
6550 try {
6551 String iccId = getIccId(subId);
6552 if (iccId != null) {
6553 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6554 if (DBG_MERGE) {
6555 log("getLine1NumberForDisplay returning "
6556 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6557 }
6558 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006560 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6561 return null;
6562 } finally {
6563 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006564 }
Derek Tan7226c842014-07-02 17:42:23 -07006565 }
6566
6567 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006568 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6569 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006570 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006571 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006572 return null;
6573 }
Derek Tan97ebb422014-09-05 16:55:38 -07006574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006575 final long identity = Binder.clearCallingIdentity();
6576 try {
6577 String iccId = getIccId(subId);
6578 if (iccId != null) {
6579 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6580 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6581 }
6582 return null;
6583 } finally {
6584 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006585 }
Derek Tan7226c842014-07-02 17:42:23 -07006586 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006587
6588 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006589 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6590 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006591 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6592 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006594 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006595 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006596 return null;
6597 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006598
Jordan Liub49b04b2019-05-06 14:45:15 -07006599 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6600 // the process, where TelephonyManager was instantiated.
6601 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006602 final long identity = Binder.clearCallingIdentity();
6603 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006604 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 final TelephonyManager tele = TelephonyManager.from(context);
6606 final SubscriptionManager sub = SubscriptionManager.from(context);
6607
6608 // Figure out what subscribers are currently active
6609 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610
Jordan Liub49b04b2019-05-06 14:45:15 -07006611 // Only consider subs which match the current subId
6612 // This logic can be simplified. See b/131189269 for progress.
6613 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006614 activeSubscriberIds.add(tele.getSubscriberId(subId));
6615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616
6617 // First pass, find a number override for an active subscriber
6618 String mergeNumber = null;
6619 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6620 for (String key : prefs.keySet()) {
6621 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6622 final String subscriberId = (String) prefs.get(key);
6623 if (activeSubscriberIds.contains(subscriberId)) {
6624 final String iccId = key.substring(
6625 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6626 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6627 mergeNumber = (String) prefs.get(numberKey);
6628 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006629 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006630 + " for active subscriber " + subscriberId);
6631 }
6632 if (!TextUtils.isEmpty(mergeNumber)) {
6633 break;
6634 }
6635 }
6636 }
6637 }
6638
6639 // Shortcut when no active merged subscribers
6640 if (TextUtils.isEmpty(mergeNumber)) {
6641 return null;
6642 }
6643
6644 // Second pass, find all subscribers under that line override
6645 final ArraySet<String> result = new ArraySet<>();
6646 for (String key : prefs.keySet()) {
6647 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6648 final String number = (String) prefs.get(key);
6649 if (mergeNumber.equals(number)) {
6650 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6651 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6652 final String subscriberId = (String) prefs.get(subscriberKey);
6653 if (!TextUtils.isEmpty(subscriberId)) {
6654 result.add(subscriberId);
6655 }
6656 }
6657 }
6658 }
6659
6660 final String[] resultArray = result.toArray(new String[result.size()]);
6661 Arrays.sort(resultArray);
6662 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006663 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006664 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6665 }
6666 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006667 } finally {
6668 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006669 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006670 }
6671
6672 @Override
zoey chen38003472019-12-13 17:16:31 +08006673 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6674 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006675
6676 final long identity = Binder.clearCallingIdentity();
6677 try {
6678 final TelephonyManager telephonyManager = mApp.getSystemService(
6679 TelephonyManager.class);
6680 String subscriberId = telephonyManager.getSubscriberId(subId);
6681 if (subscriberId == null) {
6682 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006683 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006684 + subId);
6685 }
6686 return null;
6687 }
6688
6689 final SubscriptionInfo info = SubscriptionController.getInstance()
6690 .getSubscriptionInfo(subId);
6691 final ParcelUuid groupUuid = info.getGroupUuid();
6692 // If it doesn't belong to any group, return just subscriberId of itself.
6693 if (groupUuid == null) {
6694 return new String[]{subscriberId};
6695 }
6696
6697 // Get all subscriberIds from the group.
6698 final List<String> mergedSubscriberIds = new ArrayList<>();
6699 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006700 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006701 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006702 for (SubscriptionInfo subInfo : groupInfos) {
6703 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6704 if (subscriberId != null) {
6705 mergedSubscriberIds.add(subscriberId);
6706 }
6707 }
6708
6709 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6710 } finally {
6711 Binder.restoreCallingIdentity(identity);
6712
6713 }
6714 }
6715
6716 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006717 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006718 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006719 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720
6721 final long identity = Binder.clearCallingIdentity();
6722 try {
6723 final Phone phone = getPhone(subId);
6724 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006728 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006729
6730 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006731 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006732 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6733 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006734 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6735 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736
6737 final long identity = Binder.clearCallingIdentity();
6738 try {
6739 final Phone phone = getPhone(subId);
6740 if (phone == null) {
6741 return false;
6742 }
6743 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6744 cdmaNonRoamingList);
6745 } finally {
6746 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006747 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006748 }
6749
6750 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006751 @Deprecated
6752 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6753 enforceModifyPermission();
6754
6755 int returnValue = 0;
6756 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006757 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006758 if(result.exception == null) {
6759 if (result.result != null) {
6760 byte[] responseData = (byte[])(result.result);
6761 if(responseData.length > oemResp.length) {
6762 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6763 responseData.length + "bytes. Buffer Size is " +
6764 oemResp.length + "bytes.");
6765 }
6766 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6767 returnValue = responseData.length;
6768 }
6769 } else {
6770 CommandException ex = (CommandException) result.exception;
6771 returnValue = ex.getCommandError().ordinal();
6772 if(returnValue > 0) returnValue *= -1;
6773 }
6774 } catch (RuntimeException e) {
6775 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6776 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6777 if(returnValue > 0) returnValue *= -1;
6778 }
6779
6780 return returnValue;
6781 }
6782
6783 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006784 public void setRadioCapability(RadioAccessFamily[] rafs) {
6785 try {
6786 ProxyController.getInstance().setRadioCapability(rafs);
6787 } catch (RuntimeException e) {
6788 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6789 }
6790 }
6791
6792 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006793 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006794 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006795 try {
6796 TelephonyPermissions
6797 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6798 mApp, phone.getSubId(), "getRadioAccessFamily");
6799 } catch (SecurityException e) {
6800 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6801 throw e;
6802 }
chen xub97461a2018-10-26 14:17:57 -07006803 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006804 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006805 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006807 final long identity = Binder.clearCallingIdentity();
6808 try {
chen xub97461a2018-10-26 14:17:57 -07006809 TelephonyPermissions
6810 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6811 mApp, phone.getSubId(), "getRadioAccessFamily");
6812 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 } finally {
6814 Binder.restoreCallingIdentity(identity);
6815 }
chen xub97461a2018-10-26 14:17:57 -07006816 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006817 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006818
6819 @Override
6820 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006821 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823
6824 final long identity = Binder.clearCallingIdentity();
6825 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006826 ImsManager.getInstance(defaultPhone.getContext(),
6827 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828 } finally {
6829 Binder.restoreCallingIdentity(identity);
6830 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006831 }
6832
6833 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006834 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006835 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006836 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6837 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006838 return false;
6839 }
Svet Ganovb320e182015-04-16 12:30:10 -07006840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 final long identity = Binder.clearCallingIdentity();
6842 try {
6843 // Check the user preference and the system-level IMS setting. Even if the user has
6844 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6845 // In the long run, we may instead need to check if there exists a connection service
6846 // which can support video calling.
6847 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006848 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006849 return imsManager.isVtEnabledByPlatform()
6850 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6851 && imsManager.isVtEnabledByUser();
6852 } finally {
6853 Binder.restoreCallingIdentity(identity);
6854 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006855 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006856
Andrew Leea1239f22015-03-02 17:44:07 -08006857 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006858 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6859 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006861 mApp, subId, callingPackage, callingFeatureId,
6862 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 return false;
6864 }
6865
6866 final long identity = Binder.clearCallingIdentity();
6867 try {
6868 CarrierConfigManager configManager =
6869 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006870 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6872 } finally {
6873 Binder.restoreCallingIdentity(identity);
6874 }
Andrew Leea1239f22015-03-02 17:44:07 -08006875 }
6876
6877 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006878 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006880 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 return false;
6882 }
6883
6884 final long identity = Binder.clearCallingIdentity();
6885 try {
6886 CarrierConfigManager configManager =
6887 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006888 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6890 } finally {
6891 Binder.restoreCallingIdentity(identity);
6892 }
Andrew Leea1239f22015-03-02 17:44:07 -08006893 }
6894
Andrew Lee9431b832015-03-09 18:46:45 -07006895 @Override
6896 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006897 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006898 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006899 }
6900
6901 @Override
6902 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 final long identity = Binder.clearCallingIdentity();
6904 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006905 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906 } finally {
6907 Binder.restoreCallingIdentity(identity);
6908 }
Andrew Lee9431b832015-03-09 18:46:45 -07006909 }
6910
Hall Liuf6668912018-10-31 17:05:23 -07006911 /**
6912 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6913 * support for the feature and device firmware support.
6914 *
6915 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6916 */
6917 @Override
6918 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006920 final Phone phone = getPhone(subscriptionId);
6921 if (phone == null) {
6922 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6923 return false;
6924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006926 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6928 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006929 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930 return isCarrierSupported && isDeviceSupported;
6931 } finally {
6932 Binder.restoreCallingIdentity(identity);
6933 }
Hall Liu98187582018-01-22 19:15:32 -08006934 }
6935
Hall Liuf6668912018-10-31 17:05:23 -07006936 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006937 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6938 * RTT setting, will return true if the device and carrier both support RTT.
6939 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006940 */
6941 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942 final long identity = Binder.clearCallingIdentity();
6943 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006944 boolean isRttSupported = isRttSupported(subscriptionId);
6945 boolean isUserRttSettingOn = Settings.Secure.getInt(
6946 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6947 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6948 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6949 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 } finally {
6951 Binder.restoreCallingIdentity(identity);
6952 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006953 }
6954
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006955 @Deprecated
6956 @Override
6957 public String getDeviceId(String callingPackage) {
6958 return getDeviceIdWithFeature(callingPackage, null);
6959 }
6960
Sanket Padawe7310cc72015-01-14 09:53:20 -08006961 /**
6962 * Returns the unique device ID of phone, for example, the IMEI for
6963 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6964 *
6965 * <p>Requires Permission:
6966 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6967 */
6968 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006969 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006970 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006971 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006972 return null;
6973 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006974 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006975 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006976 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006977 return null;
6978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979
6980 final long identity = Binder.clearCallingIdentity();
6981 try {
6982 return phone.getDeviceId();
6983 } finally {
6984 Binder.restoreCallingIdentity(identity);
6985 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006986 }
6987
Ping Sunc67b7c22016-03-02 19:16:45 +08006988 /**
6989 * {@hide}
6990 * Returns the IMS Registration Status on a particular subid
6991 *
6992 * @param subId
6993 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006994 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006995 Phone phone = getPhone(subId);
6996 if (phone != null) {
6997 return phone.isImsRegistered();
6998 } else {
6999 return false;
7000 }
7001 }
7002
Santos Cordon7a1885b2015-02-03 11:15:19 -08007003 @Override
7004 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 final long identity = Binder.clearCallingIdentity();
7006 try {
7007 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007011 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007012
Tyler Gunnf70ed162019-04-03 15:28:53 -07007013 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007014 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007015 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007017 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007018 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7019 }
7020 final long identity = Binder.clearCallingIdentity();
7021 try {
7022 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7023 } finally {
7024 Binder.restoreCallingIdentity(identity);
7025 }
7026 }
7027
7028 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007029 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007030 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7031 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007032 final long identity = Binder.clearCallingIdentity();
7033 try {
7034 Phone phone = getPhone(subscriptionId);
7035 if (phone == null) {
7036 return null;
7037 }
7038 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7039 } finally {
7040 Binder.restoreCallingIdentity(identity);
7041 }
7042 }
7043
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007044 /**
7045 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007046 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007047 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 final long identity = Binder.clearCallingIdentity();
7049 try {
7050 Phone phone = getPhone(subId);
7051 if (phone != null) {
7052 return phone.isWifiCallingEnabled();
7053 } else {
7054 return false;
7055 }
7056 } finally {
7057 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007058 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007059 }
7060
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007061 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007062 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007063 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007064 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 final long identity = Binder.clearCallingIdentity();
7066 try {
7067 Phone phone = getPhone(subId);
7068 if (phone != null) {
7069 return phone.isVideoEnabled();
7070 } else {
7071 return false;
7072 }
7073 } finally {
7074 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007075 }
7076 }
7077
7078 /**
7079 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7080 * defined in {@link ImsRegistrationImplBase}.
7081 */
7082 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 final long identity = Binder.clearCallingIdentity();
7084 try {
7085 Phone phone = getPhone(subId);
7086 if (phone != null) {
7087 return phone.getImsRegistrationTech();
7088 } else {
7089 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7090 }
7091 } finally {
7092 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007093 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007094 }
7095
Stuart Scott8eef64f2015-04-08 15:13:54 -07007096 @Override
7097 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007098 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007099 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7100 return;
7101 }
7102
Svet Ganovcc087f82015-05-12 20:35:54 -07007103 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007104
Svet Ganovcc087f82015-05-12 20:35:54 -07007105 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007106 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7107 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007108 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007109 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007110 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007111 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007112 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7113 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007114 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007115 // There has been issues when Sms raw table somehow stores orphan
7116 // fragments. They lead to garbled message when new fragments come
7117 // in and combined with those stale ones. In case this happens again,
7118 // user can reset all network settings which will clean up this table.
7119 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007120 // Clean up IMS settings as well here.
7121 int slotId = getSlotIndex(subId);
7122 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7123 ImsManager.getInstance(mApp, slotId).factoryReset();
7124 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007125
7126 // Erase modem config if erase modem on network setting is enabled.
7127 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7128 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7129 if (configValue != null && Boolean.parseBoolean(configValue)) {
7130 sendEraseModemConfig(getDefaultPhone());
7131 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007132 } finally {
7133 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007134 }
7135 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007136
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007137 private void cleanUpSmsRawTable(Context context) {
7138 ContentResolver resolver = context.getContentResolver();
7139 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7140 resolver.delete(uri, null, null);
7141 }
7142
Narayan Kamath1c496c22015-04-16 14:40:19 +01007143 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007144 public String getSimLocaleForSubscriber(int subId) {
7145 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7146 final Phone phone = getPhone(subId);
7147 if (phone == null) {
7148 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007149 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 final long identity = Binder.clearCallingIdentity();
7152 try {
chen xu5d3637b2019-01-21 23:31:38 -08007153 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007154 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007155 if (info == null) {
7156 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7157 return null;
7158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 // Try and fetch the locale from the carrier properties or from the SIM language
7160 // preferences (EF-PL and EF-LI)...
7161 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007163 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7164 if (localeFromDefaultSim != null) {
7165 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7166 if (DBG) log("Using locale from subId: " + subId + " locale: "
7167 + localeFromDefaultSim);
7168 return localeFromDefaultSim.toLanguageTag();
7169 } else {
7170 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 }
7172 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007173
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174 // The SIM language preferences only store a language (e.g. fr = French), not an
7175 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7176 // the SIM and carrier preferences does not include a country we add the country
7177 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007178 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007180 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 return mccLocale.toLanguageTag();
7182 }
7183
7184 if (DBG) log("No locale found - returning null");
7185 return null;
7186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007189 }
7190
7191 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007192 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007193 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007194 }
7195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 /**
7197 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7198 */
7199 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007200 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007201 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007202 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007203
Chenjie Yu1ba97252018-01-11 18:16:20 -08007204 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007205 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007206
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007207 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007208 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7209 * representing the state of the modem.
7210 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007211 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7212 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007213 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007214 */
7215 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007216 public void requestModemActivityInfo(ResultReceiver result) {
7217 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007218 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219
7220 final long identity = Binder.clearCallingIdentity();
7221 try {
sqian1a1be542020-03-05 11:37:28 -08007222 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223 } finally {
7224 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007225 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007226 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007227
Siddharth Rayb8114062018-06-17 15:02:38 -07007228 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7229 // less than total activity duration.
7230 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7231 if (info == null) {
7232 return false;
7233 }
7234 int activityDurationMs =
7235 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7236 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007237 int[] txTimeMs = info.getTransmitTimeMillis();
7238 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7239 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007240 }
7241 return (info.isValid()
7242 && (info.getSleepTimeMillis() <= activityDurationMs)
7243 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007244 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007245 && (totalTxTimeMs <= activityDurationMs));
7246 }
7247
Jack Yu85bd38a2015-11-09 11:34:32 -08007248 /**
7249 * {@hide}
7250 * Returns the service state information on specified subscription.
7251 */
7252 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007253 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7254 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007256 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007257 return null;
7258 }
7259
Hall Liuf19c44f2018-11-27 14:38:17 -08007260 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7261 LocationAccessPolicy.checkLocationPermission(mApp,
7262 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7263 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007264 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007265 .setCallingPid(Binder.getCallingPid())
7266 .setCallingUid(Binder.getCallingUid())
7267 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007268 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007269 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7270 .build());
7271
7272 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7273 LocationAccessPolicy.checkLocationPermission(mApp,
7274 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7275 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007276 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007277 .setCallingPid(Binder.getCallingPid())
7278 .setCallingUid(Binder.getCallingUid())
7279 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007280 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007281 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7282 .build());
7283 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7284 boolean hasFinePermission =
7285 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7286 boolean hasCoarsePermission =
7287 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007289 final long identity = Binder.clearCallingIdentity();
7290 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007291 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7292 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7293 Rlog.d(LOG_TAG,
7294 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7295 return null;
7296 }
7297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298 final Phone phone = getPhone(subId);
7299 if (phone == null) {
7300 return null;
7301 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007302
Hall Liuf19c44f2018-11-27 14:38:17 -08007303 ServiceState ss = phone.getServiceState();
7304
7305 // Scrub out the location info in ServiceState depending on what level of access
7306 // the caller has.
7307 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007308 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7309 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 } finally {
7311 Binder.restoreCallingIdentity(identity);
7312 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007313 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007314
7315 /**
7316 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7317 *
7318 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7319 * voicemail ringtone.
7320 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7321 * PhoneAccount.
7322 */
7323 @Override
7324 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 final long identity = Binder.clearCallingIdentity();
7326 try {
7327 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7328 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007329 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7333 } finally {
7334 Binder.restoreCallingIdentity(identity);
7335 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007336 }
7337
7338 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007339 * Sets the per-account voicemail ringtone.
7340 *
7341 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7342 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7343 *
7344 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7345 * voicemail ringtone.
7346 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7347 * PhoneAccount.
7348 */
7349 @Override
7350 public void setVoicemailRingtoneUri(String callingPackage,
7351 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007352 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007353 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007354 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7355 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7357 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7358 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360
7361 final long identity = Binder.clearCallingIdentity();
7362 try {
7363 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7364 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007365 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 }
7367 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7368 } finally {
7369 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007370 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007371 }
7372
7373 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007374 * Returns whether vibration is set for voicemail notification in Phone settings.
7375 *
7376 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7377 * voicemail vibration setting.
7378 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7379 */
7380 @Override
7381 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 final long identity = Binder.clearCallingIdentity();
7383 try {
7384 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7385 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007386 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7390 } finally {
7391 Binder.restoreCallingIdentity(identity);
7392 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007393 }
7394
Youhan Wange64578a2016-05-02 15:32:42 -07007395 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007396 * Sets the per-account voicemail vibration.
7397 *
7398 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7399 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7400 *
7401 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7402 * voicemail vibration setting.
7403 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7404 * specific PhoneAccount.
7405 */
7406 @Override
7407 public void setVoicemailVibrationEnabled(String callingPackage,
7408 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007409 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007410 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007411 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7412 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7414 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7415 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007416 }
7417
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418 final long identity = Binder.clearCallingIdentity();
7419 try {
7420 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7421 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007422 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423 }
7424 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7425 } finally {
7426 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007427 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007428 }
7429
7430 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007431 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7432 *
7433 * @throws SecurityException if the caller does not have the required permission
7434 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007435 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007436 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007437 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007438 }
7439
7440 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007441 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7442 * permission.
7443 *
7444 * @throws SecurityException if the caller does not have the required permission
7445 */
7446 private void enforceSendSmsPermission() {
7447 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7448 }
7449
7450 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007451 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007452 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007453 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007454 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007455 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 final long identity = Binder.clearCallingIdentity();
7457 try {
7458 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007459 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 if (componentName == null) {
7461 throw new SecurityException(
7462 "Caller not current active visual voicemail package[null]");
7463 }
7464 String vvmPackage = componentName.getPackageName();
7465 if (!callingPackage.equals(vvmPackage)) {
7466 throw new SecurityException("Caller not current active visual voicemail package["
7467 + vvmPackage + "]");
7468 }
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007471 }
7472 }
7473
7474 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007475 * Return the application ID for the app type.
7476 *
7477 * @param subId the subscription ID that this request applies to.
7478 * @param appType the uicc app type.
7479 * @return Application ID for specificied app type, or null if no uicc.
7480 */
7481 @Override
7482 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007483 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007484 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485
7486 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007487 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 if (phone == null) {
7489 return null;
7490 }
7491 String aid = null;
7492 try {
7493 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7494 .getApplicationByType(appType).getAid();
7495 } catch (Exception e) {
7496 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7497 }
7498 return aid;
7499 } finally {
7500 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007501 }
Youhan Wange64578a2016-05-02 15:32:42 -07007502 }
7503
Youhan Wang4001d252016-05-11 10:29:41 -07007504 /**
7505 * Return the Electronic Serial Number.
7506 *
7507 * @param subId the subscription ID that this request applies to.
7508 * @return ESN or null if error.
7509 */
7510 @Override
7511 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007512 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007513 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514
7515 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007516 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 if (phone == null) {
7518 return null;
7519 }
7520 String esn = null;
7521 try {
7522 esn = phone.getEsn();
7523 } catch (Exception e) {
7524 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7525 }
7526 return esn;
7527 } finally {
7528 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007529 }
Youhan Wang4001d252016-05-11 10:29:41 -07007530 }
7531
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007532 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007533 * Return the Preferred Roaming List Version.
7534 *
7535 * @param subId the subscription ID that this request applies to.
7536 * @return PRLVersion or null if error.
7537 */
7538 @Override
7539 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007540 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007541 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542
7543 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007544 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 if (phone == null) {
7546 return null;
7547 }
7548 String cdmaPrlVersion = null;
7549 try {
7550 cdmaPrlVersion = phone.getCdmaPrlVersion();
7551 } catch (Exception e) {
7552 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7553 }
7554 return cdmaPrlVersion;
7555 } finally {
7556 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007557 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007558 }
7559
7560 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007561 * Get snapshot of Telephony histograms
7562 * @return List of Telephony histograms
7563 * @hide
7564 */
7565 @Override
7566 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7568 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569
7570 final long identity = Binder.clearCallingIdentity();
7571 try {
7572 return RIL.getTelephonyRILTimingHistograms();
7573 } finally {
7574 Binder.restoreCallingIdentity(identity);
7575 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007576 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007577
7578 /**
7579 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007580 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7581 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007582 * Require system privileges. In the future we may add this to carrier APIs.
7583 *
Michele Berionne482f8202018-11-27 18:57:59 -08007584 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007585 */
7586 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007587 @TelephonyManager.SetCarrierRestrictionResult
7588 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007589 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007590 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007591
Michele Berionne482f8202018-11-27 18:57:59 -08007592 if (carrierRestrictionRules == null) {
7593 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007594 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 final long identity = Binder.clearCallingIdentity();
7597 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007598 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007599 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 } finally {
7601 Binder.restoreCallingIdentity(identity);
7602 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007603 }
7604
7605 /**
7606 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007607 * Get the allowed carrier list and the excluded carrier list, including the priority between
7608 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007609 * Require system privileges. In the future we may add this to carrier APIs.
7610 *
Michele Berionne482f8202018-11-27 18:57:59 -08007611 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007612 */
7613 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007614 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007615 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007616 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617
7618 final long identity = Binder.clearCallingIdentity();
7619 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007620 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7621 if (response instanceof CarrierRestrictionRules) {
7622 return (CarrierRestrictionRules) response;
7623 }
7624 // Response is an Exception of some kind,
7625 // which is signalled to the user as a NULL retval
7626 return null;
7627 } catch (Exception e) {
7628 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7629 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007630 } finally {
7631 Binder.restoreCallingIdentity(identity);
7632 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007633 }
7634
fionaxu59545b42016-05-25 15:53:37 -07007635 /**
fionaxu59545b42016-05-25 15:53:37 -07007636 * Action set from carrier signalling broadcast receivers to enable/disable radio
7637 * @param subId the subscription ID that this action applies to.
7638 * @param enabled control enable or disable radio.
7639 * {@hide}
7640 */
7641 @Override
7642 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7643 enforceModifyPermission();
7644 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645
7646 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007647 if (phone == null) {
7648 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7649 return;
7650 }
7651 try {
7652 phone.carrierActionSetRadioEnabled(enabled);
7653 } catch (Exception e) {
7654 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007655 } finally {
7656 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007657 }
7658 }
7659
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007660 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007661 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7662 * network status based on which carrier apps could apply actions accordingly,
7663 * enable/disable default url handler for example.
7664 *
7665 * @param subId the subscription ID that this action applies to.
7666 * @param report control start/stop reporting the default network status.
7667 * {@hide}
7668 */
7669 @Override
7670 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7671 enforceModifyPermission();
7672 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673
7674 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007675 if (phone == null) {
7676 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7677 return;
7678 }
7679 try {
7680 phone.carrierActionReportDefaultNetworkStatus(report);
7681 } catch (Exception e) {
7682 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683 } finally {
7684 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007685 }
7686 }
7687
7688 /**
fionaxud9622282017-07-17 17:51:30 -07007689 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7690 * @param subId the subscription ID that this action applies to.
7691 * {@hide}
7692 */
7693 @Override
7694 public void carrierActionResetAll(int subId) {
7695 enforceModifyPermission();
7696 final Phone phone = getPhone(subId);
7697 if (phone == null) {
7698 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7699 return;
7700 }
7701 try {
7702 phone.carrierActionResetAll();
7703 } catch (Exception e) {
7704 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7705 }
7706 }
7707
7708 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007709 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7710 * bug report is being generated.
7711 */
7712 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007713 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007714 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7715 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007716 writer.println("Permission Denial: can't dump Phone from pid="
7717 + Binder.getCallingPid()
7718 + ", uid=" + Binder.getCallingUid()
7719 + "without permission "
7720 + android.Manifest.permission.DUMP);
7721 return;
7722 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007723 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007724 }
Jack Yueb89b242016-06-22 13:27:47 -07007725
Brad Ebingerdac2f002018-04-03 15:17:52 -07007726 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007727 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7728 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7729 @NonNull String[] args) {
7730 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7731 this, in.getFileDescriptor(), out.getFileDescriptor(),
7732 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007733 }
7734
Jack Yueb89b242016-06-22 13:27:47 -07007735 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007736 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007737 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007738 * @param reason the reason the data enable change is taking place
7739 * @param enabled True if enabling the data, otherwise disabling.
7740 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007741 */
7742 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007743 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007744 boolean enabled) {
7745 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7746 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7747 try {
7748 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007749 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007750 } catch (SecurityException se) {
7751 enforceModifyPermission();
7752 }
7753 } else {
7754 enforceModifyPermission();
7755 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756
7757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 Phone phone = getPhone(subId);
7760 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007761 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7762 phone.carrierActionSetMeteredApnsEnabled(enabled);
7763 } else {
7764 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766 }
7767 } finally {
7768 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007769 }
7770 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007771
7772 /**
7773 * Get Client request stats
7774 * @return List of Client Request Stats
7775 * @hide
7776 */
7777 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007778 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7779 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007781 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007782 return null;
7783 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007784 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 final long identity = Binder.clearCallingIdentity();
7787 try {
7788 if (phone != null) {
7789 return phone.getClientRequestStats();
7790 }
7791
7792 return null;
7793 } finally {
7794 Binder.restoreCallingIdentity(identity);
7795 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007796 }
7797
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007798 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007799 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007800 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007801 }
Jack Yueb4124c2017-02-16 15:32:43 -08007802
7803 /**
Grace Chen70990072017-03-24 17:21:30 -07007804 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007805 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007806 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007807 * @param state State of SIM (power down, power up, pass through)
7808 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7809 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7810 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007811 *
7812 **/
7813 @Override
Grace Chen70990072017-03-24 17:21:30 -07007814 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007815 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007816 Phone phone = PhoneFactory.getPhone(slotIndex);
7817
vagdeviaf9a5b92018-08-15 16:01:53 -07007818 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7819
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820 final long identity = Binder.clearCallingIdentity();
7821 try {
7822 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007823 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007824 }
7825 } finally {
7826 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007827 }
7828 }
Shuo Qiandd210312017-04-12 22:11:33 +00007829
Tyler Gunn65d45c22017-06-05 11:22:26 -07007830 private boolean isUssdApiAllowed(int subId) {
7831 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007832 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007833 if (configManager == null) {
7834 return false;
7835 }
7836 PersistableBundle pb = configManager.getConfigForSubId(subId);
7837 if (pb == null) {
7838 return false;
7839 }
7840 return pb.getBoolean(
7841 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7842 }
7843
Shuo Qiandd210312017-04-12 22:11:33 +00007844 /**
7845 * Check if phone is in emergency callback mode
7846 * @return true if phone is in emergency callback mode
7847 * @param subId sub id
7848 */
goneil9c5f4872017-12-05 14:07:56 -08007849 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007850 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007851 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007852 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853
7854 final long identity = Binder.clearCallingIdentity();
7855 try {
7856 if (phone != null) {
7857 return phone.isInEcm();
7858 } else {
7859 return false;
7860 }
7861 } finally {
7862 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007863 }
7864 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007865
7866 /**
7867 * Get the current signal strength information for the given subscription.
7868 * Because this information is not updated when the device is in a low power state
7869 * it should not be relied-upon to be current.
7870 * @param subId Subscription index
7871 * @return the most recent cached signal strength info from the modem
7872 */
7873 @Override
7874 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875 final long identity = Binder.clearCallingIdentity();
7876 try {
7877 Phone p = getPhone(subId);
7878 if (p == null) {
7879 return null;
7880 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007882 return p.getSignalStrength();
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
7885 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007886 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007887
Pengquan Meng77b7f132018-08-22 14:49:57 -07007888 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007889 * Get the current modem radio state for the given slot.
7890 * @param slotIndex slot index.
7891 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007892 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007893 * @return the current radio power state from the modem
7894 */
7895 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007896 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007897 Phone phone = PhoneFactory.getPhone(slotIndex);
7898 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7900 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007901 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7902 }
7903
7904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 return phone.getRadioPowerState();
7907 } finally {
7908 Binder.restoreCallingIdentity(identity);
7909 }
7910 }
7911 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7912 }
7913
7914 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007915 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7916 *
7917 * <p>Requires one of the following permissions:
7918 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7919 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7920 * privileges.
7921 *
7922 * @param subId subscription id
7923 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7924 * {@code false}.
7925 */
7926 @Override
7927 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007928 try {
7929 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7930 null);
7931 } catch (Exception e) {
7932 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7933 mApp, subId, "isDataRoamingEnabled");
7934 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007935
Pengquan Menga1bb6272018-09-06 09:59:22 -07007936 boolean isEnabled = false;
7937 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007938 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007939 Phone phone = getPhone(subId);
7940 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007941 } finally {
7942 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007943 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007944 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007945 }
7946
7947
7948 /**
7949 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7950 *
7951 * <p> Requires permission:
7952 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7953 * privileges.
7954 *
7955 * @param subId subscription id
7956 * @param isEnabled {@code true} means enable, {@code false} means disable.
7957 */
7958 @Override
7959 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7961 mApp, subId, "setDataRoamingEnabled");
7962
Pengquan Menga1bb6272018-09-06 09:59:22 -07007963 final long identity = Binder.clearCallingIdentity();
7964 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007965 Phone phone = getPhone(subId);
7966 if (phone != null) {
7967 phone.setDataRoamingEnabled(isEnabled);
7968 }
7969 } finally {
7970 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007971 }
7972 }
7973
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007974 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007975 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007976 TelephonyPermissions
7977 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007978 mApp, subId, "isManualNetworkSelectionAllowed");
7979
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007980 boolean isAllowed = true;
7981 final long identity = Binder.clearCallingIdentity();
7982 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007983 Phone phone = getPhone(subId);
7984 if (phone != null) {
7985 isAllowed = phone.isCspPlmnEnabled();
7986 }
7987 } finally {
7988 Binder.restoreCallingIdentity(identity);
7989 }
7990 return isAllowed;
7991 }
7992
7993 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007994 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007995 // Verify that tha callingPackage belongs to the calling UID
7996 mApp.getSystemService(AppOpsManager.class)
7997 .checkPackage(Binder.getCallingUid(), callingPackage);
7998
Jordan Liu1e142fc2019-04-22 15:10:43 -07007999 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008000 try {
8001 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008002 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008003 } catch (SecurityException e) {
8004 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8005 // has carrier privileges on an active UICC
8006 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8007 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008008 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008009 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008010 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008011
8012 final long identity = Binder.clearCallingIdentity();
8013 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008014 UiccController uiccController = UiccController.getInstance();
8015 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008016 if (hasReadPermission) {
8017 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008018 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008019
8020 // Remove private info if the caller doesn't have access
8021 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8022 for (UiccCardInfo cardInfo : cardInfos) {
8023 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8024 // is available
8025 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8026 if (card == null || card.getUiccProfile() == null) {
8027 // assume no access if the card or profile is unavailable
8028 filteredInfos.add(cardInfo.getUnprivileged());
8029 continue;
8030 }
8031 UiccProfile profile = card.getUiccProfile();
8032 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8033 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8034 filteredInfos.add(cardInfo);
8035 } else {
8036 filteredInfos.add(cardInfo.getUnprivileged());
8037 }
8038 }
8039 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008040 } finally {
8041 Binder.restoreCallingIdentity(identity);
8042 }
8043 }
8044
8045 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008046 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008047 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 final long identity = Binder.clearCallingIdentity();
8050 try {
8051 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8052 if (slots == null) {
8053 Rlog.i(LOG_TAG, "slots is null.");
8054 return null;
8055 }
8056
8057 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8058 for (int i = 0; i < slots.length; i++) {
8059 UiccSlot slot = slots[i];
8060 if (slot == null) {
8061 continue;
8062 }
8063
Jordan Liu7be7e652019-05-06 18:55:02 +00008064 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008065 UiccCard card = slot.getUiccCard();
8066 if (card != null) {
8067 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008068 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008069 cardId = slot.getEid();
8070 if (TextUtils.isEmpty(cardId)) {
8071 cardId = slot.getIccId();
8072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008073 }
8074
Jordan Liu857451f2019-05-09 16:35:35 -07008075 if (cardId != null) {
8076 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8077 // if cardId is an EID, it's all digits so this is fine
8078 cardId = IccUtils.stripTrailingFs(cardId);
8079 }
8080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081 int cardState = 0;
8082 switch (slot.getCardState()) {
8083 case CARDSTATE_ABSENT:
8084 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8085 break;
8086 case CARDSTATE_PRESENT:
8087 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8088 break;
8089 case CARDSTATE_ERROR:
8090 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8091 break;
8092 case CARDSTATE_RESTRICTED:
8093 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8094 break;
8095 default:
8096 break;
8097
8098 }
8099
8100 infos[i] = new UiccSlotInfo(
8101 slot.isActive(),
8102 slot.isEuicc(),
8103 cardId,
8104 cardState,
8105 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008106 slot.isExtendedApduSupported(),
8107 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 }
8109 return infos;
8110 } finally {
8111 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008112 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008113 }
8114
8115 @Override
8116 public boolean switchSlots(int[] physicalSlots) {
8117 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118
8119 final long identity = Binder.clearCallingIdentity();
8120 try {
8121 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
8124 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008125 }
Jack Yu4c988042018-02-27 15:30:01 -08008126
8127 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008128 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008129 final long identity = Binder.clearCallingIdentity();
8130 try {
8131 return UiccController.getInstance().getCardIdForDefaultEuicc();
8132 } finally {
8133 Binder.restoreCallingIdentity(identity);
8134 }
8135 }
8136
Pengquan Meng85728fb2018-03-12 16:31:21 -07008137 /**
goneil47ffb6e2018-04-06 15:40:58 -07008138 * A test API to reload the UICC profile.
8139 *
8140 * <p>Requires that the calling app has permission
8141 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8142 * @hide
8143 */
8144 @Override
8145 public void refreshUiccProfile(int subId) {
8146 enforceModifyPermission();
8147
8148 final long identity = Binder.clearCallingIdentity();
8149 try {
8150 Phone phone = getPhone(subId);
8151 if (phone == null) {
8152 return;
8153 }
8154 UiccCard uiccCard = phone.getUiccCard();
8155 if (uiccCard == null) {
8156 return;
8157 }
8158 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8159 if (uiccProfile == null) {
8160 return;
8161 }
8162 uiccProfile.refresh();
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
8165 }
8166 }
8167
8168 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008169 * Returns false if the mobile data is disabled by default, otherwise return true.
8170 */
8171 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008172 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008173 }
8174
8175 /**
8176 * Returns true if the data roaming is enabled by default, i.e the system property
8177 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8178 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8179 */
8180 private boolean getDefaultDataRoamingEnabled(int subId) {
8181 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008182 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008183 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008184 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8185 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8186 return isDataRoamingEnabled;
8187 }
8188
8189 /**
8190 * Returns the default network type for the given {@code subId}, if the default network type is
8191 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8192 */
8193 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008194 List<Integer> list = TelephonyProperties.default_network();
8195 int phoneId = mSubscriptionController.getPhoneId(subId);
8196 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8197 return list.get(phoneId);
8198 }
8199 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008200 }
fionaxua13278b2018-03-21 00:08:13 -07008201
8202 @Override
8203 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008204 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008206
8207 final long identity = Binder.clearCallingIdentity();
8208 try {
8209 final Phone phone = getPhone(subId);
8210 if (phone == null) {
8211 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8212 return;
8213 }
chen xueaba88a2019-03-15 13:15:10 -07008214 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8215 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008216 if (carrierPrivilegeRules == null) {
8217 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8218 } else {
8219 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8220 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 } finally {
8222 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008223 }
fionaxua13278b2018-03-21 00:08:13 -07008224 }
8225
8226 @Override
8227 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008228 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008229
8230 final long identity = Binder.clearCallingIdentity();
8231 try {
8232 final Phone phone = getPhone(subId);
8233 if (phone == null) {
8234 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8235 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8236 }
8237 return phone.getCarrierIdListVersion();
8238 } finally {
8239 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008240 }
fionaxua13278b2018-03-21 00:08:13 -07008241 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008242
8243 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008244 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8245 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008247 mApp, subId, callingPackage, callingFeatureId,
8248 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008249 return -1;
8250 }
8251
8252 final long identity = Binder.clearCallingIdentity();
8253 try {
8254 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8255 } finally {
8256 Binder.restoreCallingIdentity(identity);
8257 }
8258 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008259
8260 @Override
8261 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008262 TelephonyPermissions
8263 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008264 mApp, subId, "getCdmaRoamingMode");
8265
8266 final long identity = Binder.clearCallingIdentity();
8267 try {
8268 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8269 } finally {
8270 Binder.restoreCallingIdentity(identity);
8271 }
8272 }
8273
8274 @Override
8275 public boolean setCdmaRoamingMode(int subId, int mode) {
8276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8277 mApp, subId, "setCdmaRoamingMode");
8278
8279 final long identity = Binder.clearCallingIdentity();
8280 try {
8281 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8282 } finally {
8283 Binder.restoreCallingIdentity(identity);
8284 }
8285 }
8286
8287 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008288 public int getCdmaSubscriptionMode(int subId) {
8289 TelephonyPermissions
8290 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8291 mApp, subId, "getCdmaSubscriptionMode");
8292
8293 final long identity = Binder.clearCallingIdentity();
8294 try {
8295 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8296 } finally {
8297 Binder.restoreCallingIdentity(identity);
8298 }
8299 }
8300
8301 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008302 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8304 mApp, subId, "setCdmaSubscriptionMode");
8305
8306 final long identity = Binder.clearCallingIdentity();
8307 try {
8308 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8309 } finally {
8310 Binder.restoreCallingIdentity(identity);
8311 }
8312 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008313
sqianc5eccab2018-10-19 18:46:41 -07008314 @Override
sqian8c685422019-02-22 15:55:18 -08008315 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008316 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008318 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8319 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008320 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8321 }
8322 final long identity = Binder.clearCallingIdentity();
8323 try {
sqian854d44b2018-12-12 16:48:18 -08008324 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8325 for (Phone phone: PhoneFactory.getPhones()) {
8326 if (phone.getEmergencyNumberTracker() != null
8327 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8328 emergencyNumberListInternal.put(
8329 phone.getSubId(),
8330 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8331 }
sqian11b7a0e2018-12-05 18:48:28 -08008332 }
sqian854d44b2018-12-12 16:48:18 -08008333 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008334 } finally {
8335 Binder.restoreCallingIdentity(identity);
8336 }
sqianc5eccab2018-10-19 18:46:41 -07008337 }
8338
8339 @Override
sqian8c685422019-02-22 15:55:18 -08008340 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008341 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008342 if (!exactMatch) {
8343 TelephonyPermissions
8344 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008345 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008346 }
8347 final long identity = Binder.clearCallingIdentity();
8348 try {
sqian854d44b2018-12-12 16:48:18 -08008349 for (Phone phone: PhoneFactory.getPhones()) {
8350 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008351 && phone.getEmergencyNumberTracker()
8352 .isEmergencyNumber(number, exactMatch)) {
8353 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008354 }
sqian11b7a0e2018-12-05 18:48:28 -08008355 }
8356 return false;
8357 } finally {
8358 Binder.restoreCallingIdentity(identity);
8359 }
8360 }
8361
sqianf4ca7ed2019-01-15 18:32:07 -08008362 /**
8363 * Update emergency number list for test mode.
8364 */
8365 @Override
8366 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8367 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8368 "updateEmergencyNumberListTestMode");
8369
8370 final long identity = Binder.clearCallingIdentity();
8371 try {
8372 for (Phone phone: PhoneFactory.getPhones()) {
8373 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8374 if (tracker != null) {
8375 tracker.executeEmergencyNumberTestModeCommand(action, num);
8376 }
8377 }
8378 } finally {
8379 Binder.restoreCallingIdentity(identity);
8380 }
8381 }
8382
8383 /**
8384 * Get the full emergency number list for test mode.
8385 */
8386 @Override
8387 public List<String> getEmergencyNumberListTestMode() {
8388 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8389 "getEmergencyNumberListTestMode");
8390
8391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 Set<String> emergencyNumbers = new HashSet<>();
8394 for (Phone phone: PhoneFactory.getPhones()) {
8395 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8396 if (tracker != null) {
8397 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8398 emergencyNumbers.add(num.getNumber());
8399 }
8400 }
8401 }
8402 return new ArrayList<>(emergencyNumbers);
8403 } finally {
8404 Binder.restoreCallingIdentity(identity);
8405 }
8406 }
8407
chen xud6b45bd2018-10-30 22:27:10 -07008408 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008409 public int getEmergencyNumberDbVersion(int subId) {
8410 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8411
8412 final long identity = Binder.clearCallingIdentity();
8413 try {
8414 final Phone phone = getPhone(subId);
8415 if (phone == null) {
8416 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8417 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8418 }
8419 return phone.getEmergencyNumberDbVersion();
8420 } finally {
8421 Binder.restoreCallingIdentity(identity);
8422 }
8423 }
8424
8425 @Override
8426 public void notifyOtaEmergencyNumberDbInstalled() {
8427 enforceModifyPermission();
8428
8429 final long identity = Binder.clearCallingIdentity();
8430 try {
8431 for (Phone phone: PhoneFactory.getPhones()) {
8432 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8433 if (tracker != null) {
8434 tracker.updateOtaEmergencyNumberDatabase();
8435 }
8436 }
8437 } finally {
8438 Binder.restoreCallingIdentity(identity);
8439 }
8440 }
8441
8442 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008443 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008444 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) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008451 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8452 }
8453 }
8454 } finally {
8455 Binder.restoreCallingIdentity(identity);
8456 }
8457 }
8458
8459 @Override
8460 public void resetOtaEmergencyNumberDbFilePath() {
8461 enforceActiveEmergencySessionPermission();
8462
8463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 for (Phone phone: PhoneFactory.getPhones()) {
8466 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8467 if (tracker != null) {
8468 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008469 }
8470 }
8471 } finally {
8472 Binder.restoreCallingIdentity(identity);
8473 }
8474 }
8475
8476 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008477 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8478 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8479 Phone phone = getPhone(subId);
8480 if (phone == null) {
8481 return null;
8482 }
8483 final long identity = Binder.clearCallingIdentity();
8484 try {
8485 UiccProfile profile = UiccController.getInstance()
8486 .getUiccProfileForPhone(phone.getPhoneId());
8487 if (profile != null) {
8488 return profile.getCertsFromCarrierPrivilegeAccessRules();
8489 }
8490 } finally {
8491 Binder.restoreCallingIdentity(identity);
8492 }
8493 return null;
8494 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008495
8496 /**
8497 * Enable or disable a modem stack.
8498 */
8499 @Override
8500 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8501 enforceModifyPermission();
8502
8503 final long identity = Binder.clearCallingIdentity();
8504 try {
8505 Phone phone = PhoneFactory.getPhone(slotIndex);
8506 if (phone == null) {
8507 return false;
8508 } else {
8509 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8510 }
8511 } finally {
8512 Binder.restoreCallingIdentity(identity);
8513 }
8514 }
Michelecea4cf22018-12-21 15:00:11 -08008515
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008516 /**
8517 * Whether a modem stack is enabled or not.
8518 */
8519 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008520 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8521 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008522 Phone phone = PhoneFactory.getPhone(slotIndex);
8523 if (phone == null) return false;
8524
8525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008526 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8527 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008528 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8529 }
8530
8531 final long identity = Binder.clearCallingIdentity();
8532 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008533 try {
8534 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8535 } catch (NoSuchElementException ex) {
8536 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8537 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008538 } finally {
8539 Binder.restoreCallingIdentity(identity);
8540 }
8541 }
8542
Michelecea4cf22018-12-21 15:00:11 -08008543 @Override
Michele0ea7d782019-03-19 14:58:42 -07008544 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008545 enforceModifyPermission();
8546
8547 final long identity = Binder.clearCallingIdentity();
8548 try {
8549 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008550 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008551 .commit();
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
8554 }
8555 }
8556
8557 @Override
Michele0ea7d782019-03-19 14:58:42 -07008558 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008559 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008561 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8562 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008563 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008564 }
Michelecea4cf22018-12-21 15:00:11 -08008565
8566 final long identity = Binder.clearCallingIdentity();
8567 try {
Michele0ea7d782019-03-19 14:58:42 -07008568 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008569 } finally {
8570 Binder.restoreCallingIdentity(identity);
8571 }
8572 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008573
Michele0ea7d782019-03-19 14:58:42 -07008574 @TelephonyManager.IsMultiSimSupportedResult
8575 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008576 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8577 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8578 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008579 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8580 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008581 }
8582 // Check if the hardware supports multisim functionality. If usage of multisim is not
8583 // supported by the modem, indicate that it is restricted.
8584 PhoneCapability staticCapability =
8585 mPhoneConfigurationManager.getStaticPhoneCapability();
8586 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008587 loge("isMultiSimSupportedInternal: no static configuration available");
8588 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008589 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008590 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008591 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8592 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008593 }
8594 // Check if support of multiple SIMs is restricted by carrier
8595 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008596 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008597 }
8598
Michele0ea7d782019-03-19 14:58:42 -07008599 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008600 }
8601
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008602 /**
8603 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008604 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8605 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8606 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008607 * @param numOfSims number of active sims we want to switch to
8608 */
8609 @Override
8610 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008611 if (numOfSims == 1) {
8612 enforceModifyPermission();
8613 } else {
8614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8615 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8616 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008617 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008618
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008619 try {
Michele30b57b22019-03-01 12:01:14 -08008620 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008621 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008622 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8623 return;
8624 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008625 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8626 } finally {
8627 Binder.restoreCallingIdentity(identity);
8628 }
8629 }
8630
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008631 @Override
8632 public boolean isApplicationOnUicc(int subId, int appType) {
8633 enforceReadPrivilegedPermission("isApplicationOnUicc");
8634 Phone phone = getPhone(subId);
8635 if (phone == null) {
8636 return false;
8637 }
8638 final long identity = Binder.clearCallingIdentity();
8639 try {
8640 UiccCard uiccCard = phone.getUiccCard();
8641 if (uiccCard == null) {
8642 return false;
8643 }
8644 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8645 if (uiccProfile == null) {
8646 return false;
8647 }
8648 if (TelephonyManager.APPTYPE_SIM <= appType
8649 && appType <= TelephonyManager.APPTYPE_ISIM) {
8650 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8651 }
8652 return false;
8653 } finally {
8654 Binder.restoreCallingIdentity(identity);
8655 }
8656 }
8657
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008658 /**
chen xub4baa772019-04-03 10:23:41 -07008659 * Get whether making changes to modem configurations will trigger reboot.
8660 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008661 */
8662 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008663 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8664 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008665 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008666 mApp, subId, callingPackage, callingFeatureId,
8667 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008668 return false;
8669 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008670 final long identity = Binder.clearCallingIdentity();
8671 try {
8672 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8673 } finally {
8674 Binder.restoreCallingIdentity(identity);
8675 }
8676 }
8677
Nathan Harold29f5f052019-02-15 13:41:57 -08008678 private void updateModemStateMetrics() {
8679 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8680 // TODO: check the state for each modem if the api is ready.
8681 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8682 }
8683
Pengquan Meng3889a572019-01-23 11:16:29 -08008684 @Override
8685 public int[] getSlotsMapping() {
8686 enforceReadPrivilegedPermission("getSlotsMapping");
8687
8688 final long identity = Binder.clearCallingIdentity();
8689 try {
8690 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8691 // All logical slots should have a mapping to a physical slot.
8692 int[] logicalSlotsMapping = new int[phoneCount];
8693 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8694 for (int i = 0; i < slotInfos.length; i++) {
8695 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8696 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8697 }
8698 }
8699 return logicalSlotsMapping;
8700 } finally {
8701 Binder.restoreCallingIdentity(identity);
8702 }
8703 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008704
8705 /**
8706 * Get the IRadio HAL Version
8707 */
8708 @Override
8709 public int getRadioHalVersion() {
8710 Phone phone = getDefaultPhone();
8711 if (phone == null) return -1;
8712 HalVersion hv = phone.getHalVersion();
8713 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8714 return hv.major * 100 + hv.minor;
8715 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008716
8717 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008718 * Get the current calling package name.
8719 * @return the current calling package name
8720 */
8721 @Override
8722 public String getCurrentPackageName() {
8723 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8724 }
8725
8726 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008727 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8728 * corresponding network requests on a subId.
8729 *
8730 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008731 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008732 * 2) APN is un-metered for this subscription, or
8733 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008734 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008735 *
8736 * @return whether data is allowed for a apn type.
8737 *
8738 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008739 */
8740 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008741 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008742 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8743 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008744
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 false;
8750
Jack Yu41407ee2019-05-13 16:54:09 -07008751 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008752 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8753 } finally {
8754 Binder.restoreCallingIdentity(identity);
8755 }
8756 }
8757
8758 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008759 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008760 enforceReadPrivilegedPermission("isApnMetered");
8761
8762 // Now that all security checks passes, perform the operation as ourselves.
8763 final long identity = Binder.clearCallingIdentity();
8764 try {
8765 Phone phone = getPhone(subId);
8766 if (phone == null) return true; // By default return true.
8767
Jack Yu41407ee2019-05-13 16:54:09 -07008768 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008769 } finally {
8770 Binder.restoreCallingIdentity(identity);
8771 }
8772 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008773
8774 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008775 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8776 int subscriptionId, IBooleanConsumer resultCallback) {
8777 enforceModifyPermission();
8778 long token = Binder.clearCallingIdentity();
8779 try {
8780 Phone phone = getPhone(subscriptionId);
8781 if (phone == null) {
8782 try {
8783 if (resultCallback != null) {
8784 resultCallback.accept(false);
8785 }
8786 } catch (RemoteException e) {
8787 // ignore
8788 }
8789 return;
8790 }
8791 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8792 Pair.create(specifiers, (x) -> {
8793 try {
8794 if (resultCallback != null) {
8795 resultCallback.accept(x);
8796 }
8797 } catch (RemoteException e) {
8798 // ignore
8799 }
8800 });
8801 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8802 } finally {
8803 Binder.restoreCallingIdentity(token);
8804 }
8805 }
8806
8807 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008808 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8809 TelephonyPermissions
8810 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8811 mApp, subId, "getSystemSelectionChannels");
8812 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8813 final long identity = Binder.clearCallingIdentity();
8814 try {
8815 List<RadioAccessSpecifier> specifiers =
8816 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8817 null, subId, workSource);
8818 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8819 return specifiers;
8820 } finally {
8821 Binder.restoreCallingIdentity(identity);
8822 }
8823 }
8824
8825 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008826 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008827 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008828 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8829 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8830 if (iccRecords == null) {
8831 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8832 return false;
8833 }
8834 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8835 }
8836
8837 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008838 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8839 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008840 if (callingPackage == null) {
8841 callingPackage = getCurrentPackageName();
8842 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008843 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8844 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008845 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8846 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008847 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8848 }
8849 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8850 Intent intent = new Intent();
8851 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8852 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8853 // Bring up choose default SMS subscription dialog right now
8854 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8855 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8856 mApp.startActivity(intent);
8857 }
chen xud5ca2d52019-05-28 15:20:57 -07008858
8859 @Override
8860 public String getMmsUAProfUrl(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 carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8865 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8866 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8867 return carrierUAProfUrl;
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_profile_url);
8871 } finally {
8872 Binder.restoreCallingIdentity(identity);
8873 }
8874 }
8875
8876 @Override
8877 public String getMmsUserAgent(int subId) {
8878 //TODO investigate if this API should require proper permission check in R b/133791609
8879 final long identity = Binder.clearCallingIdentity();
8880 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008881 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8882 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8883 if (!TextUtils.isEmpty(carrierUserAgent)) {
8884 return carrierUserAgent;
8885 }
chen xud5ca2d52019-05-28 15:20:57 -07008886 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8887 .getString(com.android.internal.R.string.config_mms_user_agent);
8888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
8891 }
Jack Yub07d4972019-05-28 16:12:25 -07008892
8893 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008894 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8895 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8896
8897 final long identity = Binder.clearCallingIdentity();
8898 try {
8899 Phone phone = getPhone(subscriptionId);
8900 if (phone == null) return false;
8901
8902 switch (policy) {
8903 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8904 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8905 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8906 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8907 default:
8908 throw new IllegalArgumentException(policy + " is not a valid policy");
8909 }
8910 } finally {
8911 Binder.restoreCallingIdentity(identity);
8912 }
8913 }
8914
8915 @Override
8916 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8917 boolean enabled) {
8918 enforceModifyPermission();
8919
8920 final long identity = Binder.clearCallingIdentity();
8921 try {
8922 Phone phone = getPhone(subscriptionId);
8923 if (phone == null) return;
8924
8925 switch (policy) {
8926 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8927 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8928 break;
8929 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8930 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
8931 break;
8932 default:
8933 throw new IllegalArgumentException(policy + " is not a valid policy");
8934 }
8935 } finally {
8936 Binder.restoreCallingIdentity(identity);
8937 }
8938 }
8939
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008940 /**
Hall Liub48cf452020-09-25 11:13:49 -07008941 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008942 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8943 * otherwise.
8944 */
8945 @Override
8946 public void setCepEnabled(boolean isCepEnabled) {
8947 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8948
8949 final long identity = Binder.clearCallingIdentity();
8950 try {
8951 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8952 for (Phone phone : PhoneFactory.getPhones()) {
8953 Phone defaultPhone = phone.getImsPhone();
8954 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8955 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8956 ImsPhoneCallTracker imsPhoneCallTracker =
8957 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8958 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8959 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8960 + imsPhone.getMsisdn());
8961 }
8962 }
8963 } finally {
8964 Binder.restoreCallingIdentity(identity);
8965 }
8966 }
allenwtsu46dcc572020-01-08 18:24:03 +08008967
8968 /**
8969 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8970 *
8971 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8972 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8973 * before being read.
8974 */
8975 @Override
8976 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8977 isCompressed) {
8978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8979 mApp, subId, "notifyRcsAutoConfigurationReceived");
8980 try {
8981 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8982 if (configBinder == null) {
8983 Rlog.e(LOG_TAG, "null result for getImsConfig");
8984 } else {
8985 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8986 }
8987 } catch (RemoteException e) {
8988 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8989 }
8990 }
zoey chenf95ca592019-12-30 16:11:23 +08008991
8992 @Override
8993 public boolean isIccLockEnabled(int subId) {
8994 enforceReadPrivilegedPermission("isIccLockEnabled");
8995
8996 // Now that all security checks passes, perform the operation as ourselves.
8997 final long identity = Binder.clearCallingIdentity();
8998 try {
8999 Phone phone = getPhone(subId);
9000 if (phone != null && phone.getIccCard() != null) {
9001 return phone.getIccCard().getIccLockEnabled();
9002 } else {
9003 return false;
9004 }
9005 } finally {
9006 Binder.restoreCallingIdentity(identity);
9007 }
9008 }
9009
9010 /**
zoey chene02881a2019-12-30 16:11:23 +08009011 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009012 *
zoey chene02881a2019-12-30 16:11:23 +08009013 * @return an integer representing the status of IccLock enabled or disabled in the following
9014 * three cases:
9015 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9016 * successfully.
9017 * - Positive number and zero for remaining password attempts.
9018 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009019 *
9020 */
9021 @Override
9022 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9023 enforceModifyPermission();
9024
9025 Phone phone = getPhone(subId);
9026 if (phone == null) {
9027 return 0;
9028 }
9029 // Now that all security checks passes, perform the operation as ourselves.
9030 final long identity = Binder.clearCallingIdentity();
9031 try {
9032 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9033 new Pair<Boolean, String>(enabled, password), phone, null);
9034 return attemptsRemaining;
9035
9036 } catch (Exception e) {
9037 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9038 } finally {
9039 Binder.restoreCallingIdentity(identity);
9040 }
9041 return 0;
9042 }
9043
9044 /**
9045 * Change the ICC password used in ICC pin lock.
9046 *
zoey chene02881a2019-12-30 16:11:23 +08009047 * @return an integer representing the status of IccLock changed in the following three cases:
9048 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9049 * - Positive number and zero for remaining password attempts.
9050 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009051 *
9052 */
9053 @Override
9054 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9055 enforceModifyPermission();
9056
9057 Phone phone = getPhone(subId);
9058 if (phone == null) {
9059 return 0;
9060 }
9061 // Now that all security checks passes, perform the operation as ourselves.
9062 final long identity = Binder.clearCallingIdentity();
9063 try {
9064 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9065 new Pair<String, String>(oldPassword, newPassword), phone, null);
9066 return attemptsRemaining;
9067
9068 } catch (Exception e) {
9069 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9070 } finally {
9071 Binder.restoreCallingIdentity(identity);
9072 }
9073 return 0;
9074 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009075
Peter Wangdafb9ac2020-01-15 14:13:38 -08009076 /**
9077 * Request for receiving user activity notification
9078 */
9079 @Override
9080 public void requestUserActivityNotification() {
9081 if (!mNotifyUserActivity.get()
9082 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9083 mNotifyUserActivity.set(true);
9084 }
9085 }
9086
9087 /**
9088 * Called when userActivity is signalled in the power manager.
9089 * This is safe to call from any thread, with any window manager locks held or not.
9090 */
9091 @Override
9092 public void userActivity() {
9093 // ***************************************
9094 // * Inherited from PhoneWindowManager *
9095 // ***************************************
9096 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9097 // WITH ITS LOCKS HELD.
9098 //
9099 // This code must be VERY careful about the locks
9100 // it acquires.
9101 // In fact, the current code acquires way too many,
9102 // and probably has lurking deadlocks.
9103
9104 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9105 throw new SecurityException("Only the OS may call notifyUserActivity()");
9106 }
9107
9108 if (mNotifyUserActivity.getAndSet(false)) {
9109 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9110 USER_ACTIVITY_NOTIFICATION_DELAY);
9111 }
9112 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009113
Malcolm Chen884180b2020-04-13 11:59:40 -07009114 @Override
9115 public boolean canConnectTo5GInDsdsMode() {
9116 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9117 }
Jack Yud10cdd42020-09-28 20:28:01 -07009118
9119 @Override
9120 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9121 String callingFeatureId) {
9122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9123 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9124 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9125 }
9126
9127 Phone phone = getPhone(subId);
9128 if (phone == null) {
9129 throw new RuntimeException("phone is not available");
9130 }
9131 // Now that all security checks passes, perform the operation as ourselves.
9132 final long identity = Binder.clearCallingIdentity();
9133 try {
9134 return phone.getEquivalentHomePlmns();
9135 } finally {
9136 Binder.restoreCallingIdentity(identity);
9137 }
9138 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009139
9140 /**
9141 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9142 * requested radio power state will actually be set. See {@link
9143 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9144 *
9145 * @param subId the subscription ID of the phone requesting to set the radio power state.
9146 * @param enable {@code true} if trying to turn radio on.
9147 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9148 * false}.
9149 */
9150 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9151 Phone phone = getPhone(subId);
9152 if (phone != null) {
9153 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9154 return true;
9155 }
9156 return false;
9157 }
9158
9159 private int handleDataThrottlingRequest(int subId,
9160 DataThrottlingRequest dataThrottlingRequest) {
9161 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9162 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9163 if (!setRadioPowerForThermal(subId, true)) {
9164 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9165 }
9166
9167 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9168
9169 int thermalMitigationResult =
9170 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9171 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9172 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9173 }
9174 return thermalMitigationResult;
9175 }
9176
9177 /**
9178 * Thermal mitigation request to control functionalities at modem.
9179 *
9180 * @param subId the id of the subscription.
9181 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9182 *
9183 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9184 */
9185 @Override
9186 @ThermalMitigationResult
9187 public int sendThermalMitigationRequest(
9188 int subId,
9189 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9190 enforceModifyPermission();
9191
9192 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9193 final long identity = Binder.clearCallingIdentity();
9194
9195 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9196 try {
9197 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9198 switch (thermalMitigationAction) {
9199 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9200 thermalMitigationResult =
9201 handleDataThrottlingRequest(subId,
9202 thermalMitigationRequest.getDataThrottlingRequest());
9203 break;
9204 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9205 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9206 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9207 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9208 }
9209
9210 // Ensure that radio is on. If not able to power on due to phone being
9211 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9212 if (!setRadioPowerForThermal(subId, true)) {
9213 thermalMitigationResult =
9214 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9215 break;
9216 }
9217
9218 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9219 false);
9220 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9221 break;
9222 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9223 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9224 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9225 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9226 }
9227
9228 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9229 if (registry != null) {
9230 TelephonyConnectionService service =
9231 registry.getTelephonyConnectionService();
9232 Phone phone = getPhone(subId);
9233 if (phone == null) {
9234 thermalMitigationResult =
9235 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9236 break;
9237 }
9238
9239 if (PhoneConstantConversions.convertCallState(phone.getState())
9240 != TelephonyManager.CALL_STATE_IDLE
9241 || phone.isInEmergencySmsMode() || phone.isInEcm()
9242 || (service != null && service.isEmergencyCallPending())) {
9243 String errorMessage = "Phone state is not valid. call state = "
9244 + PhoneConstantConversions.convertCallState(phone.getState())
9245 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9246 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9247 errorMessage += service == null
9248 ? " TelephonyConnectionService is null"
9249 : " isEmergencyCallPending = "
9250 + service.isEmergencyCallPending();
9251 Log.e(LOG_TAG, errorMessage);
9252 thermalMitigationResult =
9253 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9254 break;
9255 }
9256 } else {
9257 thermalMitigationResult =
9258 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9259 break;
9260 }
9261
9262 // Turn radio off. If not able to power off due to phone being unavailable,
9263 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9264 if (!setRadioPowerForThermal(subId, false)) {
9265 thermalMitigationResult =
9266 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9267 break;
9268 }
9269 thermalMitigationResult =
9270 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9271 break;
9272 default:
9273 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9274 + "not exist. Requested action: " + thermalMitigationAction);
9275 }
9276 } catch (IllegalArgumentException e) {
9277 throw e;
9278 } catch (Exception e) {
9279 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9280 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9281 } finally {
9282 Binder.restoreCallingIdentity(identity);
9283 }
9284
9285 if (DBG) {
9286 log("thermalMitigationRequest returning with thermalMitigationResult: "
9287 + thermalMitigationResult);
9288 }
9289
9290 return thermalMitigationResult;
9291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009292}