blob: 3e608d2da8c3c759347d0ddf6e08a9331a1290fc [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;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080047import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080050import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070055import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070058import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090061import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080066import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080067import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070068import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080078import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070079import android.telephony.IBootstrapAuthenticationCallback;
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;
Daniel Bright74f1ca82020-11-13 11:49:37 -080090import android.telephony.RadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080092import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080093import android.telephony.SignalStrengthUpdateRequest;
94import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080095import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080096import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080097import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070098import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800100import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800101import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800102import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000103import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700104import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700105import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800106import android.telephony.data.ApnSetting;
107import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700108import android.telephony.gba.GbaAuthRequest;
109import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700110import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000112import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-10-22 17:36:18 -0700113import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700114import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800115import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700116import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800117import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700118import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000119import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700120import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800122import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800123import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800124import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700127import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800129import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130
Andrew Lee312e8172014-10-23 17:01:36 -0700131import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800132import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800133import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700134import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700135import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700136import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800137import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700138import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800140import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700141import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700142import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800143import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800144import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700145import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700146import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800147import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800149import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700151import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700152import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700154import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800155import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700156import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700157import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700158import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700159import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700160import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700161import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700162import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800164import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800165import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700167import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800168import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700169import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800170import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700171import com.android.internal.telephony.imsphone.ImsPhone;
172import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800173import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900174import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700175import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800176import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800178import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700179import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700181import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800182import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000183import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800184import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700185import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700186import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800187import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700188import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700189import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800190import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700191import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700192import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800193import com.android.services.telephony.TelecomAccountRegistry;
194import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800195import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800196
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700197import java.io.FileDescriptor;
198import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800200import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800201import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800202import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800203import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100204import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800205import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700206import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800207import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800208import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800209import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800210import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211
212/**
213 * Implementation of the ITelephony interface.
214 */
Santos Cordon117fee72014-05-16 17:56:12 -0700215public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216 private static final String LOG_TAG = "PhoneInterfaceManager";
217 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
218 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800219 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220
221 // Message codes used with mMainThreadHandler
222 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700223 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
224 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700225 private static final int CMD_OPEN_CHANNEL = 9;
226 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
227 private static final int CMD_CLOSE_CHANNEL = 11;
228 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800229 private static final int CMD_NV_READ_ITEM = 13;
230 private static final int EVENT_NV_READ_ITEM_DONE = 14;
231 private static final int CMD_NV_WRITE_ITEM = 15;
232 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
233 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
234 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700235 private static final int CMD_RESET_MODEM_CONFIG = 19;
236 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800237 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
238 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
239 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
240 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800241 private static final int CMD_SEND_ENVELOPE = 25;
242 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000243 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
244 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700245 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
246 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
247 private static final int CMD_EXCHANGE_SIM_IO = 31;
248 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800249 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
250 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700251 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
252 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700253 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
254 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700255 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
256 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
257 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
258 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700259 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
260 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
261 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
262 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700263 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800264 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
265 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000266 private static final int CMD_SWITCH_SLOTS = 50;
267 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700268 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
269 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
270 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
271 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
272 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
273 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
274 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
275 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700276 private static final int CMD_GET_ALL_CELL_INFO = 60;
277 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
278 private static final int CMD_GET_CELL_LOCATION = 62;
279 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700280 private static final int CMD_MODEM_REBOOT = 64;
281 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700282 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
283 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800284 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
285 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700286 private static final int CMD_GET_MODEM_STATUS = 70;
287 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700288 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
289 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700290 private static final int CMD_ERASE_MODEM_CONFIG = 74;
291 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800292 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
293 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
294 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
295 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800296 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
297 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800298 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800299 private static final int CMD_GET_CALL_FORWARDING = 83;
300 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
301 private static final int CMD_SET_CALL_FORWARDING = 85;
302 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
303 private static final int CMD_GET_CALL_WAITING = 87;
304 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
305 private static final int CMD_SET_CALL_WAITING = 89;
306 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700307 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
308 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
309 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
310 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700311 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
312 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800313 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
314 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800315 private static final int CMD_SET_DATA_THROTTLING = 99;
316 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800317 private static final int CMD_SET_SIM_POWER = 101;
318 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800319 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
320 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
321 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
322 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800324 // Parameters of select command.
325 private static final int SELECT_COMMAND = 0xA4;
326 private static final int SELECT_P1 = 0x04;
327 private static final int SELECT_P2 = 0;
328 private static final int SELECT_P3 = 0x10;
329
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 /** The singleton instance. */
331 private static PhoneInterfaceManager sInstance;
332
Wink Saville3ab207e2014-11-20 13:07:20 -0800333 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800334 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800335 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700336 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800337 private AppOpsManager mAppOps;
338 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800339 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800340 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700341 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
Peter Wangdafb9ac2020-01-15 14:13:38 -0800343 /** User Activity */
344 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800345 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
346
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700347 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
348
Derek Tan97ebb422014-09-05 16:55:38 -0700349 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
350 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800351 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800352 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700353
Michelecea4cf22018-12-21 15:00:11 -0800354 // String to store multi SIM allowed
355 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
356
Derek Tan740e1672017-06-27 14:56:27 -0700357 // The AID of ISD-R.
358 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
359
yinxub1bed742017-04-17 11:45:04 -0700360 private NetworkScanRequestTracker mNetworkScanRequestTracker;
361
David Kelly5e06a7f2018-03-12 14:10:59 +0000362 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
363 private static final int MANUFACTURER_CODE_LENGTH = 8;
364
Jack Nudelman24d51a52020-11-24 12:08:04 -0800365 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
366
Derek Tan89e89d42014-07-08 17:00:10 -0700367 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700368 * Experiment flag to enable erase modem config on reset network, default value is false
369 */
370 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
371 "reset_network_erase_modem_config_enabled";
372
373 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700374 * A request object to use for transmitting data to an ICC.
375 */
376 private static final class IccAPDUArgument {
377 public int channel, cla, command, p1, p2, p3;
378 public String data;
379
380 public IccAPDUArgument(int channel, int cla, int command,
381 int p1, int p2, int p3, String data) {
382 this.channel = channel;
383 this.cla = cla;
384 this.command = command;
385 this.p1 = p1;
386 this.p2 = p2;
387 this.p3 = p3;
388 this.data = data;
389 }
390 }
391
392 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700393 * A request object to use for transmitting data to an ICC.
394 */
395 private static final class ManualNetworkSelectionArgument {
396 public OperatorInfo operatorInfo;
397 public boolean persistSelection;
398
399 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
400 this.operatorInfo = operatorInfo;
401 this.persistSelection = persistSelection;
402 }
403 }
404
405 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
407 * request after sending. The main thread will notify the request when it is complete.
408 */
409 private static final class MainThreadRequest {
410 /** The argument to use for the request */
411 public Object argument;
412 /** The result of the request that is run on the main thread */
413 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800414 // The subscriber id that this request applies to. Defaults to
415 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
416 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417
Nathan Harold92bed182018-10-12 18:16:49 -0700418 // In cases where subId is unavailable, the caller needs to specify the phone.
419 public Phone phone;
420
vagdeviaf9a5b92018-08-15 16:01:53 -0700421 public WorkSource workSource;
422
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 public MainThreadRequest(Object argument) {
424 this.argument = argument;
425 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800426
Nathan Harold92bed182018-10-12 18:16:49 -0700427 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
428 this.argument = argument;
429 if (phone != null) {
430 this.phone = phone;
431 }
432 this.workSource = workSource;
433 }
434
vagdeviaf9a5b92018-08-15 16:01:53 -0700435 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800436 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800437 if (subId != null) {
438 this.subId = subId;
439 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700440 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 }
443
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800444 private static final class IncomingThirdPartyCallArgs {
445 public final ComponentName component;
446 public final String callId;
447 public final String callerDisplayName;
448
449 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
450 String callerDisplayName) {
451 this.component = component;
452 this.callId = callId;
453 this.callerDisplayName = callerDisplayName;
454 }
455 }
456
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457 /**
458 * A handler that processes messages on the main thread in the phone process. Since many
459 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
460 * inbound binder threads to the main thread in the phone process. The Binder thread
461 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
462 * on, which will be notified when the operation completes and will contain the result of the
463 * request.
464 *
465 * <p>If a MainThreadRequest object is provided in the msg.obj field,
466 * note that request.result must be set to something non-null for the calling thread to
467 * unblock.
468 */
469 private final class MainThreadHandler extends Handler {
470 @Override
471 public void handleMessage(Message msg) {
472 MainThreadRequest request;
473 Message onCompleted;
474 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800475 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800477 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478
479 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 case CMD_HANDLE_USSD_REQUEST: {
481 request = (MainThreadRequest) msg.obj;
482 final Phone phone = getPhoneFromRequest(request);
483 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
484 String ussdRequest = ussdObject.first;
485 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700486
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 if (!isUssdApiAllowed(request.subId)) {
488 // Carrier does not support use of this API, return failure.
489 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
490 UssdResponse response = new UssdResponse(ussdRequest, null);
491 Bundle returnData = new Bundle();
492 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
493 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700494
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 request.result = true;
496 notifyRequester(request);
497 return;
498 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700499
Pengquan Menga1bb6272018-09-06 09:59:22 -0700500 try {
501 request.result = phone != null
502 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
503 } catch (CallStateException cse) {
504 request.result = false;
505 }
506 // Wake up the requesting thread
507 notifyRequester(request);
508 break;
pkanwar32d516d2016-10-14 19:37:38 -0700509 }
510
Yorke Lee716f67e2015-06-17 15:39:16 -0700511 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700513 final Phone phone = getPhoneFromRequest(request);
514 request.result = phone != null ?
515 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
516 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700517 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700519 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700523 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800525 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 if (uiccCard == null) {
527 loge("iccTransmitApduLogicalChannel: No UICC");
528 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
532 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 iccArgument.channel, iccArgument.cla, iccArgument.command,
535 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700536 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700538 break;
539
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 ar = (AsyncResult) msg.obj;
542 request = (MainThreadRequest) ar.userObj;
543 if (ar.exception == null && ar.result != null) {
544 request.result = ar.result;
545 } else {
546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
547 if (ar.result == null) {
548 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800549 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800551 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 } else {
553 loge("iccTransmitApduLogicalChannel: Unknown exception");
554 }
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 break;
558
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
560 request = (MainThreadRequest) msg.obj;
561 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 if (uiccCard == null) {
564 loge("iccTransmitApduBasicChannel: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
569 request);
570 uiccCard.iccTransmitApduBasicChannel(
571 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
572 iccArgument.p3, iccArgument.data, onCompleted);
573 }
574 break;
575
576 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
577 ar = (AsyncResult) msg.obj;
578 request = (MainThreadRequest) ar.userObj;
579 if (ar.exception == null && ar.result != null) {
580 request.result = ar.result;
581 } else {
582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
583 if (ar.result == null) {
584 loge("iccTransmitApduBasicChannel: Empty response");
585 } else if (ar.exception instanceof CommandException) {
586 loge("iccTransmitApduBasicChannel: CommandException: " +
587 ar.exception);
588 } else {
589 loge("iccTransmitApduBasicChannel: Unknown exception");
590 }
591 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 break;
594
595 case CMD_EXCHANGE_SIM_IO:
596 request = (MainThreadRequest) msg.obj;
597 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800598 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 if (uiccCard == null) {
600 loge("iccExchangeSimIO: No UICC");
601 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700602 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 } else {
604 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
605 request);
606 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
607 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
608 iccArgument.data, onCompleted);
609 }
610 break;
611
612 case EVENT_EXCHANGE_SIM_IO_DONE:
613 ar = (AsyncResult) msg.obj;
614 request = (MainThreadRequest) ar.userObj;
615 if (ar.exception == null && ar.result != null) {
616 request.result = ar.result;
617 } else {
618 request.result = new IccIoResult(0x6f, 0, (byte[])null);
619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 break;
622
Derek Tan4d5e5c12014-02-04 11:54:58 -0800623 case CMD_SEND_ENVELOPE:
624 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("sendEnvelopeWithStatus: No UICC");
628 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
632 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
633 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800634 break;
635
636 case EVENT_SEND_ENVELOPE_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700639 if (ar.exception == null && ar.result != null) {
640 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800641 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700642 request.result = new IccIoResult(0x6F, 0, (byte[])null);
643 if (ar.result == null) {
644 loge("sendEnvelopeWithStatus: Empty response");
645 } else if (ar.exception instanceof CommandException) {
646 loge("sendEnvelopeWithStatus: CommandException: " +
647 ar.exception);
648 } else {
649 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
650 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800651 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800653 break;
654
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 case CMD_OPEN_CHANNEL:
656 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800657 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800658 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700659 if (uiccCard == null) {
660 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800661 request.result = new IccOpenLogicalChannelResponse(-1,
662 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700663 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700664 } else {
665 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800666 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
667 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 break;
670
671 case EVENT_OPEN_CHANNEL_DONE:
672 ar = (AsyncResult) msg.obj;
673 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700674 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700676 int[] result = (int[]) ar.result;
677 int channelId = result[0];
678 byte[] selectResponse = null;
679 if (result.length > 1) {
680 selectResponse = new byte[result.length - 1];
681 for (int i = 1; i < result.length; ++i) {
682 selectResponse[i - 1] = (byte) result[i];
683 }
684 }
685 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700686 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 if (ar.result == null) {
689 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 if (ar.exception != null) {
692 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
693 }
694
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700695 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700696 if (ar.exception instanceof CommandException) {
697 CommandException.Error error =
698 ((CommandException) (ar.exception)).getCommandError();
699 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700700 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700701 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700702 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 }
704 }
705 openChannelResp = new IccOpenLogicalChannelResponse(
706 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700708 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700709 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 break;
711
712 case CMD_CLOSE_CHANNEL:
713 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800714 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700715 if (uiccCard == null) {
716 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900717 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700718 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 } else {
720 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
721 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
722 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700723 break;
724
725 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800726 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
727 break;
728
729 case CMD_NV_READ_ITEM:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800732 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
733 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800734 break;
735
736 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800739 if (ar.exception == null && ar.result != null) {
740 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800742 request.result = "";
743 if (ar.result == null) {
744 loge("nvReadItem: Empty response");
745 } else if (ar.exception instanceof CommandException) {
746 loge("nvReadItem: CommandException: " +
747 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700748 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800749 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 }
751 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 break;
754
Jake Hambye994d462014-02-03 13:10:13 -0800755 case CMD_NV_WRITE_ITEM:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
758 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800759 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700760 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800761 break;
762
763 case EVENT_NV_WRITE_ITEM_DONE:
764 handleNullReturnEvent(msg, "nvWriteItem");
765 break;
766
767 case CMD_NV_WRITE_CDMA_PRL:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800770 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800771 break;
772
773 case EVENT_NV_WRITE_CDMA_PRL_DONE:
774 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
775 break;
776
chen xu6dac5ab2018-10-26 17:39:23 -0700777 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800778 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700779 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800780 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800781 break;
782
chen xu6dac5ab2018-10-26 17:39:23 -0700783 case EVENT_RESET_MODEM_CONFIG_DONE:
784 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700787 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
790 request);
791 Phone phone = getPhoneFromRequest(request);
792 if (phone != null) {
793 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
794 } else {
795 loge("isNRDualConnectivityEnabled: No phone object");
796 request.result = false;
797 notifyRequester(request);
798 }
799 break;
800 }
801
802 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 if (ar.exception == null && ar.result != null) {
806 request.result = ar.result;
807 } else {
808 // request.result must be set to something non-null
809 // for the calling thread to unblock
810 if (request.result != null) {
811 request.result = ar.result;
812 } else {
813 request.result = false;
814 }
815 if (ar.result == null) {
816 loge("isNRDualConnectivityEnabled: Empty response");
817 } else if (ar.exception instanceof CommandException) {
818 loge("isNRDualConnectivityEnabled: CommandException: "
819 + ar.exception);
820 } else {
821 loge("isNRDualConnectivityEnabled: Unknown exception");
822 }
823 }
824 notifyRequester(request);
825 break;
826
827 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
828 request = (MainThreadRequest) msg.obj;
829 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
830 Phone phone = getPhoneFromRequest(request);
831 if (phone != null) {
832 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
833 request.workSource);
834 } else {
835 loge("enableNrDualConnectivity: No phone object");
836 request.result =
837 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
838 notifyRequester(request);
839 }
840 break;
841 }
842
843 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
846 if (ar.exception == null) {
847 request.result =
848 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
849 } else {
850 request.result =
851 TelephonyManager
852 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
853 if (ar.exception instanceof CommandException) {
854 CommandException.Error error =
855 ((CommandException) (ar.exception)).getCommandError();
856 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
857 request.result =
858 TelephonyManager
859 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
860 }
861 loge("enableNrDualConnectivity" + ": CommandException: "
862 + ar.exception);
863 } else {
864 loge("enableNrDualConnectivity" + ": Unknown exception");
865 }
866 }
867 notifyRequester(request);
868 break;
869 }
870
Jake Hamby7c27be32014-03-03 13:25:59 -0800871 case CMD_GET_PREFERRED_NETWORK_TYPE:
872 request = (MainThreadRequest) msg.obj;
873 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700874 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800875 break;
876
877 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
878 ar = (AsyncResult) msg.obj;
879 request = (MainThreadRequest) ar.userObj;
880 if (ar.exception == null && ar.result != null) {
881 request.result = ar.result; // Integer
882 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530883 // request.result must be set to something non-null
884 // for the calling thread to unblock
885 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800886 if (ar.result == null) {
887 loge("getPreferredNetworkType: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("getPreferredNetworkType: CommandException: " +
890 ar.exception);
891 } else {
892 loge("getPreferredNetworkType: Unknown exception");
893 }
894 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700895 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800896 break;
897
898 case CMD_SET_PREFERRED_NETWORK_TYPE:
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
901 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700902 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 break;
904
905 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
906 handleNullReturnEvent(msg, "setPreferredNetworkType");
907 break;
908
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000909 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
910 request = (MainThreadRequest)msg.obj;
911 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800912 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000913 break;
914
915 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
916 ar = (AsyncResult)msg.obj;
917 request = (MainThreadRequest)ar.userObj;
918 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700919 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000920 break;
921
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800922 case CMD_SET_VOICEMAIL_NUMBER:
923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
925 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800926 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
927 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800928 break;
929
930 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
931 handleNullReturnEvent(msg, "setVoicemailNumber");
932 break;
933
Stuart Scott54788802015-03-30 13:18:01 -0700934 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
935 request = (MainThreadRequest) msg.obj;
936 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
937 request);
938 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
939 break;
940
941 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
942 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
943 break;
944
Shishir Agrawal302c8692015-06-19 13:49:39 -0700945 case CMD_PERFORM_NETWORK_SCAN:
946 request = (MainThreadRequest) msg.obj;
947 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
948 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
949 break;
950
Hall Liua1acea22020-09-18 19:04:59 -0700951 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800952 request = (MainThreadRequest) msg.obj;
953 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700954 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
955 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
956 request.argument;
957 int callForwardingReason = args.first;
958 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800959 break;
Hall Liua1acea22020-09-18 19:04:59 -0700960 }
961 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700964 TelephonyManager.CallForwardingInfoCallback callback =
965 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
966 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800967 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700968 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800969 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
970 for (CallForwardInfo callForwardInfo : callForwardInfos) {
971 // Service Class is a bit mask per 3gpp 27.007. Search for
972 // any service for voice call.
973 if ((callForwardInfo.serviceClass
974 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700975 callForwardingInfo = new CallForwardingInfo(true,
976 callForwardInfo.reason,
977 callForwardInfo.number,
978 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800979 break;
980 }
981 }
982 // Didn't find a call forward info for voice call.
983 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700984 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
985 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800986 }
Hall Liua1acea22020-09-18 19:04:59 -0700987 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800988 } else {
989 if (ar.result == null) {
990 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
991 }
992 if (ar.exception != null) {
993 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
994 }
Hall Liuae527aa2020-09-29 17:10:18 -0700995 int errorCode = TelephonyManager
996 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800997 if (ar.exception instanceof CommandException) {
998 CommandException.Error error =
999 ((CommandException) (ar.exception)).getCommandError();
1000 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001001 errorCode = TelephonyManager
1002 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001003 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001004 errorCode = TelephonyManager
1005 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001006 }
1007 }
Hall Liua1acea22020-09-18 19:04:59 -07001008 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001009 }
sqian80370722020-01-29 15:02:51 -08001010 break;
Hall Liua1acea22020-09-18 19:04:59 -07001011 }
sqian80370722020-01-29 15:02:51 -08001012
Hall Liua1acea22020-09-18 19:04:59 -07001013 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001014 request = (MainThreadRequest) msg.obj;
1015 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001016 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001017 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001018 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1019 request.argument).first;
1020 request.phone.setCallForwardingOption(
1021 callForwardingInfoToSet.isEnabled()
1022 ? CommandsInterface.CF_ACTION_ENABLE
1023 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001024 callForwardingInfoToSet.getReason(),
1025 callForwardingInfoToSet.getNumber(),
1026 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1027 break;
Hall Liua1acea22020-09-18 19:04:59 -07001028 }
sqian80370722020-01-29 15:02:51 -08001029
Hall Liua1acea22020-09-18 19:04:59 -07001030 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001031 ar = (AsyncResult) msg.obj;
1032 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001033 Consumer<Integer> callback =
1034 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1035 request.argument).second;
1036 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001037 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001038 int errorCode = TelephonyManager.CallForwardingInfoCallback
1039 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001040 if (ar.exception instanceof CommandException) {
1041 CommandException.Error error =
1042 ((CommandException) (ar.exception)).getCommandError();
1043 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001044 errorCode = TelephonyManager.CallForwardingInfoCallback
1045 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001046 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001047 errorCode = TelephonyManager.CallForwardingInfoCallback
1048 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001049 }
1050 }
1051 callback.accept(errorCode);
1052 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001053 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001054 }
sqian80370722020-01-29 15:02:51 -08001055 break;
Hall Liua1acea22020-09-18 19:04:59 -07001056 }
sqian80370722020-01-29 15:02:51 -08001057
Hall Liua1acea22020-09-18 19:04:59 -07001058 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001059 request = (MainThreadRequest) msg.obj;
1060 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1061 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1062 break;
Hall Liua1acea22020-09-18 19:04:59 -07001063 }
sqian80370722020-01-29 15:02:51 -08001064
Hall Liua1acea22020-09-18 19:04:59 -07001065 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001068 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001069 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1070 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001071 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001072 // Service Class is a bit mask per 3gpp 27.007.
1073 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001074 if (callForwardResults.length > 1
1075 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001076 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001077 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001078 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1079 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001080 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001081 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001082 }
1083 } else {
1084 if (ar.result == null) {
1085 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1086 }
1087 if (ar.exception != null) {
1088 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1089 }
1090 if (ar.exception instanceof CommandException) {
1091 CommandException.Error error =
1092 ((CommandException) (ar.exception)).getCommandError();
1093 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1094 callForwardingStatus =
1095 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1096 }
1097 }
1098 }
Hall Liua1acea22020-09-18 19:04:59 -07001099 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001100 break;
Hall Liua1acea22020-09-18 19:04:59 -07001101 }
sqian80370722020-01-29 15:02:51 -08001102
Hall Liua1acea22020-09-18 19:04:59 -07001103 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001104 request = (MainThreadRequest) msg.obj;
1105 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001106 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1107 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001108 break;
Hall Liua1acea22020-09-18 19:04:59 -07001109 }
sqian80370722020-01-29 15:02:51 -08001110
Hall Liua1acea22020-09-18 19:04:59 -07001111 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001112 ar = (AsyncResult) msg.obj;
1113 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001114 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1115 Consumer<Integer> callback =
1116 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1117 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001118 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001119 if (ar.exception instanceof CommandException) {
1120 CommandException.Error error =
1121 ((CommandException) (ar.exception)).getCommandError();
1122 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1123 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1124 } else {
1125 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1126 }
1127 } else {
1128 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1129 }
1130 } else {
1131 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1132 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001133 }
sqian80370722020-01-29 15:02:51 -08001134 break;
Hall Liua1acea22020-09-18 19:04:59 -07001135 }
sqian80370722020-01-29 15:02:51 -08001136
Shishir Agrawal302c8692015-06-19 13:49:39 -07001137 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 CellNetworkScanResult cellScanResult;
1141 if (ar.exception == null && ar.result != null) {
1142 cellScanResult = new CellNetworkScanResult(
1143 CellNetworkScanResult.STATUS_SUCCESS,
1144 (List<OperatorInfo>) ar.result);
1145 } else {
1146 if (ar.result == null) {
1147 loge("getCellNetworkScanResults: Empty response");
1148 }
1149 if (ar.exception != null) {
1150 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1151 }
1152 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1153 if (ar.exception instanceof CommandException) {
1154 CommandException.Error error =
1155 ((CommandException) (ar.exception)).getCommandError();
1156 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1157 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1158 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1159 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1160 }
1161 }
1162 cellScanResult = new CellNetworkScanResult(errorCode, null);
1163 }
1164 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001165 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001166 break;
1167
1168 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1169 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001170 ManualNetworkSelectionArgument selArg =
1171 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001172 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1173 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001174 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1175 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001176 break;
1177
1178 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001179 ar = (AsyncResult) msg.obj;
1180 request = (MainThreadRequest) ar.userObj;
1181 if (ar.exception == null) {
1182 request.result = true;
1183 } else {
1184 request.result = false;
1185 loge("setNetworkSelectionModeManual " + ar.exception);
1186 }
1187 notifyRequester(request);
1188 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001189 break;
1190
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001191 case CMD_GET_MODEM_ACTIVITY_INFO:
1192 request = (MainThreadRequest) msg.obj;
1193 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001194 if (defaultPhone != null) {
1195 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001196 } else {
1197 ResultReceiver result = (ResultReceiver) request.argument;
1198 Bundle bundle = new Bundle();
1199 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1200 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1201 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001202 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001203 break;
1204
1205 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1206 ar = (AsyncResult) msg.obj;
1207 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001208 ResultReceiver result = (ResultReceiver) request.argument;
1209
1210 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001211 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001212 // Update the last modem activity info and the result of the request.
1213 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1214 if (isModemActivityInfoValid(info)) {
1215 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1216 int[] txTimeMs = info.getTransmitTimeMillis();
1217 int[] lastModemTxTimeMs = mLastModemActivityInfo
1218 .getTransmitTimeMillis();
1219 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1220 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1221 }
1222 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1223 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1224 + mLastModemActivityInfo.getSleepTimeMillis());
1225 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1226 + mLastModemActivityInfo.getIdleTimeMillis());
1227 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1228 mLastModemActivityInfo.setReceiveTimeMillis(
1229 info.getReceiveTimeMillis()
1230 + mLastModemActivityInfo.getReceiveTimeMillis());
1231 }
1232 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1233 mLastModemActivityInfo.getSleepTimeMillis(),
1234 mLastModemActivityInfo.getIdleTimeMillis(),
1235 mLastModemActivityInfo.getTransmitTimeMillis(),
1236 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001237 } else {
1238 if (ar.result == null) {
1239 loge("queryModemActivityInfo: Empty response");
1240 } else if (ar.exception instanceof CommandException) {
1241 loge("queryModemActivityInfo: CommandException: " +
1242 ar.exception);
1243 } else {
1244 loge("queryModemActivityInfo: Unknown exception");
1245 }
1246 }
sqian1a1be542020-03-05 11:37:28 -08001247 Bundle bundle = new Bundle();
1248 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1249 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001250 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001251 break;
1252
Meng Wang1a7c35a2016-05-05 20:56:15 -07001253 case CMD_SET_ALLOWED_CARRIERS:
1254 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001255 CarrierRestrictionRules argument =
1256 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001257 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001258 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001259 break;
1260
1261 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1262 ar = (AsyncResult) msg.obj;
1263 request = (MainThreadRequest) ar.userObj;
1264 if (ar.exception == null && ar.result != null) {
1265 request.result = ar.result;
1266 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001267 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1268 if (ar.exception instanceof CommandException) {
1269 loge("setAllowedCarriers: CommandException: " + ar.exception);
1270 CommandException.Error error =
1271 ((CommandException) (ar.exception)).getCommandError();
1272 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1273 request.result =
1274 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1275 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001276 } else {
1277 loge("setAllowedCarriers: Unknown exception");
1278 }
1279 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001280 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001281 break;
1282
1283 case CMD_GET_ALLOWED_CARRIERS:
1284 request = (MainThreadRequest) msg.obj;
1285 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001286 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001287 break;
1288
1289 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1290 ar = (AsyncResult) msg.obj;
1291 request = (MainThreadRequest) ar.userObj;
1292 if (ar.exception == null && ar.result != null) {
1293 request.result = ar.result;
1294 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001295 request.result = new IllegalStateException(
1296 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001297 if (ar.result == null) {
1298 loge("getAllowedCarriers: Empty response");
1299 } else if (ar.exception instanceof CommandException) {
1300 loge("getAllowedCarriers: CommandException: " +
1301 ar.exception);
1302 } else {
1303 loge("getAllowedCarriers: Unknown exception");
1304 }
1305 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001306 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001307 break;
1308
Nathan Haroldb3014052017-01-25 15:57:32 -08001309 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1310 ar = (AsyncResult) msg.obj;
1311 request = (MainThreadRequest) ar.userObj;
1312 if (ar.exception == null && ar.result != null) {
1313 request.result = ar.result;
1314 } else {
1315 request.result = new IllegalArgumentException(
1316 "Failed to retrieve Forbidden Plmns");
1317 if (ar.result == null) {
1318 loge("getForbiddenPlmns: Empty response");
1319 } else {
1320 loge("getForbiddenPlmns: Unknown exception");
1321 }
1322 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001323 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001324 break;
1325
1326 case CMD_GET_FORBIDDEN_PLMNS:
1327 request = (MainThreadRequest) msg.obj;
1328 uiccCard = getUiccCardFromRequest(request);
1329 if (uiccCard == null) {
1330 loge("getForbiddenPlmns() UiccCard is null");
1331 request.result = new IllegalArgumentException(
1332 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001333 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001334 break;
1335 }
1336 Integer appType = (Integer) request.argument;
1337 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1338 if (uiccApp == null) {
1339 loge("getForbiddenPlmns() no app with specified type -- "
1340 + appType);
1341 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001342 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001343 break;
1344 } else {
1345 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1346 + " specified type -- " + appType);
1347 }
1348 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1349 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1350 onCompleted);
1351 break;
1352
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001353 case CMD_SWITCH_SLOTS:
1354 request = (MainThreadRequest) msg.obj;
1355 int[] physicalSlots = (int[]) request.argument;
1356 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1357 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1358 break;
1359
1360 case EVENT_SWITCH_SLOTS_DONE:
1361 ar = (AsyncResult) msg.obj;
1362 request = (MainThreadRequest) ar.userObj;
1363 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001364 notifyRequester(request);
1365 break;
1366 case CMD_GET_NETWORK_SELECTION_MODE:
1367 request = (MainThreadRequest) msg.obj;
1368 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1369 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1370 break;
1371
1372 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1373 ar = (AsyncResult) msg.obj;
1374 request = (MainThreadRequest) ar.userObj;
1375 if (ar.exception != null) {
1376 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1377 } else {
1378 int mode = ((int[]) ar.result)[0];
1379 if (mode == 0) {
1380 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1381 } else {
1382 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1383 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001384 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001385 notifyRequester(request);
1386 break;
1387 case CMD_GET_CDMA_ROAMING_MODE:
1388 request = (MainThreadRequest) msg.obj;
1389 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1390 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1391 break;
1392 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1393 ar = (AsyncResult) msg.obj;
1394 request = (MainThreadRequest) ar.userObj;
1395 if (ar.exception != null) {
1396 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1397 } else {
1398 request.result = ((int[]) ar.result)[0];
1399 }
1400 notifyRequester(request);
1401 break;
1402 case CMD_SET_CDMA_ROAMING_MODE:
1403 request = (MainThreadRequest) msg.obj;
1404 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1405 int mode = (int) request.argument;
1406 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1407 break;
1408 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 request.result = ar.exception == null;
1412 notifyRequester(request);
1413 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001414 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1415 request = (MainThreadRequest) msg.obj;
1416 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1417 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1418 break;
1419 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1420 ar = (AsyncResult) msg.obj;
1421 request = (MainThreadRequest) ar.userObj;
1422 if (ar.exception != null) {
1423 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1424 } else {
1425 request.result = ((int[]) ar.result)[0];
1426 }
1427 notifyRequester(request);
1428 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001429 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1430 request = (MainThreadRequest) msg.obj;
1431 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1432 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001433 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1434 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001435 break;
1436 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1437 ar = (AsyncResult) msg.obj;
1438 request = (MainThreadRequest) ar.userObj;
1439 request.result = ar.exception == null;
1440 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001441 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001442 case CMD_GET_ALL_CELL_INFO:
1443 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001444 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001445 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001446 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001447 case EVENT_GET_ALL_CELL_INFO_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001450 // If a timeout occurs, the response will be null
1451 request.result = (ar.exception == null && ar.result != null)
1452 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001453 synchronized (request) {
1454 request.notifyAll();
1455 }
1456 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001457 case CMD_REQUEST_CELL_INFO_UPDATE:
1458 request = (MainThreadRequest) msg.obj;
1459 request.phone.requestCellInfoUpdate(request.workSource,
1460 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1461 break;
1462 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1463 ar = (AsyncResult) msg.obj;
1464 request = (MainThreadRequest) ar.userObj;
1465 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1466 try {
1467 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001468 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001469 cb.onError(
1470 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1471 ar.exception.getClass().getName(),
1472 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001473 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001474 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001475 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001476 } else {
1477 // use the result as returned
1478 cb.onCellInfo((List<CellInfo>) ar.result);
1479 }
1480 } catch (RemoteException re) {
1481 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1482 }
1483 break;
Sarah Chincc055732020-11-18 13:39:35 -08001484 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001485 request = (MainThreadRequest) msg.obj;
1486 WorkSource ws = (WorkSource) request.argument;
1487 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001488 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 break;
Sarah Chincc055732020-11-18 13:39:35 -08001490 }
1491 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 ar = (AsyncResult) msg.obj;
1493 request = (MainThreadRequest) ar.userObj;
1494 if (ar.exception == null) {
1495 request.result = ar.result;
1496 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001497 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001498 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001499 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001500 }
1501
1502 synchronized (request) {
1503 request.notifyAll();
1504 }
1505 break;
Sarah Chincc055732020-11-18 13:39:35 -08001506 }
chen xu6dac5ab2018-10-26 17:39:23 -07001507 case CMD_MODEM_REBOOT:
1508 request = (MainThreadRequest) msg.obj;
1509 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001510 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001511 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001512 case EVENT_CMD_MODEM_REBOOT_DONE:
1513 handleNullReturnEvent(msg, "rebootModem");
1514 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001515 case CMD_REQUEST_ENABLE_MODEM:
1516 request = (MainThreadRequest) msg.obj;
1517 boolean enable = (boolean) request.argument;
1518 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001519 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001520 PhoneConfigurationManager.getInstance()
1521 .enablePhone(request.phone, enable, onCompleted);
1522 break;
1523 case EVENT_ENABLE_MODEM_DONE:
1524 ar = (AsyncResult) msg.obj;
1525 request = (MainThreadRequest) ar.userObj;
1526 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001527 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001528 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001529 if ((boolean) request.result) {
1530 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1531 updateModemStateMetrics();
1532 } else {
1533 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1534 + ar.exception);
1535 }
1536 notifyRequester(request);
1537 break;
1538 case CMD_GET_MODEM_STATUS:
1539 request = (MainThreadRequest) msg.obj;
1540 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1541 PhoneConfigurationManager.getInstance()
1542 .getPhoneStatusFromModem(request.phone, onCompleted);
1543 break;
1544 case EVENT_GET_MODEM_STATUS_DONE:
1545 ar = (AsyncResult) msg.obj;
1546 request = (MainThreadRequest) ar.userObj;
1547 int id = request.phone.getPhoneId();
1548 if (ar.exception == null && ar.result != null) {
1549 request.result = ar.result;
1550 //update the cache as modem status has changed
1551 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1552 (boolean) request.result);
1553 } else {
1554 // Return true if modem status cannot be retrieved. For most cases,
1555 // modem status is on. And for older version modems, GET_MODEM_STATUS
1556 // and disable modem are not supported. Modem is always on.
1557 // TODO: this should be fixed in R to support a third
1558 // status UNKNOWN b/131631629
1559 request.result = true;
1560 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1561 + ar.exception);
1562 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001563 notifyRequester(request);
1564 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001565 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1566 request = (MainThreadRequest) msg.obj;
1567 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1568 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1569 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1570 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1571 break;
1572 }
1573 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1574 ar = (AsyncResult) msg.obj;
1575 request = (MainThreadRequest) ar.userObj;
1576 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1577 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1578 args.second.accept(ar.exception == null);
1579 notifyRequester(request);
1580 break;
1581 }
Sarah Chincc055732020-11-18 13:39:35 -08001582 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1583 request = (MainThreadRequest) msg.obj;
1584 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1585 Phone phone = getPhoneFromRequest(request);
1586 if (phone != null) {
1587 phone.getSystemSelectionChannels(onCompleted);
1588 } else {
1589 loge("getSystemSelectionChannels: No phone object");
1590 request.result = new ArrayList<RadioAccessSpecifier>();
1591 notifyRequester(request);
1592 }
1593 break;
1594 }
1595 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1596 ar = (AsyncResult) msg.obj;
1597 request = (MainThreadRequest) ar.userObj;
1598 if (ar.exception == null && ar.result != null) {
1599 request.result = ar.result;
1600 } else {
1601 request.result = new IllegalArgumentException(
1602 "Failed to retrieve system selection channels");
1603 if (ar.result == null) {
1604 loge("getSystemSelectionChannels: Empty response");
1605 } else {
1606 loge("getSystemSelectionChannels: Unknown exception");
1607 }
1608 }
1609 notifyRequester(request);
1610 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001611 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1612 ar = (AsyncResult) msg.obj;
1613 request = (MainThreadRequest) ar.userObj;
1614 if (ar.exception == null && ar.result != null) {
1615 request.result = ar.result;
1616 } else {
1617 request.result = -1;
1618 loge("Failed to set Forbidden Plmns");
1619 if (ar.result == null) {
1620 loge("setForbidenPlmns: Empty response");
1621 } else if (ar.exception != null) {
1622 loge("setForbiddenPlmns: Exception: " + ar.exception);
1623 request.result = -1;
1624 } else {
1625 loge("setForbiddenPlmns: Unknown exception");
1626 }
1627 }
1628 notifyRequester(request);
1629 break;
1630 case CMD_SET_FORBIDDEN_PLMNS:
1631 request = (MainThreadRequest) msg.obj;
1632 uiccCard = getUiccCardFromRequest(request);
1633 if (uiccCard == null) {
1634 loge("setForbiddenPlmns: UiccCard is null");
1635 request.result = -1;
1636 notifyRequester(request);
1637 break;
1638 }
1639 Pair<Integer, List<String>> setFplmnsArgs =
1640 (Pair<Integer, List<String>>) request.argument;
1641 appType = setFplmnsArgs.first;
1642 List<String> fplmns = setFplmnsArgs.second;
1643 uiccApp = uiccCard.getApplicationByType(appType);
1644 if (uiccApp == null) {
1645 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1646 request.result = -1;
1647 loge("Failed to get UICC App");
1648 notifyRequester(request);
1649 } else {
1650 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1651 ((SIMRecords) uiccApp.getIccRecords())
1652 .setForbiddenPlmns(onCompleted, fplmns);
1653 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001654 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001655 case CMD_ERASE_MODEM_CONFIG:
1656 request = (MainThreadRequest) msg.obj;
1657 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1658 defaultPhone.eraseModemConfig(onCompleted);
1659 break;
1660 case EVENT_ERASE_MODEM_CONFIG_DONE:
1661 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001662 break;
zoey chenf95ca592019-12-30 16:11:23 +08001663
1664 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1665 request = (MainThreadRequest) msg.obj;
1666 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1667 Pair<String, String> changed = (Pair<String, String>) request.argument;
1668 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1669 changed.first, changed.second, onCompleted);
1670 break;
1671 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1672 ar = (AsyncResult) msg.obj;
1673 request = (MainThreadRequest) ar.userObj;
1674 if (ar.exception == null) {
1675 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1676 } else {
1677 request.result = msg.arg1;
1678 }
1679 notifyRequester(request);
1680 break;
1681
1682 case CMD_SET_ICC_LOCK_ENABLED:
1683 request = (MainThreadRequest) msg.obj;
1684 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1685 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1686 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1687 enabled.first, enabled.second, onCompleted);
1688 break;
1689 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1690 ar = (AsyncResult) msg.obj;
1691 request = (MainThreadRequest) ar.userObj;
1692 if (ar.exception == null) {
1693 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1694 } else {
1695 request.result = msg.arg1;
1696 }
1697 notifyRequester(request);
1698 break;
1699
Peter Wangdafb9ac2020-01-15 14:13:38 -08001700 case MSG_NOTIFY_USER_ACTIVITY:
1701 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001702 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001703 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1704 getDefaultPhone().getContext().sendBroadcastAsUser(
1705 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1706 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001707
1708 case CMD_SET_DATA_THROTTLING: {
1709 request = (MainThreadRequest) msg.obj;
1710 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1711 DataThrottlingRequest dataThrottlingRequest =
1712 (DataThrottlingRequest) request.argument;
1713 Phone phone = getPhoneFromRequest(request);
1714 if (phone != null) {
1715 phone.setDataThrottling(onCompleted,
1716 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1717 dataThrottlingRequest.getCompletionDurationMillis());
1718 } else {
1719 loge("setDataThrottling: No phone object");
1720 request.result =
1721 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1722 notifyRequester(request);
1723 }
1724
1725 break;
1726 }
1727 case EVENT_SET_DATA_THROTTLING_DONE:
1728 ar = (AsyncResult) msg.obj;
1729 request = (MainThreadRequest) ar.userObj;
1730
1731 if (ar.exception == null) {
1732 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1733 } else if (ar.exception instanceof CommandException) {
1734 loge("setDataThrottling: CommandException: " + ar.exception);
1735 CommandException.Error error =
1736 ((CommandException) (ar.exception)).getCommandError();
1737
1738 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1739 request.result = TelephonyManager
1740 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1741 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1742 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1743 } else {
1744 request.result =
1745 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1746 }
1747 } else {
1748 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1749 }
1750 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1751 notifyRequester(request);
1752 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001753
1754 case CMD_SET_SIM_POWER: {
1755 request = (MainThreadRequest) msg.obj;
1756 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1757 request = (MainThreadRequest) msg.obj;
1758 int stateToSet =
1759 ((Pair<Integer, IIntegerConsumer>)
1760 request.argument).first;
1761 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1762 break;
1763 }
1764 case EVENT_SET_SIM_POWER_DONE: {
1765 ar = (AsyncResult) msg.obj;
1766 request = (MainThreadRequest) ar.userObj;
1767 IIntegerConsumer callback =
1768 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1769 if (ar.exception != null) {
1770 loge("setSimPower exception: " + ar.exception);
1771 int errorCode = TelephonyManager.CallForwardingInfoCallback
1772 .RESULT_ERROR_UNKNOWN;
1773 if (ar.exception instanceof CommandException) {
1774 CommandException.Error error =
1775 ((CommandException) (ar.exception)).getCommandError();
1776 if (error == CommandException.Error.SIM_ERR) {
1777 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1778 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1779 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1780 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1781 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1782 } else {
1783 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1784 }
1785 }
1786 try {
1787 callback.accept(errorCode);
1788 } catch (RemoteException e) {
1789 // Ignore if the remote process is no longer available to call back.
1790 Log.w(LOG_TAG, "setSimPower: callback not available.");
1791 }
1792 } else {
1793 try {
1794 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1795 } catch (RemoteException e) {
1796 // Ignore if the remote process is no longer available to call back.
1797 Log.w(LOG_TAG, "setSimPower: callback not available.");
1798 }
1799 }
1800 break;
1801 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001802 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1803 request = (MainThreadRequest) msg.obj;
1804
1805 final Phone phone = getPhoneFromRequest(request);
1806 if (phone == null || phone.getServiceStateTracker() == null) {
1807 request.result = new IllegalStateException("Phone or SST is null");
1808 notifyRequester(request);
1809 break;
1810 }
1811
1812 Pair<Integer, SignalStrengthUpdateRequest> pair =
1813 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1814 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1815 request);
1816 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1817 request.subId, pair.first /*callingUid*/,
1818 pair.second /*request*/, onCompleted);
1819 break;
1820 }
1821 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1822 ar = (AsyncResult) msg.obj;
1823 request = (MainThreadRequest) ar.userObj;
1824 // request.result will be the exception of ar if present, true otherwise.
1825 // Be cautious not to leave result null which will wait() forever
1826 request.result = ar.exception != null ? ar.exception : true;
1827 notifyRequester(request);
1828 break;
1829 }
1830 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1831 request = (MainThreadRequest) msg.obj;
1832
1833 Phone phone = getPhoneFromRequest(request);
1834 if (phone == null || phone.getServiceStateTracker() == null) {
1835 request.result = new IllegalStateException("Phone or SST is null");
1836 notifyRequester(request);
1837 break;
1838 }
1839
1840 Pair<Integer, SignalStrengthUpdateRequest> pair =
1841 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1842 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1843 request);
1844 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1845 request.subId, pair.first /*callingUid*/,
1846 pair.second /*request*/, onCompleted);
1847 break;
1848 }
1849 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1850 ar = (AsyncResult) msg.obj;
1851 request = (MainThreadRequest) ar.userObj;
1852 request.result = ar.exception != null ? ar.exception : true;
1853 notifyRequester(request);
1854 break;
1855 }
Jordan Liud5366d92020-11-24 14:50:34 -08001856
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 default:
1858 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1859 break;
1860 }
1861 }
Jake Hambye994d462014-02-03 13:10:13 -08001862
Pengquan Menga1bb6272018-09-06 09:59:22 -07001863 private void notifyRequester(MainThreadRequest request) {
1864 synchronized (request) {
1865 request.notifyAll();
1866 }
1867 }
1868
Jake Hambye994d462014-02-03 13:10:13 -08001869 private void handleNullReturnEvent(Message msg, String command) {
1870 AsyncResult ar = (AsyncResult) msg.obj;
1871 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1872 if (ar.exception == null) {
1873 request.result = true;
1874 } else {
1875 request.result = false;
1876 if (ar.exception instanceof CommandException) {
1877 loge(command + ": CommandException: " + ar.exception);
1878 } else {
1879 loge(command + ": Unknown exception");
1880 }
1881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001882 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001883 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 }
1885
1886 /**
1887 * Posts the specified command to be executed on the main thread,
1888 * waits for the request to complete, and returns the result.
1889 * @see #sendRequestAsync
1890 */
1891 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001892 return sendRequest(
1893 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001894 }
1895
1896 /**
1897 * Posts the specified command to be executed on the main thread,
1898 * waits for the request to complete, and returns the result.
1899 * @see #sendRequestAsync
1900 */
1901 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1902 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001903 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001904 }
1905
1906 /**
1907 * Posts the specified command to be executed on the main thread,
1908 * waits for the request to complete, and returns the result.
1909 * @see #sendRequestAsync
1910 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001911 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001912 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001913 }
1914
1915 /**
1916 * Posts the specified command to be executed on the main thread,
1917 * waits for the request to complete, and returns the result.
1918 * @see #sendRequestAsync
1919 */
Nathan Harold92bed182018-10-12 18:16:49 -07001920 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1921 return sendRequest(command, argument, subId, null, workSource);
1922 }
1923
1924 /**
1925 * Posts the specified command to be executed on the main thread,
1926 * waits for the request to complete, and returns the result.
1927 * @see #sendRequestAsync
1928 */
1929 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1930 return sendRequest(
1931 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1932 }
1933
1934 /**
1935 * Posts the specified command to be executed on the main thread,
1936 * waits for the request to complete, and returns the result.
1937 * @see #sendRequestAsync
1938 */
1939 private Object sendRequest(
1940 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1942 throw new RuntimeException("This method will deadlock if called from the main thread.");
1943 }
1944
Nathan Harold92bed182018-10-12 18:16:49 -07001945 MainThreadRequest request = null;
1946 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1947 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1948 } else if (phone != null) {
1949 request = new MainThreadRequest(argument, phone, workSource);
1950 } else {
1951 request = new MainThreadRequest(argument, subId, workSource);
1952 }
1953
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 Message msg = mMainThreadHandler.obtainMessage(command, request);
1955 msg.sendToTarget();
1956
1957 // Wait for the request to complete
1958 synchronized (request) {
1959 while (request.result == null) {
1960 try {
1961 request.wait();
1962 } catch (InterruptedException e) {
1963 // Do nothing, go back and wait until the request is complete
1964 }
1965 }
1966 }
1967 return request.result;
1968 }
1969
1970 /**
1971 * Asynchronous ("fire and forget") version of sendRequest():
1972 * Posts the specified command to be executed on the main thread, and
1973 * returns immediately.
1974 * @see #sendRequest
1975 */
1976 private void sendRequestAsync(int command) {
1977 mMainThreadHandler.sendEmptyMessage(command);
1978 }
1979
1980 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001981 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001982 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001983 */
1984 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001985 sendRequestAsync(command, argument, null, null);
1986 }
1987
1988 /**
1989 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1990 * @see {@link #sendRequest(int,Object)}
1991 */
1992 private void sendRequestAsync(
1993 int command, Object argument, Phone phone, WorkSource workSource) {
1994 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001995 Message msg = mMainThreadHandler.obtainMessage(command, request);
1996 msg.sendToTarget();
1997 }
1998
1999 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 * Initialize the singleton PhoneInterfaceManager instance.
2001 * This is only done once, at startup, from PhoneApp.onCreate().
2002 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002003 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004 synchronized (PhoneInterfaceManager.class) {
2005 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002006 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 } else {
2008 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2009 }
2010 return sInstance;
2011 }
2012 }
2013
2014 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002015 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002018 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002019 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2021 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002022 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002023 mTelephonySharedPreferences =
2024 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002025 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002026 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002027 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002028
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 publish();
2030 }
2031
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002032 private Phone getDefaultPhone() {
2033 Phone thePhone = getPhone(getDefaultSubscription());
2034 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2035 }
2036
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 private void publish() {
2038 if (DBG) log("publish: " + this);
2039
Peter Wangc035ce42020-01-08 21:00:22 -08002040 TelephonyFrameworkInitializer
2041 .getTelephonyServiceManager()
2042 .getTelephonyServiceRegisterer()
2043 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 }
2045
Stuart Scott584921c2015-01-15 17:10:34 -08002046 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002047 if (request.phone != null) {
2048 return request.phone;
2049 } else {
2050 return getPhoneFromSubId(request.subId);
2051 }
2052 }
2053
2054 private Phone getPhoneFromSubId(int subId) {
2055 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2056 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002057 }
2058
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002059 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2060 Phone phone = getPhoneFromRequest(request);
2061 return phone == null ? null :
2062 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2063 }
2064
Wink Saville36469e72014-06-11 15:17:00 -07002065 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002066 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002067 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002068 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002070 private void sendEraseModemConfig(Phone phone) {
2071 if (phone != null) {
2072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2073 mApp, phone.getSubId(), "eraseModemConfig");
2074 final long identity = Binder.clearCallingIdentity();
2075 try {
2076 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2077 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2078 } finally {
2079 Binder.restoreCallingIdentity(identity);
2080 }
2081 }
2082 }
2083
Peter Wang050bb052020-01-13 23:33:09 -08002084 private boolean isImsAvailableOnDevice() {
2085 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2086 if (pm == null) {
2087 // For some reason package manger is not available.. This will fail internally anyway,
2088 // so do not throw error and allow.
2089 return true;
2090 }
2091 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2092 }
2093
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002095 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002096 }
2097
Wink Savilleb564aae2014-10-23 10:18:09 -07002098 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 if (DBG) log("dial: " + number);
2100 // No permission check needed here: This is just a wrapper around the
2101 // ACTION_DIAL intent, which is available to any app since it puts up
2102 // the UI before it does anything.
2103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 String url = createTelUrl(number);
2107 if (url == null) {
2108 return;
2109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002111 // PENDING: should we just silently fail if phone is offhook or ringing?
2112 PhoneConstants.State state = mCM.getState(subId);
2113 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2114 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2115 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2116 mApp.startActivity(intent);
2117 }
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 }
2121 }
2122
2123 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002124 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002125 }
2126
Wink Savilleb564aae2014-10-23 10:18:09 -07002127 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 if (DBG) log("call: " + number);
2129
2130 // This is just a wrapper around the ACTION_CALL intent, but we still
2131 // need to do a permission check since we're calling startActivity()
2132 // from the context of the phone app.
2133 enforceCallPermission();
2134
Jordan Liu1617b712019-07-10 15:06:26 -07002135 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 != AppOpsManager.MODE_ALLOWED) {
2137 return;
2138 }
2139
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002140 final long identity = Binder.clearCallingIdentity();
2141 try {
2142 String url = createTelUrl(number);
2143 if (url == null) {
2144 return;
2145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002147 boolean isValid = false;
2148 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2149 if (slist != null) {
2150 for (SubscriptionInfo subInfoRecord : slist) {
2151 if (subInfoRecord.getSubscriptionId() == subId) {
2152 isValid = true;
2153 break;
2154 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002155 }
Wink Saville08874612014-08-31 19:19:58 -07002156 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002157 if (!isValid) {
2158 return;
2159 }
Wink Saville08874612014-08-31 19:19:58 -07002160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002161 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2162 intent.putExtra(SUBSCRIPTION_KEY, subId);
2163 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2164 mApp.startActivity(intent);
2165 } finally {
2166 Binder.restoreCallingIdentity(identity);
2167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Wink Savilleb564aae2014-10-23 10:18:09 -07002170 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002171 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002172 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2173 }
2174
Wink Savilleb564aae2014-10-23 10:18:09 -07002175 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002176 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002177 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2178 }
2179
Wink Savilleb564aae2014-10-23 10:18:09 -07002180 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002182
2183 final long identity = Binder.clearCallingIdentity();
2184 try {
2185 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2186 checkSimPin.start();
2187 return checkSimPin.unlockSim(null, pin);
2188 } finally {
2189 Binder.restoreCallingIdentity(identity);
2190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 }
2192
Wink Savilleb564aae2014-10-23 10:18:09 -07002193 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002195
2196 final long identity = Binder.clearCallingIdentity();
2197 try {
2198 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2199 checkSimPuk.start();
2200 return checkSimPuk.unlockSim(puk, pin);
2201 } finally {
2202 Binder.restoreCallingIdentity(identity);
2203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 }
2205
2206 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002207 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 * a synchronous one.
2209 */
2210 private static class UnlockSim extends Thread {
2211
2212 private final IccCard mSimCard;
2213
2214 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002215 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2216 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217
2218 // For replies from SimCard interface
2219 private Handler mHandler;
2220
2221 // For async handler to identify request type
2222 private static final int SUPPLY_PIN_COMPLETE = 100;
2223
2224 public UnlockSim(IccCard simCard) {
2225 mSimCard = simCard;
2226 }
2227
2228 @Override
2229 public void run() {
2230 Looper.prepare();
2231 synchronized (UnlockSim.this) {
2232 mHandler = new Handler() {
2233 @Override
2234 public void handleMessage(Message msg) {
2235 AsyncResult ar = (AsyncResult) msg.obj;
2236 switch (msg.what) {
2237 case SUPPLY_PIN_COMPLETE:
2238 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2239 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002240 mRetryCount = msg.arg1;
2241 if (ar.exception != null) {
2242 if (ar.exception instanceof CommandException &&
2243 ((CommandException)(ar.exception)).getCommandError()
2244 == CommandException.Error.PASSWORD_INCORRECT) {
2245 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002246 } //When UiccCardApp dispose,handle message and return exception
2247 else if (ar.exception instanceof CommandException &&
2248 ((CommandException) (ar.exception)).getCommandError()
2249 == CommandException.Error.ABORTED) {
2250 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002251 } else {
2252 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2253 }
2254 } else {
2255 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 mDone = true;
2258 UnlockSim.this.notifyAll();
2259 }
2260 break;
2261 }
2262 }
2263 };
2264 UnlockSim.this.notifyAll();
2265 }
2266 Looper.loop();
2267 }
2268
2269 /*
2270 * Use PIN or PUK to unlock SIM card
2271 *
2272 * If PUK is null, unlock SIM card with PIN
2273 *
2274 * If PUK is not null, unlock SIM card with PUK and set PIN code
2275 */
Wink Saville9de0f752013-10-22 19:04:03 -07002276 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277
2278 while (mHandler == null) {
2279 try {
2280 wait();
2281 } catch (InterruptedException e) {
2282 Thread.currentThread().interrupt();
2283 }
2284 }
2285 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2286
2287 if (puk == null) {
2288 mSimCard.supplyPin(pin, callback);
2289 } else {
2290 mSimCard.supplyPuk(puk, pin, callback);
2291 }
2292
2293 while (!mDone) {
2294 try {
2295 Log.d(LOG_TAG, "wait for done");
2296 wait();
2297 } catch (InterruptedException e) {
2298 // Restore the interrupted status
2299 Thread.currentThread().interrupt();
2300 }
2301 }
2302 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002303 int[] resultArray = new int[2];
2304 resultArray[0] = mResult;
2305 resultArray[1] = mRetryCount;
2306 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 }
2308 }
2309
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002310 /**
2311 * This method has been removed due to privacy and stability concerns.
2312 */
2313 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002315 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2316 return;
Wink Saville36469e72014-06-11 15:17:00 -07002317 }
2318
Nathan Harold1f889d82020-06-04 17:05:26 -07002319 @Override
2320 public void updateServiceLocationWithPackageName(String callingPackage) {
2321 mApp.getSystemService(AppOpsManager.class)
2322 .checkPackage(Binder.getCallingUid(), callingPackage);
2323
Nathan Haroldf096d982020-11-18 17:18:06 -08002324 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002325 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2326 // Callers targeting S have no business invoking this method.
2327 return;
2328 }
2329
2330 LocationAccessPolicy.LocationPermissionResult locationResult =
2331 LocationAccessPolicy.checkLocationPermission(mApp,
2332 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2333 .setCallingPackage(callingPackage)
2334 .setCallingFeatureId(null)
2335 .setCallingPid(Binder.getCallingPid())
2336 .setCallingUid(Binder.getCallingUid())
2337 .setMethod("updateServiceLocation")
2338 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2339 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2340 .build());
2341 // Apps that lack location permission have no business calling this method;
2342 // however, because no permission was declared in the public API, denials must
2343 // all be "soft".
2344 switch (locationResult) {
2345 case DENIED_HARD: /* fall through */
2346 case DENIED_SOFT:
2347 return;
2348 }
2349
2350 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351 final long identity = Binder.clearCallingIdentity();
2352 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002353 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002354 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002355 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002362 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002363 @Override
2364 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002365 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002366 }
2367
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002368
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002369 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002370 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2371 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2372 callingFeatureId);
2373 }
2374
2375 @Deprecated
2376 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002377 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002378 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2379 }
2380
2381 @Override
2382 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2383 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002385 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002386 return false;
2387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002388
2389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 return isRadioOnForSubscriber(subId);
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
2394 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002395 }
2396
2397 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 final Phone phone = getPhone(subId);
2401 if (phone != null) {
2402 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2403 } else {
2404 return false;
2405 }
2406 } finally {
2407 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 }
2410
2411 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002412 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 }
Wink Saville36469e72014-06-11 15:17:00 -07002414
Wink Savilleb564aae2014-10-23 10:18:09 -07002415 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
2420 final Phone phone = getPhone(subId);
2421 if (phone != null) {
2422 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2423 }
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002426 }
Wink Saville36469e72014-06-11 15:17:00 -07002427 }
2428
2429 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002430 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002431 }
2432
Wink Savilleb564aae2014-10-23 10:18:09 -07002433 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002434 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435
2436 final long identity = Binder.clearCallingIdentity();
2437 try {
2438 final Phone phone = getPhone(subId);
2439 if (phone == null) {
2440 return false;
2441 }
2442 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2443 toggleRadioOnOffForSubscriber(subId);
2444 }
2445 return true;
2446 } finally {
2447 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 }
Wink Saville36469e72014-06-11 15:17:00 -07002450
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002451 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002452 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002453 /*
2454 * If any of the Radios are available, it will need to be
2455 * shutdown. So return true if any Radio is available.
2456 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002457 final long identity = Binder.clearCallingIdentity();
2458 try {
2459 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2460 Phone phone = PhoneFactory.getPhone(i);
2461 if (phone != null && phone.isRadioAvailable()) return true;
2462 }
2463 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2464 return false;
2465 } finally {
2466 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002467 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002468 }
2469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002471 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 enforceModifyPermission();
2473
2474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2477 logv("Shutting down Phone " + i);
2478 shutdownRadioUsingPhoneId(i);
2479 }
2480 } finally {
2481 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002482 }
2483 }
2484
2485 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002486 Phone phone = PhoneFactory.getPhone(phoneId);
2487 if (phone != null && phone.isRadioAvailable()) {
2488 phone.shutdownRadio();
2489 }
2490 }
2491
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002494
2495 final long identity = Binder.clearCallingIdentity();
2496 try {
2497 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2498 if (defaultPhone != null) {
2499 defaultPhone.setRadioPower(turnOn);
2500 return true;
2501 } else {
2502 loge("There's no default phone.");
2503 return false;
2504 }
2505 } finally {
2506 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002507 }
Wink Saville36469e72014-06-11 15:17:00 -07002508 }
2509
Wink Savilleb564aae2014-10-23 10:18:09 -07002510 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512
2513 final long identity = Binder.clearCallingIdentity();
2514 try {
2515 final Phone phone = getPhone(subId);
2516 if (phone != null) {
2517 phone.setRadioPower(turnOn);
2518 return true;
2519 } else {
2520 return false;
2521 }
2522 } finally {
2523 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 }
2526
Wink Saville36469e72014-06-11 15:17:00 -07002527 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 public boolean enableDataConnectivity() {
2530 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531
2532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 int subId = mSubscriptionController.getDefaultDataSubId();
2535 final Phone phone = getPhone(subId);
2536 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002537 phone.getDataEnabledSettings().setDataEnabled(
2538 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539 return true;
2540 } else {
2541 return false;
2542 }
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 }
2547
Wink Saville36469e72014-06-11 15:17:00 -07002548 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002549 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002550 public boolean disableDataConnectivity() {
2551 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 int subId = mSubscriptionController.getDefaultDataSubId();
2556 final Phone phone = getPhone(subId);
2557 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002558 phone.getDataEnabledSettings().setDataEnabled(
2559 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560 return true;
2561 } else {
2562 return false;
2563 }
2564 } finally {
2565 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 }
2568
Sanket Padawe356d7632015-06-22 14:03:32 -07002569 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002570 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone phone = getPhone(subId);
2574 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002575 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002576 } else {
2577 return false;
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583
2584 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002585 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002586 }
2587
pkanwarae03a6b2016-11-06 20:37:09 -08002588 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002589 enforceCallPermission();
2590
2591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2594 return;
2595 }
2596 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2597 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2598 } finally {
2599 Binder.restoreCallingIdentity(identity);
2600 }
pkanwar32d516d2016-10-14 19:37:38 -07002601 };
2602
Wink Savilleb564aae2014-10-23 10:18:09 -07002603 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605
2606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2609 return false;
2610 }
2611 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2612 } finally {
2613 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002615 }
2616
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002618 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002619 }
2620
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002621 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 Phone phone = PhoneFactory.getPhone(slotIndex);
2625 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2626 PhoneConstantConversions.convertCallState(phone.getState());
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
2629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 }
2631
Sanket Padawe356d7632015-06-22 14:03:32 -07002632 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002633 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002634 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2635 }
2636
2637 @Override
2638 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 final long identity = Binder.clearCallingIdentity();
2640 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002641 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 if (phone != null) {
2643 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2644 } else {
2645 return PhoneConstantConversions.convertDataState(
2646 PhoneConstants.DataState.DISCONNECTED);
2647 }
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 }
2652
Sanket Padawe356d7632015-06-22 14:03:32 -07002653 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002654 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002655 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2656 }
2657
2658 @Override
2659 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 final long identity = Binder.clearCallingIdentity();
2661 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002662 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 if (phone != null) {
2664 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2665 } else {
2666 return TelephonyManager.DATA_ACTIVITY_NONE;
2667 }
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002671 }
2672
2673 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002674 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002675 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002676 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002677
2678 LocationAccessPolicy.LocationPermissionResult locationResult =
2679 LocationAccessPolicy.checkLocationPermission(mApp,
2680 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2681 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002682 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002683 .setCallingPid(Binder.getCallingPid())
2684 .setCallingUid(Binder.getCallingUid())
2685 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002686 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002687 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2688 .build());
2689 switch (locationResult) {
2690 case DENIED_HARD:
2691 throw new SecurityException("Not allowed to access cell location");
2692 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002693 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2694 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
2696
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002697 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002701 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002702 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 } finally {
2704 Binder.restoreCallingIdentity(identity);
2705 }
Svetoslav64fad262015-04-14 14:35:21 -07002706 }
2707
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 @Override
Jack Yu01425032020-02-22 19:38:58 -08002709 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002710 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2711 // registered cell info, so return a NULL country instead.
2712 final long identity = Binder.clearCallingIdentity();
2713 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002714 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2715 // Get default phone in this case.
2716 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2717 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002718 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002720 if (phone == null) return "";
2721 ServiceStateTracker sst = phone.getServiceStateTracker();
2722 if (sst == null) return "";
2723 LocaleTracker lt = sst.getLocaleTracker();
2724 if (lt == null) return "";
2725 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2726 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2727 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002728 } finally {
2729 Binder.restoreCallingIdentity(identity);
2730 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002731 }
2732
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002733 /**
2734 * This method was removed due to potential issues caused by performing partial
2735 * updates of service state, and lack of a credible use case.
2736 *
2737 * This has the ability to break the telephony implementation by disabling notification of
2738 * changes in device connectivity. DO NOT USE THIS!
2739 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002740 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 public void enableLocationUpdates() {
2742 mApp.enforceCallingOrSelfPermission(
2743 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 }
2745
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002746 /**
2747 * This method was removed due to potential issues caused by performing partial
2748 * updates of service state, and lack of a credible use case.
2749 *
2750 * This has the ability to break the telephony implementation by disabling notification of
2751 * changes in device connectivity. DO NOT USE THIS!
2752 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002753 @Override
2754 public void disableLocationUpdates() {
2755 mApp.enforceCallingOrSelfPermission(
2756 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 }
2758
2759 @Override
2760 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002761 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2762 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002763 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002764 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2765 throw new SecurityException(
2766 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2767 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002768
Jordan Liu1617b712019-07-10 15:06:26 -07002769 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2771 return null;
2772 }
Svetoslav64fad262015-04-14 14:35:21 -07002773
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002774 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002776 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002777 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778
Nathan Haroldf180aac2018-06-01 18:43:55 -07002779 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2780 for (CellInfo ci : info) {
2781 if (ci instanceof CellInfoGsm) {
2782 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2783 } else if (ci instanceof CellInfoWcdma) {
2784 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002786 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002787 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002788 }
2789
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002790 private List<CellInfo> getCachedCellInfo() {
2791 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2792 for (Phone phone : PhoneFactory.getPhones()) {
2793 List<CellInfo> info = phone.getAllCellInfo();
2794 if (info != null) cellInfos.addAll(info);
2795 }
2796 return cellInfos;
2797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798
2799 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002800 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002801 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002802 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002803
2804 LocationAccessPolicy.LocationPermissionResult locationResult =
2805 LocationAccessPolicy.checkLocationPermission(mApp,
2806 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2807 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002808 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002809 .setCallingPid(Binder.getCallingPid())
2810 .setCallingUid(Binder.getCallingUid())
2811 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002812 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002813 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2814 .build());
2815 switch (locationResult) {
2816 case DENIED_HARD:
2817 throw new SecurityException("Not allowed to access cell info");
2818 case DENIED_SOFT:
2819 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 }
2821
Nathan Haroldf096d982020-11-18 17:18:06 -08002822 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002823 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2824 return getCachedCellInfo();
2825 }
2826
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002827 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002828 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829 final long identity = Binder.clearCallingIdentity();
2830 try {
2831 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2832 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002833 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002834 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835 if (info != null) cellInfos.addAll(info);
2836 }
2837 return cellInfos;
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 }
2841 }
2842
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002843 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002844 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2845 String callingFeatureId) {
2846 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2847 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002848 }
2849
2850 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002851 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2852 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002853 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002854 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002855 }
2856
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002857 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2858 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002859 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002860 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002861
2862 LocationAccessPolicy.LocationPermissionResult locationResult =
2863 LocationAccessPolicy.checkLocationPermission(mApp,
2864 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2865 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002866 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002867 .setCallingPid(Binder.getCallingPid())
2868 .setCallingUid(Binder.getCallingUid())
2869 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002870 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2871 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002872 .build());
2873 switch (locationResult) {
2874 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002875 if (TelephonyPermissions
2876 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002877 // Safetynet logging for b/154934934
2878 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2879 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002880 throw new SecurityException("Not allowed to access cell info");
2881 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002882 if (TelephonyPermissions
2883 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002884 // Safetynet logging for b/154934934
2885 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2886 }
Nathan Harold5320c422019-05-09 10:26:08 -07002887 try {
2888 cb.onCellInfo(new ArrayList<CellInfo>());
2889 } catch (RemoteException re) {
2890 // Drop without consequences
2891 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002892 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002893 }
2894
Nathan Harolda939a962019-05-09 10:13:47 -07002895
2896 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002897 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2898
2899 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2900 }
2901
2902 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002903 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002904 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002905 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906
2907 final long identity = Binder.clearCallingIdentity();
2908 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002909 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 } finally {
2911 Binder.restoreCallingIdentity(identity);
2912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002913 }
2914
Shishir Agrawala9f32182016-04-12 12:00:16 -07002915 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002916 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002917 Phone phone = PhoneFactory.getPhone(slotIndex);
2918 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002919 return null;
2920 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002921 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002922 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002923 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002924 return null;
2925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926
2927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 return phone.getImei();
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002933 }
2934
2935 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002936 public String getTypeAllocationCodeForSlot(int slotIndex) {
2937 Phone phone = PhoneFactory.getPhone(slotIndex);
2938 String tac = null;
2939 if (phone != null) {
2940 String imei = phone.getImei();
2941 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2942 }
2943 return tac;
2944 }
2945
2946 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002947 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002948 Phone phone = PhoneFactory.getPhone(slotIndex);
2949 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002950 return null;
2951 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002952
Jeff Davidson913390f2018-02-23 17:11:49 -08002953 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002954 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002955 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002956 return null;
2957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002958
2959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 return phone.getMeid();
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
Jack Yu2af8d712017-03-15 17:14:14 -07002965 }
2966
2967 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002968 public String getManufacturerCodeForSlot(int slotIndex) {
2969 Phone phone = PhoneFactory.getPhone(slotIndex);
2970 String manufacturerCode = null;
2971 if (phone != null) {
2972 String meid = phone.getMeid();
2973 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2974 }
2975 return manufacturerCode;
2976 }
2977
2978 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002979 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2980 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002981 Phone phone = PhoneFactory.getPhone(slotIndex);
2982 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002983 return null;
2984 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002985 int subId = phone.getSubId();
2986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002987 mApp, subId, callingPackage, callingFeatureId,
2988 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002989 return null;
2990 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 return phone.getDeviceSvn();
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002998 }
2999
fionaxu43304da2017-11-27 22:51:16 -08003000 @Override
3001 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 final Phone phone = getPhone(subId);
3005 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
fionaxu43304da2017-11-27 22:51:16 -08003009 }
3010
3011 @Override
3012 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 final Phone phone = getPhone(subId);
3016 return phone == null ? null : phone.getCarrierName();
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
fionaxu43304da2017-11-27 22:51:16 -08003020 }
3021
calvinpanffe225e2018-11-01 19:43:06 +08003022 @Override
chen xu0026ca62019-03-06 15:28:50 -08003023 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 final Phone phone = getPhone(subId);
3027 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003028 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003029 } finally {
3030 Binder.restoreCallingIdentity(identity);
3031 }
3032 }
3033
3034 @Override
chen xu0026ca62019-03-06 15:28:50 -08003035 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003039 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003040 } finally {
3041 Binder.restoreCallingIdentity(identity);
3042 }
3043 }
3044
chen xu651eec72018-11-11 19:03:44 -08003045 @Override
chen xu864e11c2018-12-06 22:10:03 -08003046 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3047 if (!isSubscriptionMccMnc) {
3048 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3049 }
chen xu651eec72018-11-11 19:03:44 -08003050 final Phone phone = PhoneFactory.getPhone(slotIndex);
3051 if (phone == null) {
3052 return TelephonyManager.UNKNOWN_CARRIER_ID;
3053 }
3054 final long identity = Binder.clearCallingIdentity();
3055 try {
3056 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
3059 }
3060 }
3061
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062 //
3063 // Internal helper methods.
3064 //
3065
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003066 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003067 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3068 *
3069 * @throws SecurityException if the caller does not have the required permission
3070 */
3071 private void enforceModifyPermission() {
3072 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3073 }
3074
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003075 /**
3076 * Make sure the caller is system.
3077 *
3078 * @throws SecurityException if the caller is not system.
3079 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003080 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003081 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3082 throw new SecurityException("Caller must be system");
3083 }
3084 }
3085
Shuo Qianf2b2df42019-11-13 17:43:31 -08003086 private void enforceActiveEmergencySessionPermission() {
3087 mApp.enforceCallingOrSelfPermission(
3088 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3089 }
3090
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003091 /**
3092 * Make sure the caller has the CALL_PHONE permission.
3093 *
3094 * @throws SecurityException if the caller does not have the required permission
3095 */
3096 private void enforceCallPermission() {
3097 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3098 }
3099
paulhu423b5f22019-08-23 19:17:33 +08003100 private void enforceSettingsPermission() {
3101 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003102 }
3103
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003104 private String createTelUrl(String number) {
3105 if (TextUtils.isEmpty(number)) {
3106 return null;
3107 }
3108
Jake Hambye994d462014-02-03 13:10:13 -08003109 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003110 }
3111
Ihab Awadf9e92732013-12-05 18:02:52 -08003112 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003113 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3114 }
3115
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003116 private static void logv(String msg) {
3117 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3118 }
3119
Ihab Awadf9e92732013-12-05 18:02:52 -08003120 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003121 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3122 }
3123
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003124 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003125 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003126 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003127 }
3128
Sanket Padawe356d7632015-06-22 14:03:32 -07003129 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003130 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 final Phone phone = PhoneFactory.getPhone(slotIndex);
3134 if (phone == null) {
3135 return PhoneConstants.PHONE_TYPE_NONE;
3136 } else {
3137 return phone.getPhoneType();
3138 }
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 }
3143
3144 /**
3145 * Returns the CDMA ERI icon index to display
3146 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003147 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003148 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3149 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3150 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003151 }
3152
Sanket Padawe356d7632015-06-22 14:03:32 -07003153 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003154 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3155 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003156 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003157 mApp, subId, callingPackage, callingFeatureId,
3158 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003159 return -1;
3160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003161
3162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 final Phone phone = getPhone(subId);
3165 if (phone != null) {
3166 return phone.getCdmaEriIconIndex();
3167 } else {
3168 return -1;
3169 }
3170 } finally {
3171 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 }
3174
3175 /**
3176 * Returns the CDMA ERI icon mode,
3177 * 0 - ON
3178 * 1 - FLASHING
3179 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003180 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003181 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3182 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3183 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003184 }
3185
Sanket Padawe356d7632015-06-22 14:03:32 -07003186 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003187 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3188 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003190 mApp, subId, callingPackage, callingFeatureId,
3191 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003192 return -1;
3193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
3197 final Phone phone = getPhone(subId);
3198 if (phone != null) {
3199 return phone.getCdmaEriIconMode();
3200 } else {
3201 return -1;
3202 }
3203 } finally {
3204 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003205 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 }
3207
3208 /**
3209 * Returns the CDMA ERI text,
3210 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003211 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003212 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3213 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3214 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003215 }
3216
Sanket Padawe356d7632015-06-22 14:03:32 -07003217 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003218 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3219 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003221 mApp, subId, callingPackage, callingFeatureId,
3222 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003223 return null;
3224 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225
3226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 final Phone phone = getPhone(subId);
3229 if (phone != null) {
3230 return phone.getCdmaEriText();
3231 } else {
3232 return null;
3233 }
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003237 }
3238
3239 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003240 * Returns the CDMA MDN.
3241 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003242 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003243 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3245 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003246
3247 final long identity = Binder.clearCallingIdentity();
3248 try {
3249 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003250 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 return phone.getLine1Number();
3252 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003253 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254 return null;
3255 }
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003258 }
3259 }
3260
3261 /**
3262 * Returns the CDMA MIN.
3263 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003264 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003265 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3267 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003268
3269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 final Phone phone = getPhone(subId);
3272 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3273 return phone.getCdmaMin();
3274 } else {
3275 return null;
3276 }
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003279 }
3280 }
3281
Hall Liud892bec2018-11-30 14:51:45 -08003282 @Override
3283 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3284 INumberVerificationCallback callback, String callingPackage) {
3285 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3286 != PERMISSION_GRANTED) {
3287 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3288 }
3289 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3290
3291 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3292 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003293 throw new SecurityException("Calling package must be configured in the device config: "
3294 + "calling package: " + callingPackage
3295 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003296 }
3297
3298 if (range == null) {
3299 throw new NullPointerException("Range must be non-null");
3300 }
3301
3302 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003303 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003304
3305 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3306 }
3307
Junda Liuca05d5d2014-08-14 22:36:34 -07003308 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003309 * Returns true if CDMA provisioning needs to run.
3310 */
3311 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312 final long identity = Binder.clearCallingIdentity();
3313 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003314 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003318 }
3319
3320 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003321 * Sets the voice mail number of a given subId.
3322 */
3323 @Override
3324 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003325 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3326 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003327
3328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3331 new Pair<String, String>(alphaTag, number), new Integer(subId));
3332 return success;
3333 } finally {
3334 Binder.restoreCallingIdentity(identity);
3335 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003336 }
3337
Ta-wei Yen87c49842016-05-13 21:19:52 -07003338 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003339 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3340 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003341 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3342 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003343 if (!TextUtils.equals(callingPackage, systemDialer)) {
3344 throw new SecurityException("caller must be system dialer");
3345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346
3347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3350 if (phoneAccountHandle == null) {
3351 return null;
3352 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003353 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354 } finally {
3355 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003356 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003357 }
3358
3359 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003360 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3361 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003362 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003363 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003364 mApp, subId, callingPackage, callingFeatureId,
3365 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003366 return null;
3367 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003368
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003369 final long identity = Binder.clearCallingIdentity();
3370 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003371 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003372 } finally {
3373 Binder.restoreCallingIdentity(identity);
3374 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003375 }
3376
3377 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003378 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3379 VisualVoicemailSmsFilterSettings settings) {
3380 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003381
3382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003385 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003389 }
3390
3391 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003392 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003394
3395 final long identity = Binder.clearCallingIdentity();
3396 try {
3397 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003398 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003402 }
3403
3404 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003405 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3406 String callingPackage, int subId) {
3407 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003412 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003416 }
3417
3418 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003419 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003420 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003425 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003429 }
3430
3431 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003432 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3433 String callingAttributionTag, int subId, String number, int port, String text,
3434 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003435 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003436 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003437 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003438 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003439 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3440 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003441 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003442
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003443 /**
fionaxu0152e512016-11-14 13:36:14 -08003444 * Sets the voice activation state of a given subId.
3445 */
3446 @Override
3447 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003448 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3449 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450
3451 final long identity = Binder.clearCallingIdentity();
3452 try {
3453 final Phone phone = getPhone(subId);
3454 if (phone != null) {
3455 phone.setVoiceActivationState(activationState);
3456 } else {
3457 loge("setVoiceActivationState fails with invalid subId: " + subId);
3458 }
3459 } finally {
3460 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003461 }
3462 }
3463
3464 /**
3465 * Sets the data activation state of a given subId.
3466 */
3467 @Override
3468 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3470 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003471
3472 final long identity = Binder.clearCallingIdentity();
3473 try {
3474 final Phone phone = getPhone(subId);
3475 if (phone != null) {
3476 phone.setDataActivationState(activationState);
3477 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003478 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479 }
3480 } finally {
3481 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003482 }
3483 }
3484
3485 /**
3486 * Returns the voice activation state of a given subId.
3487 */
3488 @Override
3489 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003490 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491
fionaxu0152e512016-11-14 13:36:14 -08003492 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 if (phone != null) {
3496 return phone.getVoiceActivationState();
3497 } else {
3498 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3499 }
3500 } finally {
3501 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003502 }
3503 }
3504
3505 /**
3506 * Returns the data activation state of a given subId.
3507 */
3508 @Override
3509 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003510 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003511
fionaxu0152e512016-11-14 13:36:14 -08003512 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 if (phone != null) {
3516 return phone.getDataActivationState();
3517 } else {
3518 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3519 }
3520 } finally {
3521 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003522 }
3523 }
3524
3525 /**
Wink Saville36469e72014-06-11 15:17:00 -07003526 * Returns the unread count of voicemails for a subId
3527 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003528 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003529 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3530 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003532 mApp, subId, callingPackage, callingFeatureId,
3533 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003534 return 0;
3535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 final Phone phone = getPhone(subId);
3539 if (phone != null) {
3540 return phone.getVoiceMessageCount();
3541 } else {
3542 return 0;
3543 }
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003547 }
3548
3549 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003550 * returns true, if the device is in a state where both voice and data
3551 * are supported simultaneously. This can change based on location or network condition.
3552 */
3553 @Override
3554 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 final Phone phone = getPhone(subId);
3558 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3559 } finally {
3560 Binder.restoreCallingIdentity(identity);
3561 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003562 }
3563
3564 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003565 * Send the dialer code if called from the current default dialer or the caller has
3566 * carrier privilege.
3567 * @param inputCode The dialer code to send
3568 */
3569 @Override
3570 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003571 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003572 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003573 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3574 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003575 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003576 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003577 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579
3580 final long identity = Binder.clearCallingIdentity();
3581 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003582 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583 } finally {
3584 Binder.restoreCallingIdentity(identity);
3585 }
fionaxu235cc5e2017-03-06 22:25:57 -08003586 }
3587
Pengquan Menga1bb6272018-09-06 09:59:22 -07003588 @Override
3589 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003590 TelephonyPermissions
3591 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3592 mApp, subId, "getNetworkSelectionMode");
3593 final long identity = Binder.clearCallingIdentity();
3594 try {
3595 if (!isActiveSubscription(subId)) {
3596 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3597 }
3598 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003601 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003602 }
3603
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003605 public boolean isInEmergencySmsMode() {
3606 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 for (Phone phone : PhoneFactory.getPhones()) {
3610 if (phone.isInEmergencySmsMode()) {
3611 return true;
3612 }
3613 }
3614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
3617 return false;
3618 }
3619
shilu366312e2019-12-17 09:28:10 -08003620 /**
3621 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3622 * @param subId The subscription to use to check the configuration.
3623 * @param c The callback that will be used to send the result.
3624 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003625 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003626 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3627 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003628 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3629 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003630
Brad Ebinger77b832e2019-10-17 17:03:22 -07003631 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3632 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3633 "IMS not available on device.");
3634 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003635 final long token = Binder.clearCallingIdentity();
3636 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003637 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003638 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003640 } catch (ImsException e) {
3641 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003642 } finally {
3643 Binder.restoreCallingIdentity(token);
3644 }
3645 }
3646
shilu366312e2019-12-17 09:28:10 -08003647 /**
3648 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3649 * @param subId The subscription to use to check the configuration.
3650 * @param c The callback that will be used to send the result.
3651 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003652 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003653 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003654 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3655 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003656 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3657 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3658 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003659 final long token = Binder.clearCallingIdentity();
3660 try {
3661 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3662 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3663 .removeRegistrationCallbackForSubscription(c, subId);
3664 } catch (ImsException e) {
3665 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3666 + "is inactive, ignoring unregister.");
3667 // If the subscription is no longer active, just return, since the callback
3668 // will already have been removed internally.
3669 } finally {
3670 Binder.restoreCallingIdentity(token);
3671 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003672 }
3673
Brad Ebinger774ba362019-10-22 17:36:18 -07003674 /**
3675 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3676 */
3677 @Override
3678 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3679 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3680 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3681 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3682 "IMS not available on device.");
3683 }
3684 final long token = Binder.clearCallingIdentity();
3685 try {
3686 Phone phone = getPhone(subId);
3687 if (phone == null) {
3688 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3689 + subId + "'");
3690 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3691 }
3692 phone.getImsRegistrationState(regState -> {
3693 try {
3694 consumer.accept((regState == null)
3695 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3696 } catch (RemoteException e) {
3697 // Ignore if the remote process is no longer available to call back.
3698 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3699 }
3700 });
3701 } finally {
3702 Binder.restoreCallingIdentity(token);
3703 }
3704 }
3705
3706 /**
3707 * Get the transport type for the IMS service registration state.
3708 */
3709 @Override
3710 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003711 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3712 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003713 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3714 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3715 "IMS not available on device.");
3716 }
3717 final long token = Binder.clearCallingIdentity();
3718 try {
3719 Phone phone = getPhone(subId);
3720 if (phone == null) {
3721 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3722 + subId + "'");
3723 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3724 }
3725 phone.getImsRegistrationTech(regTech -> {
3726 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3727 int regTechConverted = (regTech == null)
3728 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3729 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3730 regTechConverted);
3731 try {
3732 consumer.accept(regTechConverted);
3733 } catch (RemoteException e) {
3734 // Ignore if the remote process is no longer available to call back.
3735 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3736 }
3737 });
3738 } finally {
3739 Binder.restoreCallingIdentity(token);
3740 }
3741 }
3742
shilu366312e2019-12-17 09:28:10 -08003743 /**
3744 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3745 * @param subId The subscription to use to check the configuration.
3746 * @param c The callback that will be used to send the result.
3747 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003748 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003749 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3750 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003751 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3752 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003753 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3754 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3755 "IMS not available on device.");
3756 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3758 final long token = Binder.clearCallingIdentity();
3759 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 } catch (ImsException e) {
3763 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003764 } finally {
3765 Binder.restoreCallingIdentity(token);
3766 }
3767 }
3768
shilu366312e2019-12-17 09:28:10 -08003769 /**
3770 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3771 * @param subId The subscription to use to check the configuration.
3772 * @param c The callback that will be used to send the result.
3773 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003774 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003775 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003776 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3777 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003778 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3779 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3780 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003781
3782 final long token = Binder.clearCallingIdentity();
3783 try {
3784 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3785 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003786 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003787 } catch (ImsException e) {
3788 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3789 + "is inactive, ignoring unregister.");
3790 // If the subscription is no longer active, just return, since the callback
3791 // will already have been removed internally.
3792 } finally {
3793 Binder.restoreCallingIdentity(token);
3794 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003795 }
3796
3797 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003798 public boolean isCapable(int subId, int capability, int regTech) {
3799 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003800 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3801 final long token = Binder.clearCallingIdentity();
3802 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003803 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003804 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003805 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003806 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3807 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003808 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003809 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3810 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003811 } finally {
3812 Binder.restoreCallingIdentity(token);
3813 }
3814 }
3815
3816 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003817 public boolean isAvailable(int subId, int capability, int regTech) {
3818 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 final long token = Binder.clearCallingIdentity();
3820 try {
3821 Phone phone = getPhone(subId);
3822 if (phone == null) return false;
3823 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003824 } catch (com.android.ims.ImsException e) {
3825 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3826 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003827 } finally {
3828 Binder.restoreCallingIdentity(token);
3829 }
3830 }
3831
Brad Ebinger77b832e2019-10-17 17:03:22 -07003832 /**
3833 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3834 * subscription.
3835 * @param subId The subscription to use to check the configuration.
3836 * @param callback The callback that will be used to send the result.
3837 * @param capability The MmTelFeature capability that will be used to send the result.
3838 * @param transportType The transport type of the MmTelFeature capability.
3839 */
3840 @Override
3841 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3842 int transportType) {
3843 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3844 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3845 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3846 "IMS not available on device.");
3847 }
3848 final long token = Binder.clearCallingIdentity();
3849 try {
3850 int slotId = getSlotIndex(subId);
3851 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3852 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3853 + subId + "'");
3854 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3855 }
3856 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3857 transportType, aBoolean -> {
3858 try {
3859 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3860 } catch (RemoteException e) {
3861 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3862 + "running. Ignore");
3863 }
3864 });
3865 } finally {
3866 Binder.restoreCallingIdentity(token);
3867 }
3868 }
3869
shilu366312e2019-12-17 09:28:10 -08003870 /**
3871 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3872 * @param subId The subscription to use to check the configuration.
3873 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003874 @Override
3875 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003876 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3877 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003878
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3880 final long token = Binder.clearCallingIdentity();
3881 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003882 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003883 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003884 } catch (ImsException e) {
3885 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003886 } finally {
3887 Binder.restoreCallingIdentity(token);
3888 }
3889 }
3890
3891 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003892 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003894 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003895 final long identity = Binder.clearCallingIdentity();
3896 try {
3897 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003898 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003900 } catch (ImsException e) {
3901 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 } finally {
3903 Binder.restoreCallingIdentity(identity);
3904 }
3905 }
3906
shilu366312e2019-12-17 09:28:10 -08003907 /**
3908 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3909 * @param subId The subscription to use to check the configuration.
3910 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003911 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003912 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003913 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3914 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 final long identity = Binder.clearCallingIdentity();
3916 try {
3917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003918 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3919 } catch (ImsException e) {
3920 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
3924 }
3925
3926 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003927 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003929 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003930 final long identity = Binder.clearCallingIdentity();
3931 try {
3932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003933 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003934 } catch (ImsException e) {
3935 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 } finally {
3937 Binder.restoreCallingIdentity(identity);
3938 }
3939 }
3940
shilu366312e2019-12-17 09:28:10 -08003941 /**
3942 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3943 * @param subId The subscription to use to check the configuration.
3944 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 @Override
3946 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003947 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3948 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003952 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003953 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003954 } catch (ImsException e) {
3955 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003956 } finally {
3957 Binder.restoreCallingIdentity(identity);
3958 }
3959 }
3960
3961 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003962 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003964 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 final long identity = Binder.clearCallingIdentity();
3966 try {
3967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003968 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003969 } catch (ImsException e) {
3970 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 } finally {
3972 Binder.restoreCallingIdentity(identity);
3973 }
3974 }
3975
shilu366312e2019-12-17 09:28:10 -08003976 /**
3977 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3978 * @param subId The subscription to use to check the configuration.
3979 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 @Override
3981 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003982 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3983 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 final long identity = Binder.clearCallingIdentity();
3985 try {
3986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003987 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003989 } catch (ImsException e) {
3990 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
3994 }
3995
3996 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003997 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003999 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004003 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004005 } catch (ImsException e) {
4006 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 } finally {
4008 Binder.restoreCallingIdentity(identity);
4009 }
4010 }
4011
4012 @Override
4013 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4015 "setVoWiFiNonPersistent");
4016 final long identity = Binder.clearCallingIdentity();
4017 try {
4018 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004019 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004020 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004021 } catch (ImsException e) {
4022 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 } finally {
4024 Binder.restoreCallingIdentity(identity);
4025 }
4026 }
4027
shilu366312e2019-12-17 09:28:10 -08004028 /**
4029 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4030 * @param subId The subscription to use to check the configuration.
4031 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 @Override
4033 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004034 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4035 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 final long identity = Binder.clearCallingIdentity();
4037 try {
4038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004039 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004041 } catch (ImsException e) {
4042 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 } finally {
4044 Binder.restoreCallingIdentity(identity);
4045 }
4046 }
4047
4048 @Override
4049 public void setVoWiFiModeSetting(int subId, int mode) {
4050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4051 "setVoWiFiModeSetting");
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004055 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004057 } catch (ImsException e) {
4058 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 } finally {
4060 Binder.restoreCallingIdentity(identity);
4061 }
4062 }
4063
4064 @Override
4065 public int getVoWiFiRoamingModeSetting(int subId) {
4066 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4067 final long identity = Binder.clearCallingIdentity();
4068 try {
4069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004070 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004072 } catch (ImsException e) {
4073 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
4077 }
4078
4079 @Override
4080 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4082 "setVoWiFiRoamingModeSetting");
4083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004086 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004088 } catch (ImsException e) {
4089 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 } finally {
4091 Binder.restoreCallingIdentity(identity);
4092 }
4093 }
4094
4095 @Override
4096 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4098 "setRttCapabilityEnabled");
4099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004102 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4103 } catch (ImsException e) {
4104 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004105 } finally {
4106 Binder.restoreCallingIdentity(identity);
4107 }
4108 }
4109
shilu366312e2019-12-17 09:28:10 -08004110 /**
4111 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4112 * @param subId The subscription to use to check the configuration.
4113 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 @Override
4115 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004116 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4117 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004121 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004123 } catch (ImsException e) {
4124 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 } finally {
4126 Binder.restoreCallingIdentity(identity);
4127 }
4128 }
4129
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004130 @Override
4131 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4132 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4133 final long identity = Binder.clearCallingIdentity();
4134 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004135 if (!isImsAvailableOnDevice()) {
4136 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4137 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004138 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004140 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004141 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004142 } catch (ImsException e) {
4143 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
4147 }
4148
4149 @Override
4150 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4151 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4152 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004153 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4154 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4155 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004156 try {
4157 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004158 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004159 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004160 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004161 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4162 + "is inactive, ignoring unregister.");
4163 // If the subscription is no longer active, just return, since the callback will already
4164 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
4168 }
4169
allenwtsu99c623b2020-01-03 18:24:23 +08004170
4171 private void checkModifyPhoneStatePermission(int subId, String message) {
4172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4173 message);
4174 }
4175
4176 private boolean isImsProvisioningRequired(int subId, int capability,
4177 boolean isMmtelCapability) {
4178 Phone phone = getPhone(subId);
4179 if (phone == null) {
4180 loge("phone instance null for subid " + subId);
4181 return false;
4182 }
4183 if (isMmtelCapability) {
4184 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4185 return false;
4186 }
4187 } else {
4188 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4189 return false;
4190 }
4191 }
4192 return true;
4193 }
4194
4195 @Override
4196 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4197 boolean isProvisioned) {
4198 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4199
4200 final long identity = Binder.clearCallingIdentity();
4201 try {
4202 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4203 if (!isImsProvisioningRequired(subId, capability, false)) {
4204 return;
4205 }
4206
4207 // this capability requires provisioning, route to the correct API.
4208 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4209 switch (capability) {
4210 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4211 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4212 ims.setEabProvisioned(isProvisioned);
4213 break;
4214 default: {
4215 throw new IllegalArgumentException("Tried to set provisioning for "
4216 + "rcs capability '" + capability + "', which does not require "
4217 + "provisioning.");
4218 }
4219 }
4220 } finally {
4221 Binder.restoreCallingIdentity(identity);
4222 }
4223
4224 }
4225
4226
4227 @Override
4228 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4229 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4230 final long identity = Binder.clearCallingIdentity();
4231 try {
4232 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4233 if (!isImsProvisioningRequired(subId, capability, false)) {
4234 return true;
4235 }
4236
4237 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4238 switch (capability) {
4239 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4240 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4241 return ims.isEabProvisionedOnDevice();
4242
4243 default: {
4244 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4245 + "capability '" + capability + "', which does not require "
4246 + "provisioning.");
4247 }
4248 }
4249
4250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
4253 }
4254
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004255 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004256 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4257 boolean isProvisioned) {
4258 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4259 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4260 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4261 }
allenwtsu99c623b2020-01-03 18:24:23 +08004262 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004263 final long identity = Binder.clearCallingIdentity();
4264 try {
4265 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004266 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004267 return;
4268 }
4269
4270 // this capability requires provisioning, route to the correct API.
4271 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4272 switch (capability) {
4273 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4274 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4275 ims.setVolteProvisioned(isProvisioned);
4276 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4277 ims.setWfcProvisioned(isProvisioned);
4278 }
4279 break;
4280 }
4281 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4282 // There is currently no difference in VT provisioning type.
4283 ims.setVtProvisioned(isProvisioned);
4284 break;
4285 }
4286 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4287 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4288 // change the capability of the feature instead if needed.
4289 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4290 == isProvisioned) {
4291 // No change in provisioning.
4292 return;
4293 }
4294 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4295 try {
4296 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004297 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004298 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4299 + ", Exception" + e.getMessage());
4300 }
4301 break;
4302 }
4303 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004304 throw new IllegalArgumentException("Tried to set provisioning for "
4305 + "MmTel capability '" + capability + "', which does not require "
4306 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004307 }
4308 }
4309
4310 } finally {
4311 Binder.restoreCallingIdentity(identity);
4312 }
4313 }
4314
4315 @Override
4316 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4317 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4318 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4319 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4320 }
4321 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4322 final long identity = Binder.clearCallingIdentity();
4323 try {
4324 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004325 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004326 return true;
4327 }
4328
4329 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4330 switch (capability) {
4331 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4332 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4333 return ims.isVolteProvisionedOnDevice();
4334 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4335 return ims.isWfcProvisionedOnDevice();
4336 }
4337 // This should never happen, since we are checking tech above to make sure it
4338 // is either LTE or IWLAN.
4339 throw new IllegalArgumentException("Invalid radio technology for voice "
4340 + "capability.");
4341 }
4342 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4343 // There is currently no difference in VT provisioning type.
4344 return ims.isVtProvisionedOnDevice();
4345 }
4346 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4347 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4348 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4349 }
4350 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004351 throw new IllegalArgumentException(
4352 "Tried to get provisioning for MmTel capability '" + capability
4353 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004354 }
4355 }
4356
4357 } finally {
4358 Binder.restoreCallingIdentity(identity);
4359 }
4360 }
4361
4362 @Override
4363 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4364 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4365 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4366 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4367 }
4368 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4369 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4370 return (provisionedBits & capability) > 0;
4371 }
4372
4373 @Override
4374 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4375 boolean isProvisioned) {
4376 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4377 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4378 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4379 }
4380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4381 "setProvisioningStatusForCapability");
4382 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4383 // If the current provisioning status for capability already matches isProvisioned,
4384 // do nothing.
4385 if (((provisionedBits & capability) > 0) == isProvisioned) {
4386 return;
4387 }
4388 if (isProvisioned) {
4389 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4390 } else {
4391 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4392 }
4393 }
4394
4395 /**
4396 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4397 * technology. The bitfield should mirror the bitfield defined by
4398 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4399 */
4400 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4401 String key = getMmTelProvisioningKey(subId, tech);
4402 // Default is no capabilities are provisioned.
4403 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4404 }
4405
4406 /**
4407 * Sets the MmTel capability provisioning bitfield (defined by
4408 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4409 * technology specified.
4410 *
4411 * Note: This is a synchronous command and should not be called on UI thread.
4412 */
4413 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4414 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4415 String key = getMmTelProvisioningKey(subId, tech);
4416 editor.putInt(key, newField);
4417 editor.commit();
4418 }
4419
4420 private static String getMmTelProvisioningKey(int subId, int tech) {
4421 // resulting key is provision_ims_mmtel_{subId}_{tech}
4422 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4423 }
4424
4425 /**
4426 * Query CarrierConfig to see if the specified capability requires provisioning for the
4427 * carrier associated with the subscription id.
4428 */
4429 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4430 int capability) {
4431 CarrierConfigManager configManager = new CarrierConfigManager(context);
4432 PersistableBundle c = configManager.getConfigForSubId(subId);
4433 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004434 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004435 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4436 false);
4437 boolean requireVoiceVtProvisioning = c.getBoolean(
4438 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4439
4440 // First check to make sure that the capability requires provisioning.
4441 switch (capability) {
4442 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4443 // intentional fallthrough
4444 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4445 if (requireVoiceVtProvisioning) {
4446 // Voice and Video requires provisioning
4447 return true;
4448 }
4449 break;
4450 }
4451 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4452 if (requireUtProvisioning) {
4453 // UT requires provisioning
4454 return true;
4455 }
4456 break;
4457 }
4458 }
4459 return false;
4460 }
4461
allenwtsu99c623b2020-01-03 18:24:23 +08004462 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4463 int capability) {
4464 CarrierConfigManager configManager = new CarrierConfigManager(context);
4465 PersistableBundle c = configManager.getConfigForSubId(subId);
4466
4467 boolean requireRcsProvisioning = c.getBoolean(
4468 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4469
4470 // First check to make sure that the capability requires provisioning.
4471 switch (capability) {
4472 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4473 // intentional fallthrough
4474 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4475 if (requireRcsProvisioning) {
4476 // OPTION or PRESENCE requires provisioning
4477 return true;
4478 }
4479 break;
4480 }
4481 }
4482 return false;
4483 }
4484
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004485 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004486 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004487 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4488 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4489 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004490 enforceReadPrivilegedPermission("getImsProvisioningInt");
4491 final long identity = Binder.clearCallingIdentity();
4492 try {
4493 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004494 int slotId = getSlotIndex(subId);
4495 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4496 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4497 + subId + "' for key:" + key);
4498 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4499 }
4500 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004501 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004502 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4503 + subId + "' for key:" + key);
4504 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004505 } finally {
4506 Binder.restoreCallingIdentity(identity);
4507 }
4508 }
4509
4510 @Override
4511 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004512 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4513 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4514 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004515 enforceReadPrivilegedPermission("getImsProvisioningString");
4516 final long identity = Binder.clearCallingIdentity();
4517 try {
4518 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004519 int slotId = getSlotIndex(subId);
4520 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4521 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4522 + subId + "' for key:" + key);
4523 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4524 }
4525 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004526 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004527 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4528 + subId + "' for key:" + key);
4529 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004530 } finally {
4531 Binder.restoreCallingIdentity(identity);
4532 }
4533 }
4534
4535 @Override
4536 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004537 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4538 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4539 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4541 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004542 final long identity = Binder.clearCallingIdentity();
4543 try {
4544 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004545 int slotId = getSlotIndex(subId);
4546 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4547 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4548 + subId + "' for key:" + key);
4549 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4550 }
4551 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004552 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004553 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4554 + "' for key:" + key);
4555 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004556 } finally {
4557 Binder.restoreCallingIdentity(identity);
4558 }
4559 }
4560
4561 @Override
4562 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004563 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4564 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4565 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4567 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004568 final long identity = Binder.clearCallingIdentity();
4569 try {
4570 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004571 int slotId = getSlotIndex(subId);
4572 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4573 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4574 + subId + "' for key:" + key);
4575 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4576 }
4577 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004578 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004579 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4580 + "' for key:" + key);
4581 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
4585 }
4586
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004587 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004588 int slotId = SubscriptionManager.getSlotIndex(subId);
4589 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004590 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4591 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004592 }
4593 return slotId;
4594 }
4595
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004596 private int getSlotIndex(int subId) {
4597 int slotId = SubscriptionManager.getSlotIndex(subId);
4598 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4599 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4600 }
4601 return slotId;
4602 }
4603
Wink Saville36469e72014-06-11 15:17:00 -07004604 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004605 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004606 */
4607 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004608 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4609 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004610 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004611 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004612 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004613 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004614 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004615 mApp, subId, callingPackage, callingFeatureId,
4616 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004617 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4618 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004620 final long identity = Binder.clearCallingIdentity();
4621 try {
4622 final Phone phone = getPhone(subId);
4623 if (phone != null) {
4624 return phone.getServiceState().getDataNetworkType();
4625 } else {
4626 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4627 }
4628 } finally {
4629 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004631 }
4632
4633 /**
4634 * Returns the data network type
4635 */
4636 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004637 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4638 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4639 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004640 }
4641
4642 /**
4643 * Returns the data network type for a subId
4644 */
4645 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004646 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4647 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004649 mApp, subId, callingPackage, callingFeatureId,
4650 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004651 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4652 }
4653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654 final long identity = Binder.clearCallingIdentity();
4655 try {
4656 final Phone phone = getPhone(subId);
4657 if (phone != null) {
4658 return phone.getServiceState().getDataNetworkType();
4659 } else {
4660 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4661 }
4662 } finally {
4663 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004665 }
4666
4667 /**
Wink Saville36469e72014-06-11 15:17:00 -07004668 * Returns the Voice network type for a subId
4669 */
4670 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004671 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4672 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004673 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004674 mApp, subId, callingPackage, callingFeatureId,
4675 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004676 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4677 }
4678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679 final long identity = Binder.clearCallingIdentity();
4680 try {
4681 final Phone phone = getPhone(subId);
4682 if (phone != null) {
4683 return phone.getServiceState().getVoiceNetworkType();
4684 } else {
4685 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4686 }
4687 } finally {
4688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004690 }
4691
4692 /**
4693 * @return true if a ICC card is present
4694 */
4695 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004696 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004697 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4698 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004699 }
4700
4701 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004702 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004703 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004704 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004705 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706 final long identity = Binder.clearCallingIdentity();
4707 try {
4708 final Phone phone = PhoneFactory.getPhone(slotIndex);
4709 if (phone != null) {
4710 return phone.getIccCard().hasIccCard();
4711 } else {
4712 return false;
4713 }
4714 } finally {
4715 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004717 }
4718
4719 /**
4720 * Return if the current radio is LTE on CDMA. This
4721 * is a tri-state return value as for a period of time
4722 * the mode may be unknown.
4723 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004724 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004725 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004726 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004727 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004728 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004729 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4730 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4731 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004732 }
4733
Sanket Padawe356d7632015-06-22 14:03:32 -07004734 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004735 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4736 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004737 try {
4738 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4739 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004740 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4741 }
4742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743 final long identity = Binder.clearCallingIdentity();
4744 try {
4745 final Phone phone = getPhone(subId);
4746 if (phone == null) {
4747 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4748 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004749 return TelephonyProperties.lte_on_cdma_device()
4750 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004751 }
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004754 }
Wink Saville36469e72014-06-11 15:17:00 -07004755 }
4756
Wink Saville36469e72014-06-11 15:17:00 -07004757 /**
4758 * {@hide}
4759 * Returns Default subId, 0 in the case of single standby.
4760 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004761 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004762 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004763 }
4764
Shishir Agrawala9f32182016-04-12 12:00:16 -07004765 private int getSlotForDefaultSubscription() {
4766 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4767 }
4768
Wink Savilleb564aae2014-10-23 10:18:09 -07004769 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004770 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004771 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004772
Pengquan Menge92a50d2018-09-21 15:54:48 -07004773 private boolean isActiveSubscription(int subId) {
4774 return mSubscriptionController.isActiveSubId(subId);
4775 }
4776
Ihab Awadf2177b72013-11-25 13:33:23 -08004777 /**
4778 * @see android.telephony.TelephonyManager.WifiCallingChoices
4779 */
4780 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 final long identity = Binder.clearCallingIdentity();
4782 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004783 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4785 getWhenToMakeWifiCallsDefaultPreference());
4786 } finally {
4787 Binder.restoreCallingIdentity(identity);
4788 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004789 }
4790
4791 /**
4792 * @see android.telephony.TelephonyManager.WifiCallingChoices
4793 */
4794 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004795 final long identity = Binder.clearCallingIdentity();
4796 try {
4797 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004798 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4800 } finally {
4801 Binder.restoreCallingIdentity(identity);
4802 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004803 }
4804
Sailesh Nepald1e68152013-12-12 19:08:02 -08004805 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004806 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004807 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004808 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004809
Jordan Liu4c733742019-02-28 12:03:40 -08004810 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4811 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4812 if (phoneId == -1) {
4813 throw new IllegalArgumentException("Given slot index: " + slotIndex
4814 + " does not correspond to an active phone");
4815 }
4816 return PhoneFactory.getPhone(phoneId);
4817 }
4818
Shishir Agrawal566b7612013-10-28 14:41:00 -07004819 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004820 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4821 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4823 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004825 if (DBG) {
4826 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4827 }
4828 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4829 p2);
4830 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004831
Jordan Liu4c733742019-02-28 12:03:40 -08004832
4833 @Override
4834 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4835 int slotIndex, String callingPackage, String aid, int p2) {
4836 enforceModifyPermission();
4837 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4838 if (DBG) {
4839 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4840 }
4841 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4842 callingPackage, aid, p2);
4843 }
4844
4845 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4846 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847 final long identity = Binder.clearCallingIdentity();
4848 try {
4849 if (TextUtils.equals(ISDR_AID, aid)) {
4850 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004851 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4852 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853 if (bestComponent == null
4854 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4855 loge("The calling package is not allowed to access ISD-R.");
4856 throw new SecurityException(
4857 "The calling package is not allowed to access ISD-R.");
4858 }
Derek Tan740e1672017-06-27 14:56:27 -07004859 }
Derek Tan740e1672017-06-27 14:56:27 -07004860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004862 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4863 null /* workSource */);
4864 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865 return response;
4866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004869 }
4870
4871 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004872 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4874 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004875 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4876 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4877 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004878
Jordan Liu4c733742019-02-28 12:03:40 -08004879 @Override
4880 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4881 enforceModifyPermission();
4882 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4883 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4884 channel);
4885 }
4886
4887 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890 if (channel < 0) {
4891 return false;
4892 }
Jordan Liu4c733742019-02-28 12:03:40 -08004893 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4894 null /* workSource */);
4895 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896 return success;
4897 } finally {
4898 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004899 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004900 }
4901
4902 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004903 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004904 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4906 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004907 if (DBG) {
4908 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4909 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4910 + p3 + " data=" + data);
4911 }
4912 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4913 command, p1, p2, p3, data);
4914 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004915
Jordan Liu4c733742019-02-28 12:03:40 -08004916 @Override
4917 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4918 int command, int p1, int p2, int p3, String data) {
4919 enforceModifyPermission();
4920 if (DBG) {
4921 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4922 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4923 + p3 + " data=" + data);
4924 }
4925 return iccTransmitApduLogicalChannelWithPermission(
4926 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4927 data);
4928 }
4929
4930 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4931 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 final long identity = Binder.clearCallingIdentity();
4933 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004934 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 return "";
4936 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004939 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4940 null /* workSource */);
4941 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 // Append the returned status code to the end of the response payload.
4944 String s = Integer.toHexString(
4945 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4946 if (response.payload != null) {
4947 s = IccUtils.bytesToHexString(response.payload) + s;
4948 }
4949 return s;
4950 } finally {
4951 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004952 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004953 }
Jake Hambye994d462014-02-03 13:10:13 -08004954
Evan Charltonc66da362014-05-16 14:06:40 -07004955 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004956 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4957 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4959 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004961 if (DBG) {
4962 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4963 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4964 }
4965 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4966 cla, command, p1, p2, p3, data);
4967 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004968
Jordan Liu4c733742019-02-28 12:03:40 -08004969 @Override
4970 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4971 int command, int p1, int p2, int p3, String data) {
4972 enforceModifyPermission();
4973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4974 if (DBG) {
4975 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4976 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4977 + " data=" + data);
4978 }
4979
4980 return iccTransmitApduBasicChannelWithPermission(
4981 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4982 p2, p3, data);
4983 }
4984
4985 // open APDU basic channel assuming the caller has sufficient permissions
4986 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4987 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4991 && TextUtils.equals(ISDR_AID, data)) {
4992 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004993 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4994 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 if (bestComponent == null
4996 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4997 loge("The calling package is not allowed to select ISD-R.");
4998 throw new SecurityException(
4999 "The calling package is not allowed to select ISD-R.");
5000 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005001 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005002
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005004 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5005 null /* workSource */);
5006 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005007
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008 // Append the returned status code to the end of the response payload.
5009 String s = Integer.toHexString(
5010 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5011 if (response.payload != null) {
5012 s = IccUtils.bytesToHexString(response.payload) + s;
5013 }
5014 return s;
5015 } finally {
5016 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005017 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005018 }
5019
5020 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005021 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005022 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5024 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 if (DBG) {
5029 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5030 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5031 }
5032
5033 IccIoResult response =
5034 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5035 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5036 subId);
5037
5038 if (DBG) {
5039 log("Exchange SIM_IO [R]" + response);
5040 }
5041
5042 byte[] result = null;
5043 int length = 2;
5044 if (response.payload != null) {
5045 length = 2 + response.payload.length;
5046 result = new byte[length];
5047 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5048 } else {
5049 result = new byte[length];
5050 }
5051
5052 result[length - 1] = (byte) response.sw2;
5053 result[length - 2] = (byte) response.sw1;
5054 return result;
5055 } finally {
5056 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005057 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005058 }
5059
Nathan Haroldb3014052017-01-25 15:57:32 -08005060 /**
5061 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5062 * on a particular subscription
5063 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005064 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5065 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005067 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005068 return null;
5069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005070
5071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 if (appType != TelephonyManager.APPTYPE_USIM
5074 && appType != TelephonyManager.APPTYPE_SIM) {
5075 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5076 return null;
5077 }
5078 Object response = sendRequest(
5079 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5080 if (response instanceof String[]) {
5081 return (String[]) response;
5082 }
yincheng zhaod698b842019-09-06 17:06:54 -07005083 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005084 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005085 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 } finally {
5087 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005088 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005089 }
5090
yincheng zhaod698b842019-09-06 17:06:54 -07005091 /**
5092 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5093 * subscription.
5094 *
5095 * @param subId the id of the subscription.
5096 * @param appType the uicc app type, must be USIM or SIM.
5097 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5098 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005099 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005100 * @return number of fplmns that is successfully written to the SIM.
5101 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005102 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5103 String callingFeatureId) {
5104 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5105 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005106 if (DBG) logv("no permissions for setForbiddenplmns");
5107 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5108 }
5109 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5110 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5111 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5112 }
5113 if (fplmns == null) {
5114 throw new IllegalArgumentException("Fplmn List provided is null");
5115 }
5116 for (String fplmn : fplmns) {
5117 if (!CellIdentity.isValidPlmn(fplmn)) {
5118 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5119 }
5120 }
5121 final long identity = Binder.clearCallingIdentity();
5122 try {
5123 Object response = sendRequest(
5124 CMD_SET_FORBIDDEN_PLMNS,
5125 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5126 subId);
5127 return (int) response;
5128 } finally {
5129 Binder.restoreCallingIdentity(identity);
5130 }
5131 }
5132
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005133 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005134 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5136 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 final long identity = Binder.clearCallingIdentity();
5139 try {
5140 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5141 if (response.payload == null) {
5142 return "";
5143 }
Evan Charltonc66da362014-05-16 14:06:40 -07005144
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 // Append the returned status code to the end of the response payload.
5146 String s = Integer.toHexString(
5147 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5148 s = IccUtils.bytesToHexString(response.payload) + s;
5149 return s;
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
5152 }
Evan Charltonc66da362014-05-16 14:06:40 -07005153 }
5154
Jake Hambye994d462014-02-03 13:10:13 -08005155 /**
5156 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5157 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5158 *
5159 * @param itemID the ID of the item to read
5160 * @return the NV item as a String, or null on error.
5161 */
5162 @Override
5163 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005164 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5166 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167
5168 final long identity = Binder.clearCallingIdentity();
5169 try {
5170 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005171 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5173 return value;
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
Jake Hambye994d462014-02-03 13:10:13 -08005177 }
5178
5179 /**
5180 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5181 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5182 *
5183 * @param itemID the ID of the item to read
5184 * @param itemValue the value to write, as a String
5185 * @return true on success; false on any failure
5186 */
5187 @Override
5188 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005189 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5191 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192
5193 final long identity = Binder.clearCallingIdentity();
5194 try {
5195 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5196 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005197 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5199 return success;
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
5202 }
Jake Hambye994d462014-02-03 13:10:13 -08005203 }
5204
5205 /**
5206 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5207 * Used for device configuration by some CDMA operators.
5208 *
5209 * @param preferredRoamingList byte array containing the new PRL
5210 * @return true on success; false on any failure
5211 */
5212 @Override
5213 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5215 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216
5217 final long identity = Binder.clearCallingIdentity();
5218 try {
5219 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5220 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5221 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5222 return success;
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
5225 }
Jake Hambye994d462014-02-03 13:10:13 -08005226 }
5227
5228 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005229 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005230 * Used for device configuration by some CDMA operators.
5231 *
chen xu6dac5ab2018-10-26 17:39:23 -07005232 * @param slotIndex - device slot.
5233 *
Jake Hambye994d462014-02-03 13:10:13 -08005234 * @return true on success; false on any failure
5235 */
5236 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005237 public boolean resetModemConfig(int slotIndex) {
5238 Phone phone = PhoneFactory.getPhone(slotIndex);
5239 if (phone != null) {
5240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5241 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242
chen xu6dac5ab2018-10-26 17:39:23 -07005243 final long identity = Binder.clearCallingIdentity();
5244 try {
5245 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5246 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5247 return success;
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 }
chen xu6dac5ab2018-10-26 17:39:23 -07005252 return false;
5253 }
5254
5255 /**
5256 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5257 *
5258 * @param slotIndex - device slot.
5259 *
5260 * @return true on success; false on any failure
5261 */
5262 @Override
5263 public boolean rebootModem(int slotIndex) {
5264 Phone phone = PhoneFactory.getPhone(slotIndex);
5265 if (phone != null) {
5266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5267 mApp, phone.getSubId(), "rebootModem");
5268
5269 final long identity = Binder.clearCallingIdentity();
5270 try {
5271 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5272 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5273 return success;
5274 } finally {
5275 Binder.restoreCallingIdentity(identity);
5276 }
5277 }
5278 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005279 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005280
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005281 public String[] getPcscfAddress(String apnType, String callingPackage,
5282 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005283 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5285 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005286 return new String[0];
5287 }
5288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 final long identity = Binder.clearCallingIdentity();
5290 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005291 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 } finally {
5293 Binder.restoreCallingIdentity(identity);
5294 }
Wink Saville36469e72014-06-11 15:17:00 -07005295 }
5296
Brad Ebinger51f743a2017-01-23 13:50:20 -08005297 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005298 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5299 * {@link #disableIms(int)}.
5300 * @param slotIndex device slot.
5301 */
5302 public void resetIms(int slotIndex) {
5303 enforceModifyPermission();
5304
5305 final long identity = Binder.clearCallingIdentity();
5306 try {
5307 if (mImsResolver == null) {
5308 // may happen if the does not support IMS.
5309 return;
5310 }
5311 mImsResolver.disableIms(slotIndex);
5312 mImsResolver.enableIms(slotIndex);
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
5316 }
5317
5318 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005319 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5320 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005321 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005322 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005323 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324
5325 final long identity = Binder.clearCallingIdentity();
5326 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005327 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005328 // may happen if the device does not support IMS.
5329 return;
5330 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005331 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005335 }
5336
5337 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005338 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5339 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005340 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005341 public void disableIms(int slotId) {
5342 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343
5344 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;
5349 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005350 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005354 }
5355
5356 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005357 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5358 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005359 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005360 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005361 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005362 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363
5364 final long identity = Binder.clearCallingIdentity();
5365 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005366 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005367 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5368 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005369 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005370 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 } finally {
5372 Binder.restoreCallingIdentity(identity);
5373 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005374 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005375 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005376 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5377 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005378 @Override
5379 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005380 enforceModifyPermission();
5381
5382 final long identity = Binder.clearCallingIdentity();
5383 try {
5384 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005385 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388 }
5389 }
5390
5391 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005392 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005393 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005394 */
5395 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5396 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397
5398 final long identity = Binder.clearCallingIdentity();
5399 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005400 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005401 // may happen if the device does not support IMS.
5402 return null;
5403 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005404 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 } finally {
5406 Binder.restoreCallingIdentity(identity);
5407 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005408 }
5409
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005410 /**
5411 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005412 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005413 */
5414 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5415 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416
5417 final long identity = Binder.clearCallingIdentity();
5418 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005419 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005420 // may happen if the device does not support IMS.
5421 return null;
5422 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005423 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 } finally {
5425 Binder.restoreCallingIdentity(identity);
5426 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005427 }
5428
Brad Ebinger884c07b2018-02-15 16:17:40 -08005429 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005430 * Sets the ImsService Package Name that Telephony will bind to.
5431 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005432 * @param slotIndex the slot ID that the ImsService should bind for.
5433 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005434 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005435 * @param featureTypes An integer array of feature types associated with a packageName.
5436 * @param packageName The name of the package that the current configuration will be replaced
5437 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005438 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005439 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005440 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5441 int[] featureTypes, String packageName) {
5442 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5443 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5445 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005446 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 final long identity = Binder.clearCallingIdentity();
5449 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005450 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005451 // may happen if the device does not support IMS.
5452 return false;
5453 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005454 Map<Integer, String> featureConfig = new HashMap<>();
5455 for (int featureType : featureTypes) {
5456 featureConfig.put(featureType, packageName);
5457 }
5458 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5459 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005463 }
5464
5465 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005466 * Clears any carrier ImsService overrides for the slot index specified that were previously
5467 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5468 *
5469 * This should only be used for testing.
5470 *
5471 * @param slotIndex the slot ID that the ImsService should bind for.
5472 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5473 */
5474 @Override
5475 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5476 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5477 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5478 "clearCarrierImsServiceOverride");
5479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5480 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5481 "clearCarrierImsServiceOverride");
5482
5483 final long identity = Binder.clearCallingIdentity();
5484 try {
5485 if (mImsResolver == null) {
5486 // may happen if the device does not support IMS.
5487 return false;
5488 }
5489 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5490 } finally {
5491 Binder.restoreCallingIdentity(identity);
5492 }
5493 }
5494
5495 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005496 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005497 *
5498 * @param slotId The slot that the ImsService is associated with.
5499 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5500 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005501 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005502 * @return the package name of the ImsService configuration.
5503 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005504 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5505 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005506 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005507 TelephonyPermissions
5508 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5509 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5510 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 final long identity = Binder.clearCallingIdentity();
5513 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005514 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005515 // may happen if the device does not support IMS.
5516 return "";
5517 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005518 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005519 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5520 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 } finally {
5522 Binder.restoreCallingIdentity(identity);
5523 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005524 }
5525
Brad Ebinger77b832e2019-10-17 17:03:22 -07005526 /**
5527 * Get the MmTelFeature state associated with the requested subscription id.
5528 * @param subId The subscription that the MmTelFeature is associated with.
5529 * @param callback A callback with an integer containing the
5530 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5531 */
5532 @Override
5533 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5534 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5535 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5536 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5537 "IMS not available on device.");
5538 }
5539 final long token = Binder.clearCallingIdentity();
5540 try {
5541 int slotId = getSlotIndex(subId);
5542 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5543 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5544 + subId + "'");
5545 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5546 }
5547 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5548 try {
5549 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5550 } catch (RemoteException e) {
5551 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5552 + "Ignore");
5553 }
5554 });
5555 } finally {
5556 Binder.restoreCallingIdentity(token);
5557 }
5558 }
5559
Daniel Brightbb5840b2021-01-12 15:48:18 -08005560 /**
5561 * Sets the ims registration state on all valid {@link Phone}s.
5562 */
5563 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005564 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565
5566 final long identity = Binder.clearCallingIdentity();
5567 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005568 // NOTE: Before S, this method only set the default phone.
5569 for (final Phone phone : PhoneFactory.getPhones()) {
5570 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5571 phone.setImsRegistrationState(registered);
5572 }
5573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 } finally {
5575 Binder.restoreCallingIdentity(identity);
5576 }
Wink Saville36469e72014-06-11 15:17:00 -07005577 }
5578
5579 /**
Stuart Scott54788802015-03-30 13:18:01 -07005580 * Set the network selection mode to automatic.
5581 *
5582 */
5583 @Override
5584 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5586 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587
5588 final long identity = Binder.clearCallingIdentity();
5589 try {
shilufc958392020-01-20 11:36:01 -08005590 if (!isActiveSubscription(subId)) {
5591 return;
5592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5594 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
Stuart Scott54788802015-03-30 13:18:01 -07005598 }
5599
Jack Yud10cdd42020-09-28 20:28:01 -07005600 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005601 * Ask the radio to connect to the input network and change selection mode to manual.
5602 *
5603 * @param subId the id of the subscription.
5604 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5605 * the operator to attach to.
5606 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5607 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5608 * normal network selection next time.
5609 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005610 */
5611 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005612 public boolean setNetworkSelectionModeManual(
5613 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5615 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005616
5617 if (!isActiveSubscription(subId)) {
5618 return false;
5619 }
5620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 final long identity = Binder.clearCallingIdentity();
5622 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005623 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005625 if (DBG) {
5626 log("setNetworkSelectionModeManual: subId: " + subId
5627 + " operator: " + operatorInfo);
5628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005633 }
shilu84f6e8b2019-12-19 13:58:01 -08005634 /**
5635 * Get the manual network selection
5636 *
5637 * @param subId the id of the subscription.
5638 *
5639 * @return the previously saved user selected PLMN
5640 */
5641 @Override
5642 public String getManualNetworkSelectionPlmn(int subId) {
5643 TelephonyPermissions
5644 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5645 mApp, subId, "getManualNetworkSelectionPlmn");
5646
5647 final long identity = Binder.clearCallingIdentity();
5648 try {
5649 if (!isActiveSubscription(subId)) {
5650 return "";
5651 }
5652
5653 final Phone phone = getPhone(subId);
5654 if (phone == null) {
5655 return "";
5656 }
5657 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5658 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5659 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
5663 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005664
5665 /**
5666 * Scans for available networks.
5667 */
5668 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005669 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5670 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5672 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005673 LocationAccessPolicy.LocationPermissionResult locationResult =
5674 LocationAccessPolicy.checkLocationPermission(mApp,
5675 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5676 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005677 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005678 .setCallingPid(Binder.getCallingPid())
5679 .setCallingUid(Binder.getCallingUid())
5680 .setMethod("getCellNetworkScanResults")
5681 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5682 .build());
5683 switch (locationResult) {
5684 case DENIED_HARD:
5685 throw new SecurityException("Not allowed to access scan results -- location");
5686 case DENIED_SOFT:
5687 return null;
5688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689
Pengquan Menga1bb6272018-09-06 09:59:22 -07005690 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005691 try {
5692 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005693 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 } finally {
5696 Binder.restoreCallingIdentity(identity);
5697 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005698 }
5699
5700 /**
sqian80370722020-01-29 15:02:51 -08005701 * Get the call forwarding info, given the call forwarding reason.
5702 */
5703 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005704 public void getCallForwarding(int subId, int callForwardingReason,
5705 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005706 enforceReadPrivilegedPermission("getCallForwarding");
5707 long identity = Binder.clearCallingIdentity();
5708 try {
5709 if (DBG) {
5710 log("getCallForwarding: subId " + subId
5711 + " callForwardingReason" + callForwardingReason);
5712 }
Hall Liua1acea22020-09-18 19:04:59 -07005713
5714 Phone phone = getPhone(subId);
5715 if (phone == null) {
5716 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005717 callback.onError(
5718 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005719 } catch (RemoteException e) {
5720 // ignore
5721 }
5722 return;
5723 }
5724
5725 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5726 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5727 @Override
5728 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5729 try {
5730 callback.onCallForwardingInfoAvailable(info);
5731 } catch (RemoteException e) {
5732 // ignore
5733 }
5734 }
5735
5736 @Override
5737 public void onError(int error) {
5738 try {
5739 callback.onError(error);
5740 } catch (RemoteException e) {
5741 // ignore
5742 }
5743 }
5744 });
5745 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005746 } finally {
5747 Binder.restoreCallingIdentity(identity);
5748 }
5749 }
5750
5751 /**
5752 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5753 * reason, the number to forward, and the timeout before the forwarding is attempted.
5754 */
5755 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005756 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5757 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005758 enforceModifyPermission();
5759 long identity = Binder.clearCallingIdentity();
5760 try {
5761 if (DBG) {
5762 log("setCallForwarding: subId " + subId
5763 + " callForwardingInfo" + callForwardingInfo);
5764 }
Hall Liua1acea22020-09-18 19:04:59 -07005765
5766 Phone phone = getPhone(subId);
5767 if (phone == null) {
5768 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005769 callback.accept(
5770 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005771 } catch (RemoteException e) {
5772 // ignore
5773 }
5774 return;
5775 }
5776
5777 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5778 FunctionalUtils.ignoreRemoteException(callback::accept));
5779
5780 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005781 } finally {
5782 Binder.restoreCallingIdentity(identity);
5783 }
5784 }
5785
5786 /**
Hall Liua1acea22020-09-18 19:04:59 -07005787 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005788 */
5789 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005790 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005791 enforceReadPrivilegedPermission("getCallForwarding");
5792 long identity = Binder.clearCallingIdentity();
5793 try {
Hall Liua1acea22020-09-18 19:04:59 -07005794
5795 Phone phone = getPhone(subId);
5796 if (phone == null) {
5797 try {
5798 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5799 } catch (RemoteException e) {
5800 // ignore
5801 }
5802 return;
5803 }
5804
5805 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5806
sqian80370722020-01-29 15:02:51 -08005807 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005808 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005809 } finally {
5810 Binder.restoreCallingIdentity(identity);
5811 }
5812 }
5813
5814 /**
Hall Liua1acea22020-09-18 19:04:59 -07005815 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005816 */
5817 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005818 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005819 enforceModifyPermission();
5820 long identity = Binder.clearCallingIdentity();
5821 try {
Hall Liua1acea22020-09-18 19:04:59 -07005822 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5823
5824 Phone phone = getPhone(subId);
5825 if (phone == null) {
5826 try {
5827 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5828 } catch (RemoteException e) {
5829 // ignore
5830 }
5831 return;
5832 }
5833
5834 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5835 FunctionalUtils.ignoreRemoteException(callback::accept));
5836
5837 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005838 } finally {
5839 Binder.restoreCallingIdentity(identity);
5840 }
5841 }
5842
5843 /**
yinxub1bed742017-04-17 11:45:04 -07005844 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005845 *
yinxub1bed742017-04-17 11:45:04 -07005846 * @param subId id of the subscription
5847 * @param request contains the radio access networks with bands/channels to scan
5848 * @param messenger callback messenger for scan results or errors
5849 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005850 * @return the id of the requested scan which can be used to stop the scan.
5851 */
5852 @Override
5853 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005854 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5856 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005857 LocationAccessPolicy.LocationPermissionResult locationResult =
5858 LocationAccessPolicy.checkLocationPermission(mApp,
5859 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5860 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005861 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005862 .setCallingPid(Binder.getCallingPid())
5863 .setCallingUid(Binder.getCallingUid())
5864 .setMethod("requestNetworkScan")
5865 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5866 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005867 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005868 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5869 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005870 if (e != null) {
5871 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5872 throw e;
5873 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005874 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005875 return TelephonyScanManager.INVALID_SCAN_ID;
5876 }
5877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005878 }
Hall Liu912dfd32019-04-25 14:02:26 -07005879 int callingUid = Binder.getCallingUid();
5880 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 return mNetworkScanRequestTracker.startNetworkScan(
5884 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005885 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005886 } finally {
5887 Binder.restoreCallingIdentity(identity);
5888 }
yinxu504e1392017-04-12 16:03:22 -07005889 }
5890
Hall Liub2ac8ef2019-02-28 15:56:23 -08005891 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005892 NetworkScanRequest request, int subId, String callingPackage) {
5893 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005894 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5895 boolean hasNetworkScanPermission =
5896 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5897 == PERMISSION_GRANTED;
5898
5899 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5900 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5901 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005902 }
5903
5904 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5905 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005906 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5907 return new SecurityException("Specific channels must not be"
5908 + " scanned without location access.");
5909 }
5910 }
5911 }
5912
Hall Liub2ac8ef2019-02-28 15:56:23 -08005913 return null;
5914 }
5915
yinxu504e1392017-04-12 16:03:22 -07005916 /**
5917 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005918 *
5919 * @param subId id of the subscription
5920 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005921 */
5922 @Override
5923 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5925 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926
Hall Liu912dfd32019-04-25 14:02:26 -07005927 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 final long identity = Binder.clearCallingIdentity();
5929 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005930 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
yinxu504e1392017-04-12 16:03:22 -07005934 }
5935
5936 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005937 * Get the calculated preferred network type.
5938 * Used for debugging incorrect network type.
5939 *
5940 * @return the preferred network type, defined in RILConstants.java.
5941 */
5942 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005943 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005944 final Phone defaultPhone = getDefaultPhone();
5945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005946 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005947 return RILConstants.PREFERRED_NETWORK_MODE;
5948 }
5949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950 final long identity = Binder.clearCallingIdentity();
5951 try {
5952 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005953 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 } finally {
5955 Binder.restoreCallingIdentity(identity);
5956 }
Junda Liu84d15a22014-07-02 11:21:04 -07005957 }
5958
5959 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005960 * Get the preferred network type.
5961 * Used for device configuration by some CDMA operators.
5962 *
5963 * @return the preferred network type, defined in RILConstants.java.
5964 */
5965 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005966 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005967 TelephonyPermissions
5968 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5969 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970
5971 final long identity = Binder.clearCallingIdentity();
5972 try {
5973 if (DBG) log("getPreferredNetworkType");
5974 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5975 int networkType = (result != null ? result[0] : -1);
5976 if (DBG) log("getPreferredNetworkType: " + networkType);
5977 return networkType;
5978 } finally {
5979 Binder.restoreCallingIdentity(identity);
5980 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005981 }
5982
5983 /**
5984 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005985 *
5986 * @param networkType the preferred network type, defined in RILConstants.java.
5987 * @return true on success; false on any failure.
5988 */
5989 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005990 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5992 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993
5994 final long identity = Binder.clearCallingIdentity();
5995 try {
calvinpan089c2a62020-03-12 14:17:55 +08005996 Boolean success = (Boolean) sendRequest(
5997 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005998
5999 if (success) {
6000 Settings.Global.putInt(mApp.getContentResolver(),
6001 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
6002 }
calvinpan089c2a62020-03-12 14:17:55 +08006003 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
6004 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 } finally {
6006 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07006007 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006008 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006009
6010 /**
calvinpan677fc2b2020-01-14 20:42:55 +08006011 * Get the allowed network types that store in the telephony provider.
6012 *
6013 * @param subId the id of the subscription.
6014 * @return allowedNetworkTypes the allowed network types.
6015 */
6016 @Override
6017 public long getAllowedNetworkTypes(int subId) {
6018 TelephonyPermissions
6019 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6020 mApp, subId, "getAllowedNetworkTypes");
6021
6022 final long identity = Binder.clearCallingIdentity();
6023 try {
6024 return SubscriptionManager.getLongSubscriptionProperty(
6025 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6026 } finally {
6027 Binder.restoreCallingIdentity(identity);
6028 }
6029 }
6030
6031 /**
6032 * Set the allowed network types.
6033 *
6034 * @param subId the id of the subscription.
6035 * @param allowedNetworkTypes the allowed network types.
6036 * @return true on success; false on any failure.
6037 */
6038 @Override
6039 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6041 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08006042
calvinpan089c2a62020-03-12 14:17:55 +08006043 SubscriptionManager.setSubscriptionProperty(subId,
6044 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6045 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08006046
calvinpan089c2a62020-03-12 14:17:55 +08006047 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6048 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6049 RILConstants.PREFERRED_NETWORK_MODE);
6050 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08006051 }
6052
6053 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006054 * Get the allowed network types for certain reason.
6055 *
6056 * @param subId the id of the subscription.
6057 * @param reason the reason the allowed network type change is taking place
6058 * @return the allowed network types.
6059 */
6060 @Override
6061 public long getAllowedNetworkTypesForReason(int subId,
6062 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6063 TelephonyPermissions
6064 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6065 mApp, subId, "getAllowedNetworkTypesForReason");
6066 final long identity = Binder.clearCallingIdentity();
6067 try {
6068 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6069 } finally {
6070 Binder.restoreCallingIdentity(identity);
6071 }
6072 }
6073
6074 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006075 * Enable/Disable E-UTRA-NR Dual Connectivity
6076 * @param subId subscription id of the sim card
6077 * @param nrDualConnectivityState expected NR dual connectivity state
6078 * This can be passed following states
6079 * <ol>
6080 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6081 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6082 * <li>Disable NR dual connectivity and force secondary cell to be released
6083 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6084 * </ol>
6085 * @return operation result.
6086 */
6087 @Override
6088 public int setNrDualConnectivityState(int subId,
6089 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6091 mApp, subId, "enableNRDualConnectivity");
6092 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6093 final long identity = Binder.clearCallingIdentity();
6094 try {
6095 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6096 nrDualConnectivityState, subId,
6097 workSource);
6098 if (DBG) log("enableNRDualConnectivity result: " + result);
6099 return result;
6100 } finally {
6101 Binder.restoreCallingIdentity(identity);
6102 }
6103 }
6104
6105 /**
6106 * Is E-UTRA-NR Dual Connectivity enabled
6107 * @return true if dual connectivity is enabled else false
6108 */
6109 @Override
6110 public boolean isNrDualConnectivityEnabled(int subId) {
6111 TelephonyPermissions
6112 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6113 mApp, subId, "isNRDualConnectivityEnabled");
6114 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6115 final long identity = Binder.clearCallingIdentity();
6116 try {
6117 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6118 null, subId, workSource);
6119 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6120 return isEnabled;
6121 } finally {
6122 Binder.restoreCallingIdentity(identity);
6123 }
6124 }
6125
6126 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006127 * get carrier bandwidth per primary and secondary carrier
6128 * @param subId subscription id of the sim card
6129 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6130 */
6131 @Override
6132 public CarrierBandwidth getCarrierBandwidth(int subId) {
6133 TelephonyPermissions
6134 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6135 mApp, subId, "isNRDualConnectivityEnabled");
6136 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6137 final long identity = Binder.clearCallingIdentity();
6138 try {
6139 CarrierBandwidth carrierBandwidth =
6140 getPhoneFromSubId(subId).getCarrierBandwidth();
6141 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6142 return carrierBandwidth;
6143 } finally {
6144 Binder.restoreCallingIdentity(identity);
6145 }
6146 }
6147
6148 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006149 * Get the effective allowed network types on the device.
6150 * This API will return an intersection of allowed network types for all reasons,
6151 * including the configuration done through setAllowedNetworkTypes
6152 *
6153 * @param subId the id of the subscription.
6154 * @return the allowed network types
6155 */
6156 @Override
6157 public long getEffectiveAllowedNetworkTypes(int subId) {
6158 TelephonyPermissions
6159 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6160 mApp, subId, "getEffectiveAllowedNetworkTypes");
6161 final long identity = Binder.clearCallingIdentity();
6162 try {
6163 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6164 } finally {
6165 Binder.restoreCallingIdentity(identity);
6166 }
6167 }
6168
6169 /**
6170 * Set the allowed network types of the device and
6171 * provide the reason triggering the allowed network change.
6172 *
6173 * @param subId the id of the subscription.
6174 * @param reason the reason the allowed network type change is taking place
6175 * @param allowedNetworkTypes the allowed network types.
6176 * @return true on success; false on any failure.
6177 */
6178 @Override
6179 public boolean setAllowedNetworkTypesForReason(int subId,
6180 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6182 mApp, subId, "setAllowedNetworkTypesForReason");
6183 final long identity = Binder.clearCallingIdentity();
6184 try {
6185 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6186 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6187 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6188 RILConstants.PREFERRED_NETWORK_MODE);
6189 return setPreferredNetworkType(subId, preferredNetworkMode);
6190 } finally {
6191 Binder.restoreCallingIdentity(identity);
6192 }
6193 }
6194
6195 /**
Miaoa84611c2019-03-15 09:21:10 +08006196 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006197 *
Miaoa84611c2019-03-15 09:21:10 +08006198 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006199 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006200 * @hide
6201 */
6202 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006203 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006204 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006206 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207 try {
Miaoa84611c2019-03-15 09:21:10 +08006208 if (phone != null) {
6209 return phone.hasMatchedTetherApnSetting();
6210 } else {
6211 return false;
6212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 } finally {
6214 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006215 }
Junda Liu475951f2014-11-07 16:45:03 -08006216 }
6217
6218 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006219 * Enable or disable always reporting signal strength changes from radio.
6220 *
6221 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6222 */
6223 @Override
6224 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6225 enforceModifyPermission();
6226 enforceSystemCaller();
6227
6228 final long identity = Binder.clearCallingIdentity();
6229 final Phone phone = getPhone(subId);
6230 try {
6231 if (phone != null) {
6232 if (DBG) {
6233 log("setAlwaysReportSignalStrength: subId=" + subId
6234 + " isEnable=" + isEnable);
6235 }
6236 phone.setAlwaysReportSignalStrength(isEnable);
6237 } else {
6238 loge("setAlwaysReportSignalStrength: no phone found for subId="
6239 + subId);
6240 }
6241 } finally {
6242 Binder.restoreCallingIdentity(identity);
6243 }
6244 }
6245
6246 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006247 * Get the user enabled state of Mobile Data.
6248 *
6249 * TODO: remove and use isUserDataEnabled.
6250 * This can't be removed now because some vendor codes
6251 * calls through ITelephony directly while they should
6252 * use TelephonyManager.
6253 *
6254 * @return true on enabled
6255 */
6256 @Override
6257 public boolean getDataEnabled(int subId) {
6258 return isUserDataEnabled(subId);
6259 }
6260
6261 /**
6262 * Get whether mobile data is enabled per user setting.
6263 *
6264 * There are other factors deciding whether mobile data is actually enabled, but they are
6265 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006266 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006267 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006268 *
6269 * @return {@code true} if data is enabled else {@code false}
6270 */
6271 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006272 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006273 try {
6274 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6275 null);
6276 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6278 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280
6281 final long identity = Binder.clearCallingIdentity();
6282 try {
6283 int phoneId = mSubscriptionController.getPhoneId(subId);
6284 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6285 Phone phone = PhoneFactory.getPhone(phoneId);
6286 if (phone != null) {
6287 boolean retVal = phone.isUserDataEnabled();
6288 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6289 return retVal;
6290 } else {
6291 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6292 return false;
6293 }
6294 } finally {
6295 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006296 }
6297 }
6298
6299 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006300 * Checks if the device is capable of mobile data by considering whether whether the
6301 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6302 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006303 *
Shuo Qian985d1232020-01-08 14:30:06 -08006304 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006305 */
6306 @Override
6307 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006308 try {
6309 try {
6310 mApp.enforceCallingOrSelfPermission(
6311 android.Manifest.permission.ACCESS_NETWORK_STATE,
6312 null);
6313 } catch (Exception e) {
6314 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6315 "isDataEnabled");
6316 }
6317 } catch (Exception e) {
6318 enforceReadPrivilegedPermission("isDataEnabled");
6319 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006320
6321 final long identity = Binder.clearCallingIdentity();
6322 try {
6323 int phoneId = mSubscriptionController.getPhoneId(subId);
6324 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6325 Phone phone = PhoneFactory.getPhone(phoneId);
6326 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006327 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6329 return retVal;
6330 } else {
6331 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6332 return false;
6333 }
6334 } finally {
6335 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006336 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006337 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006338
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006339 /**
6340 * Check if data is enabled for a specific reason
6341 * @param subId Subscription index
6342 * @param reason the reason the data enable change is taking place
6343 * @return {@code true} if the overall data is enabled; {@code false} if not.
6344 */
6345 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006346 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006347 @TelephonyManager.DataEnabledReason int reason) {
6348 try {
6349 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6350 null);
6351 } catch (Exception e) {
6352 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006353 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006354 }
6355
6356
6357 final long identity = Binder.clearCallingIdentity();
6358 try {
6359 int phoneId = mSubscriptionController.getPhoneId(subId);
6360 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006361 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006362 + " reason=" + reason);
6363 }
6364 Phone phone = PhoneFactory.getPhone(phoneId);
6365 if (phone != null) {
6366 boolean retVal;
6367 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6368 retVal = phone.isUserDataEnabled();
6369 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006370 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006371 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006372 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006373 return retVal;
6374 } else {
6375 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006376 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006377 + subId + " retVal=false");
6378 }
6379 return false;
6380 }
6381 } finally {
6382 Binder.restoreCallingIdentity(identity);
6383 }
6384 }
6385
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006386 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006387 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006388 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6389 // Skip the check if it's one of these special uids
6390 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6391 }
6392
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006393 //load access rules from carrier configs, and check those as well: b/139133814
6394 SubscriptionController subController = SubscriptionController.getInstance();
6395 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6396 || subController == null) return privilegeFromSim;
6397
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006398 PackageManager pkgMgr = phone.getContext().getPackageManager();
6399 String[] packages = pkgMgr.getPackagesForUid(uid);
6400
6401 final long identity = Binder.clearCallingIdentity();
6402 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006403 int subId = phone.getSubId();
6404 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6405 // A test override is in place for the privileges for this subId, so don't try to
6406 // read the subscription privileges.
6407 return privilegeFromSim;
6408 }
6409 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006410 SubscriptionManager subManager = (SubscriptionManager)
6411 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6412 for (String pkg : packages) {
6413 if (subManager.canManageSubscription(subInfo, pkg)) {
6414 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6415 }
6416 }
6417 return privilegeFromSim;
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
6421 }
6422
6423 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6424 String pkgName) {
6425 //load access rules from carrier configs, and check those as well: b/139133814
6426 SubscriptionController subController = SubscriptionController.getInstance();
6427 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6428 || subController == null) return privilegeFromSim;
6429
6430 final long identity = Binder.clearCallingIdentity();
6431 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006432 int subId = phone.getSubId();
6433 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6434 // A test override is in place for the privileges for this subId, so don't try to
6435 // read the subscription privileges.
6436 return privilegeFromSim;
6437 }
6438 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006439 SubscriptionManager subManager = (SubscriptionManager)
6440 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6441 return subManager.canManageSubscription(subInfo, pkgName)
6442 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
6446 }
6447
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006448 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006449 public int getCarrierPrivilegeStatus(int subId) {
6450 final Phone phone = getPhone(subId);
6451 if (phone == null) {
6452 loge("getCarrierPrivilegeStatus: Invalid subId");
6453 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6454 }
6455 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006456 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006457 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006458 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6459 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006460
6461 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6462 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006463 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006464 }
Junda Liu29340342014-07-10 15:23:27 -07006465
6466 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006467 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006468 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006469 final Phone phone = getPhone(subId);
6470 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006471 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006472 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6473 }
6474 UiccProfile profile =
6475 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6476 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006477 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006478 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6479 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006480 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006481 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006482 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006483 }
6484
6485 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006486 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6487 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006488 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006489 }
6490
6491 int phoneId = SubscriptionManager.getPhoneId(subId);
6492 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006493 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006494 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006495 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6496 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006497 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6498 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6499 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006500 }
6501
6502 @Override
6503 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006504 if (TextUtils.isEmpty(pkgName))
6505 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006506 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6507 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6508 UiccCard card = UiccController.getInstance().getUiccCard(i);
6509 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006510 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006511 continue;
6512 }
6513
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006514 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6515 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6516 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006517 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6518 break;
6519 }
6520 }
6521
6522 return result;
Junda Liu29340342014-07-10 15:23:27 -07006523 }
Derek Tan89e89d42014-07-08 17:00:10 -07006524
6525 @Override
Junda Liue64de782015-04-16 17:19:16 -07006526 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6527 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6528 loge("phoneId " + phoneId + " is not valid.");
6529 return null;
6530 }
6531 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006532 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006533 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006534 return null ;
6535 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006536 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006537 }
6538
Amith Yamasani6e118872016-02-19 12:53:51 -08006539 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006540 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006541 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006542 List<String> privilegedPackages = new ArrayList<>();
6543 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006544 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6545 // has UICC in that slot.
6546 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006547 if (card.hasCarrierPrivilegeRules()) {
6548 if (packages == null) {
6549 // Only check packages in user 0 for now
6550 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006551 PackageManager.MATCH_DISABLED_COMPONENTS
6552 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006553 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006554 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006555 }
6556 for (int p = packages.size() - 1; p >= 0; p--) {
6557 PackageInfo pkgInfo = packages.get(p);
6558 if (pkgInfo != null && pkgInfo.packageName != null
6559 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006560 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006561 privilegedPackages.add(pkgInfo.packageName);
6562 }
6563 }
6564 }
6565 }
6566 return privilegedPackages;
6567 }
6568
chen xuf7e9fe82019-05-09 19:31:02 -07006569 @Override
6570 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006571 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6572
6573 final long identity = Binder.clearCallingIdentity();
6574
chen xuf7e9fe82019-05-09 19:31:02 -07006575 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006576 try {
6577 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6578 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6579 }
6580 } finally {
6581 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006582 }
6583 return privilegedPackages;
6584 }
6585
Wink Savilleb564aae2014-10-23 10:18:09 -07006586 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006587 final Phone phone = getPhone(subId);
6588 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006589 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006590 return null;
6591 }
6592 String iccId = card.getIccId();
6593 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006594 return null;
6595 }
6596 return iccId;
6597 }
6598
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006599 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006600 public void setCallComposerStatus(int subId, int status) {
6601 enforceModifyPermission();
6602
6603 final long identity = Binder.clearCallingIdentity();
6604 try {
6605 Phone phone = getPhone(subId);
6606 if (phone != null) {
6607 Phone defaultPhone = phone.getImsPhone();
6608 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6609 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6610 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006611 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6612 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006613 }
6614 }
Shuo Qiand8782462020-12-22 19:10:14 -08006615 } catch (ImsException e) {
6616 throw new ServiceSpecificException(e.getCode());
6617 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006618 Binder.restoreCallingIdentity(identity);
6619 }
6620 }
6621
6622 @Override
6623 public int getCallComposerStatus(int subId) {
6624 enforceReadPrivilegedPermission("getCallComposerStatus");
6625
6626 final long identity = Binder.clearCallingIdentity();
6627 try {
6628 Phone phone = getPhone(subId);
6629 if (phone != null) {
6630 Phone defaultPhone = phone.getImsPhone();
6631 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6632 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6633 return imsPhone.getCallComposerStatus();
6634 }
6635 }
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
6638 }
6639 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6640 }
6641
6642 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006643 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6644 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006645 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006646 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006648 final long identity = Binder.clearCallingIdentity();
6649 try {
6650 final String iccId = getIccId(subId);
6651 final Phone phone = getPhone(subId);
6652 if (phone == null) {
6653 return false;
6654 }
6655 final String subscriberId = phone.getSubscriberId();
6656
6657 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006658 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006659 + subscriberId + " to " + number);
6660 }
6661
6662 if (TextUtils.isEmpty(iccId)) {
6663 return false;
6664 }
6665
6666 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6667
6668 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6669 if (alphaTag == null) {
6670 editor.remove(alphaTagPrefKey);
6671 } else {
6672 editor.putString(alphaTagPrefKey, alphaTag);
6673 }
6674
6675 // Record both the line number and IMSI for this ICCID, since we need to
6676 // track all merged IMSIs based on line number
6677 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6678 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6679 if (number == null) {
6680 editor.remove(numberPrefKey);
6681 editor.remove(subscriberPrefKey);
6682 } else {
6683 editor.putString(numberPrefKey, number);
6684 editor.putString(subscriberPrefKey, subscriberId);
6685 }
6686
6687 editor.commit();
6688 return true;
6689 } finally {
6690 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006691 }
Derek Tan7226c842014-07-02 17:42:23 -07006692 }
6693
6694 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006695 public String getLine1NumberForDisplay(int subId, String callingPackage,
6696 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006697 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006699 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006700 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006701 return null;
6702 }
Derek Tan97ebb422014-09-05 16:55:38 -07006703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 final long identity = Binder.clearCallingIdentity();
6705 try {
6706 String iccId = getIccId(subId);
6707 if (iccId != null) {
6708 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6709 if (DBG_MERGE) {
6710 log("getLine1NumberForDisplay returning "
6711 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6712 }
6713 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006714 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6716 return null;
6717 } finally {
6718 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006719 }
Derek Tan7226c842014-07-02 17:42:23 -07006720 }
6721
6722 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006723 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6724 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006726 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006727 return null;
6728 }
Derek Tan97ebb422014-09-05 16:55:38 -07006729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730 final long identity = Binder.clearCallingIdentity();
6731 try {
6732 String iccId = getIccId(subId);
6733 if (iccId != null) {
6734 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6735 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6736 }
6737 return null;
6738 } finally {
6739 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006740 }
Derek Tan7226c842014-07-02 17:42:23 -07006741 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006742
6743 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006744 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6745 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006746 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6747 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006749 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006750 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006751 return null;
6752 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006753
Jordan Liub49b04b2019-05-06 14:45:15 -07006754 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6755 // the process, where TelephonyManager was instantiated.
6756 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006757 final long identity = Binder.clearCallingIdentity();
6758 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006759 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 final TelephonyManager tele = TelephonyManager.from(context);
6761 final SubscriptionManager sub = SubscriptionManager.from(context);
6762
6763 // Figure out what subscribers are currently active
6764 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765
Jordan Liub49b04b2019-05-06 14:45:15 -07006766 // Only consider subs which match the current subId
6767 // This logic can be simplified. See b/131189269 for progress.
6768 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006769 activeSubscriberIds.add(tele.getSubscriberId(subId));
6770 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771
6772 // First pass, find a number override for an active subscriber
6773 String mergeNumber = null;
6774 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6775 for (String key : prefs.keySet()) {
6776 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6777 final String subscriberId = (String) prefs.get(key);
6778 if (activeSubscriberIds.contains(subscriberId)) {
6779 final String iccId = key.substring(
6780 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6781 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6782 mergeNumber = (String) prefs.get(numberKey);
6783 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006784 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 + " for active subscriber " + subscriberId);
6786 }
6787 if (!TextUtils.isEmpty(mergeNumber)) {
6788 break;
6789 }
6790 }
6791 }
6792 }
6793
6794 // Shortcut when no active merged subscribers
6795 if (TextUtils.isEmpty(mergeNumber)) {
6796 return null;
6797 }
6798
6799 // Second pass, find all subscribers under that line override
6800 final ArraySet<String> result = new ArraySet<>();
6801 for (String key : prefs.keySet()) {
6802 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6803 final String number = (String) prefs.get(key);
6804 if (mergeNumber.equals(number)) {
6805 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6806 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6807 final String subscriberId = (String) prefs.get(subscriberKey);
6808 if (!TextUtils.isEmpty(subscriberId)) {
6809 result.add(subscriberId);
6810 }
6811 }
6812 }
6813 }
6814
6815 final String[] resultArray = result.toArray(new String[result.size()]);
6816 Arrays.sort(resultArray);
6817 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006818 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6820 }
6821 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006822 } finally {
6823 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006824 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006825 }
6826
6827 @Override
zoey chen38003472019-12-13 17:16:31 +08006828 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6829 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006830
6831 final long identity = Binder.clearCallingIdentity();
6832 try {
6833 final TelephonyManager telephonyManager = mApp.getSystemService(
6834 TelephonyManager.class);
6835 String subscriberId = telephonyManager.getSubscriberId(subId);
6836 if (subscriberId == null) {
6837 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006838 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006839 + subId);
6840 }
6841 return null;
6842 }
6843
6844 final SubscriptionInfo info = SubscriptionController.getInstance()
6845 .getSubscriptionInfo(subId);
6846 final ParcelUuid groupUuid = info.getGroupUuid();
6847 // If it doesn't belong to any group, return just subscriberId of itself.
6848 if (groupUuid == null) {
6849 return new String[]{subscriberId};
6850 }
6851
6852 // Get all subscriberIds from the group.
6853 final List<String> mergedSubscriberIds = new ArrayList<>();
6854 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006855 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006856 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006857 for (SubscriptionInfo subInfo : groupInfos) {
6858 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6859 if (subscriberId != null) {
6860 mergedSubscriberIds.add(subscriberId);
6861 }
6862 }
6863
6864 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6865 } finally {
6866 Binder.restoreCallingIdentity(identity);
6867
6868 }
6869 }
6870
6871 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006872 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006873 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006874 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006875
6876 final long identity = Binder.clearCallingIdentity();
6877 try {
6878 final Phone phone = getPhone(subId);
6879 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6880 } finally {
6881 Binder.restoreCallingIdentity(identity);
6882 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006883 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006884
6885 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006886 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006887 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6888 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006889 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6890 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891
6892 final long identity = Binder.clearCallingIdentity();
6893 try {
6894 final Phone phone = getPhone(subId);
6895 if (phone == null) {
6896 return false;
6897 }
6898 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6899 cdmaNonRoamingList);
6900 } finally {
6901 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006902 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006903 }
6904
6905 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006906 @Deprecated
6907 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6908 enforceModifyPermission();
6909
6910 int returnValue = 0;
6911 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006912 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006913 if(result.exception == null) {
6914 if (result.result != null) {
6915 byte[] responseData = (byte[])(result.result);
6916 if(responseData.length > oemResp.length) {
6917 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6918 responseData.length + "bytes. Buffer Size is " +
6919 oemResp.length + "bytes.");
6920 }
6921 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6922 returnValue = responseData.length;
6923 }
6924 } else {
6925 CommandException ex = (CommandException) result.exception;
6926 returnValue = ex.getCommandError().ordinal();
6927 if(returnValue > 0) returnValue *= -1;
6928 }
6929 } catch (RuntimeException e) {
6930 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6931 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6932 if(returnValue > 0) returnValue *= -1;
6933 }
6934
6935 return returnValue;
6936 }
6937
6938 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006939 public void setRadioCapability(RadioAccessFamily[] rafs) {
6940 try {
6941 ProxyController.getInstance().setRadioCapability(rafs);
6942 } catch (RuntimeException e) {
6943 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6944 }
6945 }
6946
6947 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006948 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006949 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006950 try {
6951 TelephonyPermissions
6952 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6953 mApp, phone.getSubId(), "getRadioAccessFamily");
6954 } catch (SecurityException e) {
6955 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6956 throw e;
6957 }
chen xub97461a2018-10-26 14:17:57 -07006958 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006959 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006960 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006962 final long identity = Binder.clearCallingIdentity();
6963 try {
chen xub97461a2018-10-26 14:17:57 -07006964 TelephonyPermissions
6965 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6966 mApp, phone.getSubId(), "getRadioAccessFamily");
6967 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
chen xub97461a2018-10-26 14:17:57 -07006971 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006972 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006973
6974 @Override
6975 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006976 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006977 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978
6979 final long identity = Binder.clearCallingIdentity();
6980 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006981 ImsManager.getInstance(defaultPhone.getContext(),
6982 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006983 } finally {
6984 Binder.restoreCallingIdentity(identity);
6985 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006986 }
6987
6988 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006989 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006990 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6992 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006993 return false;
6994 }
Svet Ganovb320e182015-04-16 12:30:10 -07006995
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996 final long identity = Binder.clearCallingIdentity();
6997 try {
6998 // Check the user preference and the system-level IMS setting. Even if the user has
6999 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7000 // In the long run, we may instead need to check if there exists a connection service
7001 // which can support video calling.
7002 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007003 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 return imsManager.isVtEnabledByPlatform()
7005 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7006 && imsManager.isVtEnabledByUser();
7007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007010 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007011
Andrew Leea1239f22015-03-02 17:44:07 -08007012 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007013 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7014 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007016 mApp, subId, callingPackage, callingFeatureId,
7017 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 return false;
7019 }
7020
7021 final long identity = Binder.clearCallingIdentity();
7022 try {
7023 CarrierConfigManager configManager =
7024 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007025 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7027 } finally {
7028 Binder.restoreCallingIdentity(identity);
7029 }
Andrew Leea1239f22015-03-02 17:44:07 -08007030 }
7031
7032 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007033 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007035 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 return false;
7037 }
7038
7039 final long identity = Binder.clearCallingIdentity();
7040 try {
7041 CarrierConfigManager configManager =
7042 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007043 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7045 } finally {
7046 Binder.restoreCallingIdentity(identity);
7047 }
Andrew Leea1239f22015-03-02 17:44:07 -08007048 }
7049
Andrew Lee9431b832015-03-09 18:46:45 -07007050 @Override
7051 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007052 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007053 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007054 }
7055
7056 @Override
7057 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 final long identity = Binder.clearCallingIdentity();
7059 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007060 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 } finally {
7062 Binder.restoreCallingIdentity(identity);
7063 }
Andrew Lee9431b832015-03-09 18:46:45 -07007064 }
7065
Hall Liuf6668912018-10-31 17:05:23 -07007066 /**
7067 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7068 * support for the feature and device firmware support.
7069 *
7070 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7071 */
7072 @Override
7073 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007075 final Phone phone = getPhone(subscriptionId);
7076 if (phone == null) {
7077 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7078 return false;
7079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007081 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7083 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007084 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 return isCarrierSupported && isDeviceSupported;
7086 } finally {
7087 Binder.restoreCallingIdentity(identity);
7088 }
Hall Liu98187582018-01-22 19:15:32 -08007089 }
7090
Hall Liuf6668912018-10-31 17:05:23 -07007091 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007092 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7093 * RTT setting, will return true if the device and carrier both support RTT.
7094 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007095 */
7096 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 final long identity = Binder.clearCallingIdentity();
7098 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007099 boolean isRttSupported = isRttSupported(subscriptionId);
7100 boolean isUserRttSettingOn = Settings.Secure.getInt(
7101 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7102 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7103 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7104 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105 } finally {
7106 Binder.restoreCallingIdentity(identity);
7107 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007108 }
7109
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007110 @Deprecated
7111 @Override
7112 public String getDeviceId(String callingPackage) {
7113 return getDeviceIdWithFeature(callingPackage, null);
7114 }
7115
Sanket Padawe7310cc72015-01-14 09:53:20 -08007116 /**
7117 * Returns the unique device ID of phone, for example, the IMEI for
7118 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7119 *
7120 * <p>Requires Permission:
7121 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7122 */
7123 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007124 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007125 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007126 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007127 return null;
7128 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007129 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007130 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007131 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007132 return null;
7133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134
7135 final long identity = Binder.clearCallingIdentity();
7136 try {
7137 return phone.getDeviceId();
7138 } finally {
7139 Binder.restoreCallingIdentity(identity);
7140 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007141 }
7142
Ping Sunc67b7c22016-03-02 19:16:45 +08007143 /**
7144 * {@hide}
7145 * Returns the IMS Registration Status on a particular subid
7146 *
7147 * @param subId
7148 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007149 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007150 Phone phone = getPhone(subId);
7151 if (phone != null) {
7152 return phone.isImsRegistered();
7153 } else {
7154 return false;
7155 }
7156 }
7157
Santos Cordon7a1885b2015-02-03 11:15:19 -08007158 @Override
7159 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160 final long identity = Binder.clearCallingIdentity();
7161 try {
7162 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007166 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007167
Tyler Gunnf70ed162019-04-03 15:28:53 -07007168 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007169 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007170 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007172 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007173 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7174 }
7175 final long identity = Binder.clearCallingIdentity();
7176 try {
7177 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7178 } finally {
7179 Binder.restoreCallingIdentity(identity);
7180 }
7181 }
7182
7183 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007184 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007185 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7186 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007187 final long identity = Binder.clearCallingIdentity();
7188 try {
7189 Phone phone = getPhone(subscriptionId);
7190 if (phone == null) {
7191 return null;
7192 }
7193 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7194 } finally {
7195 Binder.restoreCallingIdentity(identity);
7196 }
7197 }
7198
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007199 /**
7200 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007201 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007202 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 final long identity = Binder.clearCallingIdentity();
7204 try {
7205 Phone phone = getPhone(subId);
7206 if (phone != null) {
7207 return phone.isWifiCallingEnabled();
7208 } else {
7209 return false;
7210 }
7211 } finally {
7212 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007213 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007214 }
7215
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007216 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007217 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007218 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007219 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007220 final long identity = Binder.clearCallingIdentity();
7221 try {
7222 Phone phone = getPhone(subId);
7223 if (phone != null) {
7224 return phone.isVideoEnabled();
7225 } else {
7226 return false;
7227 }
7228 } finally {
7229 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007230 }
7231 }
7232
7233 /**
7234 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7235 * defined in {@link ImsRegistrationImplBase}.
7236 */
7237 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 Phone phone = getPhone(subId);
7241 if (phone != null) {
7242 return phone.getImsRegistrationTech();
7243 } else {
7244 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7245 }
7246 } finally {
7247 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007248 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007249 }
7250
Stuart Scott8eef64f2015-04-08 15:13:54 -07007251 @Override
7252 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007253 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007254 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7255 return;
7256 }
7257
Svet Ganovcc087f82015-05-12 20:35:54 -07007258 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007259
Svet Ganovcc087f82015-05-12 20:35:54 -07007260 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007261 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7262 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007263 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007264 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007265 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007266 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007267 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7268 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007269 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007270 // There has been issues when Sms raw table somehow stores orphan
7271 // fragments. They lead to garbled message when new fragments come
7272 // in and combined with those stale ones. In case this happens again,
7273 // user can reset all network settings which will clean up this table.
7274 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007275 // Clean up IMS settings as well here.
7276 int slotId = getSlotIndex(subId);
7277 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7278 ImsManager.getInstance(mApp, slotId).factoryReset();
7279 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007280
7281 // Erase modem config if erase modem on network setting is enabled.
7282 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7283 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7284 if (configValue != null && Boolean.parseBoolean(configValue)) {
7285 sendEraseModemConfig(getDefaultPhone());
7286 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007287 } finally {
7288 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007289 }
7290 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007291
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007292 private void cleanUpSmsRawTable(Context context) {
7293 ContentResolver resolver = context.getContentResolver();
7294 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7295 resolver.delete(uri, null, null);
7296 }
7297
Narayan Kamath1c496c22015-04-16 14:40:19 +01007298 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007299 public String getSimLocaleForSubscriber(int subId) {
7300 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7301 final Phone phone = getPhone(subId);
7302 if (phone == null) {
7303 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007304 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306 final long identity = Binder.clearCallingIdentity();
7307 try {
chen xu5d3637b2019-01-21 23:31:38 -08007308 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007309 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007310 if (info == null) {
7311 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7312 return null;
7313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 // Try and fetch the locale from the carrier properties or from the SIM language
7315 // preferences (EF-PL and EF-LI)...
7316 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007318 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7319 if (localeFromDefaultSim != null) {
7320 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7321 if (DBG) log("Using locale from subId: " + subId + " locale: "
7322 + localeFromDefaultSim);
7323 return localeFromDefaultSim.toLanguageTag();
7324 } else {
7325 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 }
7327 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 // The SIM language preferences only store a language (e.g. fr = French), not an
7330 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7331 // the SIM and carrier preferences does not include a country we add the country
7332 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007333 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007334 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007335 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007336 return mccLocale.toLanguageTag();
7337 }
7338
7339 if (DBG) log("No locale found - returning null");
7340 return null;
7341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007344 }
7345
7346 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007347 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007348 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007349 }
7350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 /**
7352 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7353 */
7354 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007355 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007356 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007357 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007358
Chenjie Yu1ba97252018-01-11 18:16:20 -08007359 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007360 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007361
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007362 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007363 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7364 * representing the state of the modem.
7365 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007366 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7367 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007368 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007369 */
7370 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007371 public void requestModemActivityInfo(ResultReceiver result) {
7372 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007373 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374
7375 final long identity = Binder.clearCallingIdentity();
7376 try {
sqian1a1be542020-03-05 11:37:28 -08007377 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378 } finally {
7379 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007380 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007381 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007382
Siddharth Rayb8114062018-06-17 15:02:38 -07007383 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7384 // less than total activity duration.
7385 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7386 if (info == null) {
7387 return false;
7388 }
7389 int activityDurationMs =
7390 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7391 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007392 int[] txTimeMs = info.getTransmitTimeMillis();
7393 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7394 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007395 }
7396 return (info.isValid()
7397 && (info.getSleepTimeMillis() <= activityDurationMs)
7398 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007399 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007400 && (totalTxTimeMs <= activityDurationMs));
7401 }
7402
Jack Yu85bd38a2015-11-09 11:34:32 -08007403 /**
7404 * {@hide}
7405 * Returns the service state information on specified subscription.
7406 */
7407 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007408 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7409 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007411 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007412 return null;
7413 }
7414
Hall Liuf19c44f2018-11-27 14:38:17 -08007415 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7416 LocationAccessPolicy.checkLocationPermission(mApp,
7417 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7418 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007419 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007420 .setCallingPid(Binder.getCallingPid())
7421 .setCallingUid(Binder.getCallingUid())
7422 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007423 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007424 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7425 .build());
7426
7427 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7428 LocationAccessPolicy.checkLocationPermission(mApp,
7429 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7430 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007431 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007432 .setCallingPid(Binder.getCallingPid())
7433 .setCallingUid(Binder.getCallingUid())
7434 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007435 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007436 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7437 .build());
7438 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7439 boolean hasFinePermission =
7440 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7441 boolean hasCoarsePermission =
7442 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 final long identity = Binder.clearCallingIdentity();
7445 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007446 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7447 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7448 Rlog.d(LOG_TAG,
7449 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7450 return null;
7451 }
7452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 final Phone phone = getPhone(subId);
7454 if (phone == null) {
7455 return null;
7456 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007457
Hall Liuf19c44f2018-11-27 14:38:17 -08007458 ServiceState ss = phone.getServiceState();
7459
7460 // Scrub out the location info in ServiceState depending on what level of access
7461 // the caller has.
7462 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007463 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7464 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 } finally {
7466 Binder.restoreCallingIdentity(identity);
7467 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007468 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007469
7470 /**
7471 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7472 *
7473 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7474 * voicemail ringtone.
7475 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7476 * PhoneAccount.
7477 */
7478 @Override
7479 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007480 final long identity = Binder.clearCallingIdentity();
7481 try {
7482 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7483 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007484 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007486
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007491 }
7492
7493 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007494 * Sets the per-account voicemail ringtone.
7495 *
7496 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7497 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7498 *
7499 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7500 * voicemail ringtone.
7501 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7502 * PhoneAccount.
7503 */
7504 @Override
7505 public void setVoicemailRingtoneUri(String callingPackage,
7506 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007507 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007509 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7510 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7512 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7513 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515
7516 final long identity = Binder.clearCallingIdentity();
7517 try {
7518 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7519 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007520 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 }
7522 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7523 } finally {
7524 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007525 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007526 }
7527
7528 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007529 * Returns whether vibration is set for voicemail notification in Phone settings.
7530 *
7531 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7532 * voicemail vibration setting.
7533 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7534 */
7535 @Override
7536 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 final long identity = Binder.clearCallingIdentity();
7538 try {
7539 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7540 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007541 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7545 } finally {
7546 Binder.restoreCallingIdentity(identity);
7547 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007548 }
7549
Youhan Wange64578a2016-05-02 15:32:42 -07007550 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007551 * Sets the per-account voicemail vibration.
7552 *
7553 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7554 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7555 *
7556 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7557 * voicemail vibration setting.
7558 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7559 * specific PhoneAccount.
7560 */
7561 @Override
7562 public void setVoicemailVibrationEnabled(String callingPackage,
7563 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007564 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007565 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007566 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7567 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7569 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7570 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007571 }
7572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 final long identity = Binder.clearCallingIdentity();
7574 try {
7575 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7576 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007577 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007578 }
7579 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7580 } finally {
7581 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007582 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007583 }
7584
7585 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007586 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7587 *
7588 * @throws SecurityException if the caller does not have the required permission
7589 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007590 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007591 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007592 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007593 }
7594
7595 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007596 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7597 * permission.
7598 *
7599 * @throws SecurityException if the caller does not have the required permission
7600 */
7601 private void enforceSendSmsPermission() {
7602 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7603 }
7604
7605 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007606 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007607 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007608 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007609 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007610 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611 final long identity = Binder.clearCallingIdentity();
7612 try {
7613 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007614 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007615 if (componentName == null) {
7616 throw new SecurityException(
7617 "Caller not current active visual voicemail package[null]");
7618 }
7619 String vvmPackage = componentName.getPackageName();
7620 if (!callingPackage.equals(vvmPackage)) {
7621 throw new SecurityException("Caller not current active visual voicemail package["
7622 + vvmPackage + "]");
7623 }
7624 } finally {
7625 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007626 }
7627 }
7628
7629 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007630 * Return the application ID for the app type.
7631 *
7632 * @param subId the subscription ID that this request applies to.
7633 * @param appType the uicc app type.
7634 * @return Application ID for specificied app type, or null if no uicc.
7635 */
7636 @Override
7637 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007638 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007639 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007640
7641 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007642 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 if (phone == null) {
7644 return null;
7645 }
7646 String aid = null;
7647 try {
7648 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7649 .getApplicationByType(appType).getAid();
7650 } catch (Exception e) {
7651 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7652 }
7653 return aid;
7654 } finally {
7655 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007656 }
Youhan Wange64578a2016-05-02 15:32:42 -07007657 }
7658
Youhan Wang4001d252016-05-11 10:29:41 -07007659 /**
7660 * Return the Electronic Serial Number.
7661 *
7662 * @param subId the subscription ID that this request applies to.
7663 * @return ESN or null if error.
7664 */
7665 @Override
7666 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007667 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007668 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669
7670 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007671 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672 if (phone == null) {
7673 return null;
7674 }
7675 String esn = null;
7676 try {
7677 esn = phone.getEsn();
7678 } catch (Exception e) {
7679 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7680 }
7681 return esn;
7682 } finally {
7683 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007684 }
Youhan Wang4001d252016-05-11 10:29:41 -07007685 }
7686
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007687 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007688 * Return the Preferred Roaming List Version.
7689 *
7690 * @param subId the subscription ID that this request applies to.
7691 * @return PRLVersion or null if error.
7692 */
7693 @Override
7694 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007695 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007696 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697
7698 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007699 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700 if (phone == null) {
7701 return null;
7702 }
7703 String cdmaPrlVersion = null;
7704 try {
7705 cdmaPrlVersion = phone.getCdmaPrlVersion();
7706 } catch (Exception e) {
7707 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7708 }
7709 return cdmaPrlVersion;
7710 } finally {
7711 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007712 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007713 }
7714
7715 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007716 * Get snapshot of Telephony histograms
7717 * @return List of Telephony histograms
7718 * @hide
7719 */
7720 @Override
7721 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7723 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724
7725 final long identity = Binder.clearCallingIdentity();
7726 try {
7727 return RIL.getTelephonyRILTimingHistograms();
7728 } finally {
7729 Binder.restoreCallingIdentity(identity);
7730 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007731 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007732
7733 /**
7734 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007735 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7736 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007737 * Require system privileges. In the future we may add this to carrier APIs.
7738 *
Michele Berionne482f8202018-11-27 18:57:59 -08007739 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007740 */
7741 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007742 @TelephonyManager.SetCarrierRestrictionResult
7743 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007744 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007745 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007746
Michele Berionne482f8202018-11-27 18:57:59 -08007747 if (carrierRestrictionRules == null) {
7748 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007749 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 final long identity = Binder.clearCallingIdentity();
7752 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007753 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007754 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007755 } finally {
7756 Binder.restoreCallingIdentity(identity);
7757 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007758 }
7759
7760 /**
7761 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007762 * Get the allowed carrier list and the excluded carrier list, including the priority between
7763 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007764 * Require system privileges. In the future we may add this to carrier APIs.
7765 *
Michele Berionne482f8202018-11-27 18:57:59 -08007766 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007767 */
7768 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007769 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007770 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007771 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007772
7773 final long identity = Binder.clearCallingIdentity();
7774 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007775 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7776 if (response instanceof CarrierRestrictionRules) {
7777 return (CarrierRestrictionRules) response;
7778 }
7779 // Response is an Exception of some kind,
7780 // which is signalled to the user as a NULL retval
7781 return null;
7782 } catch (Exception e) {
7783 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7784 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785 } finally {
7786 Binder.restoreCallingIdentity(identity);
7787 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007788 }
7789
fionaxu59545b42016-05-25 15:53:37 -07007790 /**
fionaxu59545b42016-05-25 15:53:37 -07007791 * Action set from carrier signalling broadcast receivers to enable/disable radio
7792 * @param subId the subscription ID that this action applies to.
7793 * @param enabled control enable or disable radio.
7794 * {@hide}
7795 */
7796 @Override
7797 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7798 enforceModifyPermission();
7799 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800
7801 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007802 if (phone == null) {
7803 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7804 return;
7805 }
7806 try {
7807 phone.carrierActionSetRadioEnabled(enabled);
7808 } catch (Exception e) {
7809 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810 } finally {
7811 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007812 }
7813 }
7814
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007815 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007816 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7817 * network status based on which carrier apps could apply actions accordingly,
7818 * enable/disable default url handler for example.
7819 *
7820 * @param subId the subscription ID that this action applies to.
7821 * @param report control start/stop reporting the default network status.
7822 * {@hide}
7823 */
7824 @Override
7825 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7826 enforceModifyPermission();
7827 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828
7829 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007830 if (phone == null) {
7831 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7832 return;
7833 }
7834 try {
7835 phone.carrierActionReportDefaultNetworkStatus(report);
7836 } catch (Exception e) {
7837 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838 } finally {
7839 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007840 }
7841 }
7842
7843 /**
fionaxud9622282017-07-17 17:51:30 -07007844 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7845 * @param subId the subscription ID that this action applies to.
7846 * {@hide}
7847 */
7848 @Override
7849 public void carrierActionResetAll(int subId) {
7850 enforceModifyPermission();
7851 final Phone phone = getPhone(subId);
7852 if (phone == null) {
7853 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7854 return;
7855 }
7856 try {
7857 phone.carrierActionResetAll();
7858 } catch (Exception e) {
7859 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7860 }
7861 }
7862
7863 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007864 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7865 * bug report is being generated.
7866 */
7867 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007868 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007869 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7870 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007871 writer.println("Permission Denial: can't dump Phone from pid="
7872 + Binder.getCallingPid()
7873 + ", uid=" + Binder.getCallingUid()
7874 + "without permission "
7875 + android.Manifest.permission.DUMP);
7876 return;
7877 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007878 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007879 }
Jack Yueb89b242016-06-22 13:27:47 -07007880
Brad Ebingerdac2f002018-04-03 15:17:52 -07007881 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007882 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7883 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7884 @NonNull String[] args) {
7885 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7886 this, in.getFileDescriptor(), out.getFileDescriptor(),
7887 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007888 }
7889
Jack Yueb89b242016-06-22 13:27:47 -07007890 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007891 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007892 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007893 * @param reason the reason the data enable change is taking place
7894 * @param enabled True if enabling the data, otherwise disabling.
7895 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007896 */
7897 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007898 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007899 boolean enabled) {
7900 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7901 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7902 try {
7903 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007904 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007905 } catch (SecurityException se) {
7906 enforceModifyPermission();
7907 }
7908 } else {
7909 enforceModifyPermission();
7910 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911
7912 final long identity = Binder.clearCallingIdentity();
7913 try {
7914 Phone phone = getPhone(subId);
7915 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007916 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7917 phone.carrierActionSetMeteredApnsEnabled(enabled);
7918 } else {
7919 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7920 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921 }
7922 } finally {
7923 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007924 }
7925 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007926
7927 /**
7928 * Get Client request stats
7929 * @return List of Client Request Stats
7930 * @hide
7931 */
7932 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007933 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7934 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007936 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007937 return null;
7938 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007939 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007941 final long identity = Binder.clearCallingIdentity();
7942 try {
7943 if (phone != null) {
7944 return phone.getClientRequestStats();
7945 }
7946
7947 return null;
7948 } finally {
7949 Binder.restoreCallingIdentity(identity);
7950 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007951 }
7952
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007953 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007954 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007955 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007956 }
Jack Yueb4124c2017-02-16 15:32:43 -08007957
7958 /**
Grace Chen70990072017-03-24 17:21:30 -07007959 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007960 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007961 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007962 * @param state State of SIM (power down, power up, pass through)
7963 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7964 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7965 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007966 *
7967 **/
7968 @Override
Grace Chen70990072017-03-24 17:21:30 -07007969 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007970 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007971 Phone phone = PhoneFactory.getPhone(slotIndex);
7972
vagdeviaf9a5b92018-08-15 16:01:53 -07007973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7974
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007975 final long identity = Binder.clearCallingIdentity();
7976 try {
7977 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007978 phone.setSimPowerState(state, null, workSource);
7979 }
7980 } finally {
7981 Binder.restoreCallingIdentity(identity);
7982 }
7983 }
7984
7985 /**
7986 * Set SIM card power state.
7987 *
7988 * @param slotIndex SIM slot id.
7989 * @param state State of SIM (power down, power up, pass through)
7990 * @param callback callback to trigger after success or failure
7991 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7992 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7993 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7994 *
7995 **/
7996 @Override
7997 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7998 IIntegerConsumer callback) {
7999 enforceModifyPermission();
8000 Phone phone = PhoneFactory.getPhone(slotIndex);
8001
8002 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8003
8004 final long identity = Binder.clearCallingIdentity();
8005 try {
8006 if (phone != null) {
8007 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8008 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009 }
8010 } finally {
8011 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008012 }
8013 }
Shuo Qiandd210312017-04-12 22:11:33 +00008014
Tyler Gunn65d45c22017-06-05 11:22:26 -07008015 private boolean isUssdApiAllowed(int subId) {
8016 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008017 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008018 if (configManager == null) {
8019 return false;
8020 }
8021 PersistableBundle pb = configManager.getConfigForSubId(subId);
8022 if (pb == null) {
8023 return false;
8024 }
8025 return pb.getBoolean(
8026 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8027 }
8028
Shuo Qiandd210312017-04-12 22:11:33 +00008029 /**
8030 * Check if phone is in emergency callback mode
8031 * @return true if phone is in emergency callback mode
8032 * @param subId sub id
8033 */
goneil9c5f4872017-12-05 14:07:56 -08008034 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008035 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008036 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008037 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038
8039 final long identity = Binder.clearCallingIdentity();
8040 try {
8041 if (phone != null) {
8042 return phone.isInEcm();
8043 } else {
8044 return false;
8045 }
8046 } finally {
8047 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008048 }
8049 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008050
8051 /**
8052 * Get the current signal strength information for the given subscription.
8053 * Because this information is not updated when the device is in a low power state
8054 * it should not be relied-upon to be current.
8055 * @param subId Subscription index
8056 * @return the most recent cached signal strength info from the modem
8057 */
8058 @Override
8059 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 final long identity = Binder.clearCallingIdentity();
8061 try {
8062 Phone p = getPhone(subId);
8063 if (p == null) {
8064 return null;
8065 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067 return p.getSignalStrength();
8068 } finally {
8069 Binder.restoreCallingIdentity(identity);
8070 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008071 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008072
Pengquan Meng77b7f132018-08-22 14:49:57 -07008073 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008074 * Get the current modem radio state for the given slot.
8075 * @param slotIndex slot index.
8076 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008077 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008078 * @return the current radio power state from the modem
8079 */
8080 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008081 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008082 Phone phone = PhoneFactory.getPhone(slotIndex);
8083 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8085 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008086 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8087 }
8088
8089 final long identity = Binder.clearCallingIdentity();
8090 try {
8091 return phone.getRadioPowerState();
8092 } finally {
8093 Binder.restoreCallingIdentity(identity);
8094 }
8095 }
8096 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8097 }
8098
8099 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008100 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8101 *
8102 * <p>Requires one of the following permissions:
8103 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8104 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8105 * privileges.
8106 *
8107 * @param subId subscription id
8108 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8109 * {@code false}.
8110 */
8111 @Override
8112 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008113 try {
8114 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8115 null);
8116 } catch (Exception e) {
8117 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8118 mApp, subId, "isDataRoamingEnabled");
8119 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008120
Pengquan Menga1bb6272018-09-06 09:59:22 -07008121 boolean isEnabled = false;
8122 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008123 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008124 Phone phone = getPhone(subId);
8125 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008126 } finally {
8127 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008128 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008129 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008130 }
8131
8132
8133 /**
8134 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8135 *
8136 * <p> Requires permission:
8137 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8138 * privileges.
8139 *
8140 * @param subId subscription id
8141 * @param isEnabled {@code true} means enable, {@code false} means disable.
8142 */
8143 @Override
8144 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8146 mApp, subId, "setDataRoamingEnabled");
8147
Pengquan Menga1bb6272018-09-06 09:59:22 -07008148 final long identity = Binder.clearCallingIdentity();
8149 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008150 Phone phone = getPhone(subId);
8151 if (phone != null) {
8152 phone.setDataRoamingEnabled(isEnabled);
8153 }
8154 } finally {
8155 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008156 }
8157 }
8158
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008159 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008160 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008161 TelephonyPermissions
8162 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008163 mApp, subId, "isManualNetworkSelectionAllowed");
8164
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008165 boolean isAllowed = true;
8166 final long identity = Binder.clearCallingIdentity();
8167 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008168 Phone phone = getPhone(subId);
8169 if (phone != null) {
8170 isAllowed = phone.isCspPlmnEnabled();
8171 }
8172 } finally {
8173 Binder.restoreCallingIdentity(identity);
8174 }
8175 return isAllowed;
8176 }
8177
8178 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008179 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008180 // Verify that tha callingPackage belongs to the calling UID
8181 mApp.getSystemService(AppOpsManager.class)
8182 .checkPackage(Binder.getCallingUid(), callingPackage);
8183
Jordan Liu1e142fc2019-04-22 15:10:43 -07008184 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008185 try {
8186 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008187 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008188 } catch (SecurityException e) {
8189 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8190 // has carrier privileges on an active UICC
8191 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8192 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008193 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008194 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008195 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008196
8197 final long identity = Binder.clearCallingIdentity();
8198 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008199 UiccController uiccController = UiccController.getInstance();
8200 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008201 if (hasReadPermission) {
8202 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008203 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008204
8205 // Remove private info if the caller doesn't have access
8206 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8207 for (UiccCardInfo cardInfo : cardInfos) {
8208 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8209 // is available
8210 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8211 if (card == null || card.getUiccProfile() == null) {
8212 // assume no access if the card or profile is unavailable
8213 filteredInfos.add(cardInfo.getUnprivileged());
8214 continue;
8215 }
8216 UiccProfile profile = card.getUiccProfile();
8217 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8218 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8219 filteredInfos.add(cardInfo);
8220 } else {
8221 filteredInfos.add(cardInfo.getUnprivileged());
8222 }
8223 }
8224 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008225 } finally {
8226 Binder.restoreCallingIdentity(identity);
8227 }
8228 }
8229
8230 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008231 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008232 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008234 final long identity = Binder.clearCallingIdentity();
8235 try {
8236 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8237 if (slots == null) {
8238 Rlog.i(LOG_TAG, "slots is null.");
8239 return null;
8240 }
8241
8242 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8243 for (int i = 0; i < slots.length; i++) {
8244 UiccSlot slot = slots[i];
8245 if (slot == null) {
8246 continue;
8247 }
8248
Jordan Liu7be7e652019-05-06 18:55:02 +00008249 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250 UiccCard card = slot.getUiccCard();
8251 if (card != null) {
8252 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008253 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008254 cardId = slot.getEid();
8255 if (TextUtils.isEmpty(cardId)) {
8256 cardId = slot.getIccId();
8257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 }
8259
Jordan Liu857451f2019-05-09 16:35:35 -07008260 if (cardId != null) {
8261 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8262 // if cardId is an EID, it's all digits so this is fine
8263 cardId = IccUtils.stripTrailingFs(cardId);
8264 }
8265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008266 int cardState = 0;
8267 switch (slot.getCardState()) {
8268 case CARDSTATE_ABSENT:
8269 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8270 break;
8271 case CARDSTATE_PRESENT:
8272 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8273 break;
8274 case CARDSTATE_ERROR:
8275 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8276 break;
8277 case CARDSTATE_RESTRICTED:
8278 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8279 break;
8280 default:
8281 break;
8282
8283 }
8284
8285 infos[i] = new UiccSlotInfo(
8286 slot.isActive(),
8287 slot.isEuicc(),
8288 cardId,
8289 cardState,
8290 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008291 slot.isExtendedApduSupported(),
8292 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293 }
8294 return infos;
8295 } finally {
8296 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008297 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008298 }
8299
8300 @Override
8301 public boolean switchSlots(int[] physicalSlots) {
8302 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303
8304 final long identity = Binder.clearCallingIdentity();
8305 try {
8306 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8307 } finally {
8308 Binder.restoreCallingIdentity(identity);
8309 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008310 }
Jack Yu4c988042018-02-27 15:30:01 -08008311
8312 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008313 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008314 final long identity = Binder.clearCallingIdentity();
8315 try {
8316 return UiccController.getInstance().getCardIdForDefaultEuicc();
8317 } finally {
8318 Binder.restoreCallingIdentity(identity);
8319 }
8320 }
8321
Pengquan Meng85728fb2018-03-12 16:31:21 -07008322 /**
goneil47ffb6e2018-04-06 15:40:58 -07008323 * A test API to reload the UICC profile.
8324 *
8325 * <p>Requires that the calling app has permission
8326 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8327 * @hide
8328 */
8329 @Override
8330 public void refreshUiccProfile(int subId) {
8331 enforceModifyPermission();
8332
8333 final long identity = Binder.clearCallingIdentity();
8334 try {
8335 Phone phone = getPhone(subId);
8336 if (phone == null) {
8337 return;
8338 }
8339 UiccCard uiccCard = phone.getUiccCard();
8340 if (uiccCard == null) {
8341 return;
8342 }
8343 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8344 if (uiccProfile == null) {
8345 return;
8346 }
8347 uiccProfile.refresh();
8348 } finally {
8349 Binder.restoreCallingIdentity(identity);
8350 }
8351 }
8352
8353 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008354 * Returns false if the mobile data is disabled by default, otherwise return true.
8355 */
8356 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008357 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008358 }
8359
8360 /**
8361 * Returns true if the data roaming is enabled by default, i.e the system property
8362 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8363 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8364 */
8365 private boolean getDefaultDataRoamingEnabled(int subId) {
8366 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008367 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008368 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008369 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8370 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8371 return isDataRoamingEnabled;
8372 }
8373
8374 /**
8375 * Returns the default network type for the given {@code subId}, if the default network type is
8376 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8377 */
8378 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008379 List<Integer> list = TelephonyProperties.default_network();
8380 int phoneId = mSubscriptionController.getPhoneId(subId);
8381 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8382 return list.get(phoneId);
8383 }
8384 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008385 }
fionaxua13278b2018-03-21 00:08:13 -07008386
8387 @Override
8388 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008389 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008390 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391
8392 final long identity = Binder.clearCallingIdentity();
8393 try {
8394 final Phone phone = getPhone(subId);
8395 if (phone == null) {
8396 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8397 return;
8398 }
chen xueaba88a2019-03-15 13:15:10 -07008399 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8400 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008401 if (carrierPrivilegeRules == null) {
8402 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8403 } else {
8404 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008406 } finally {
8407 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008408 }
fionaxua13278b2018-03-21 00:08:13 -07008409 }
8410
8411 @Override
8412 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008413 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008414
8415 final long identity = Binder.clearCallingIdentity();
8416 try {
8417 final Phone phone = getPhone(subId);
8418 if (phone == null) {
8419 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8420 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8421 }
8422 return phone.getCarrierIdListVersion();
8423 } finally {
8424 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008425 }
fionaxua13278b2018-03-21 00:08:13 -07008426 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008427
8428 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008429 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8430 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008431 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008432 mApp, subId, callingPackage, callingFeatureId,
8433 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008434 return -1;
8435 }
8436
8437 final long identity = Binder.clearCallingIdentity();
8438 try {
8439 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8440 } finally {
8441 Binder.restoreCallingIdentity(identity);
8442 }
8443 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008444
8445 @Override
8446 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008447 TelephonyPermissions
8448 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008449 mApp, subId, "getCdmaRoamingMode");
8450
8451 final long identity = Binder.clearCallingIdentity();
8452 try {
8453 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8454 } finally {
8455 Binder.restoreCallingIdentity(identity);
8456 }
8457 }
8458
8459 @Override
8460 public boolean setCdmaRoamingMode(int subId, int mode) {
8461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8462 mApp, subId, "setCdmaRoamingMode");
8463
8464 final long identity = Binder.clearCallingIdentity();
8465 try {
8466 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8467 } finally {
8468 Binder.restoreCallingIdentity(identity);
8469 }
8470 }
8471
8472 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008473 public int getCdmaSubscriptionMode(int subId) {
8474 TelephonyPermissions
8475 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8476 mApp, subId, "getCdmaSubscriptionMode");
8477
8478 final long identity = Binder.clearCallingIdentity();
8479 try {
8480 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8481 } finally {
8482 Binder.restoreCallingIdentity(identity);
8483 }
8484 }
8485
8486 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008487 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8489 mApp, subId, "setCdmaSubscriptionMode");
8490
8491 final long identity = Binder.clearCallingIdentity();
8492 try {
8493 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8494 } finally {
8495 Binder.restoreCallingIdentity(identity);
8496 }
8497 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008498
sqianc5eccab2018-10-19 18:46:41 -07008499 @Override
sqian8c685422019-02-22 15:55:18 -08008500 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008501 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008503 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8504 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008505 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8506 }
8507 final long identity = Binder.clearCallingIdentity();
8508 try {
sqian854d44b2018-12-12 16:48:18 -08008509 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8510 for (Phone phone: PhoneFactory.getPhones()) {
8511 if (phone.getEmergencyNumberTracker() != null
8512 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8513 emergencyNumberListInternal.put(
8514 phone.getSubId(),
8515 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8516 }
sqian11b7a0e2018-12-05 18:48:28 -08008517 }
sqian854d44b2018-12-12 16:48:18 -08008518 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008519 } finally {
8520 Binder.restoreCallingIdentity(identity);
8521 }
sqianc5eccab2018-10-19 18:46:41 -07008522 }
8523
8524 @Override
sqian8c685422019-02-22 15:55:18 -08008525 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008526 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008527 if (!exactMatch) {
8528 TelephonyPermissions
8529 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008530 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008531 }
8532 final long identity = Binder.clearCallingIdentity();
8533 try {
sqian854d44b2018-12-12 16:48:18 -08008534 for (Phone phone: PhoneFactory.getPhones()) {
8535 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008536 && phone.getEmergencyNumberTracker()
8537 .isEmergencyNumber(number, exactMatch)) {
8538 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008539 }
sqian11b7a0e2018-12-05 18:48:28 -08008540 }
8541 return false;
8542 } finally {
8543 Binder.restoreCallingIdentity(identity);
8544 }
8545 }
8546
sqianf4ca7ed2019-01-15 18:32:07 -08008547 /**
8548 * Update emergency number list for test mode.
8549 */
8550 @Override
8551 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8552 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8553 "updateEmergencyNumberListTestMode");
8554
8555 final long identity = Binder.clearCallingIdentity();
8556 try {
8557 for (Phone phone: PhoneFactory.getPhones()) {
8558 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8559 if (tracker != null) {
8560 tracker.executeEmergencyNumberTestModeCommand(action, num);
8561 }
8562 }
8563 } finally {
8564 Binder.restoreCallingIdentity(identity);
8565 }
8566 }
8567
8568 /**
8569 * Get the full emergency number list for test mode.
8570 */
8571 @Override
8572 public List<String> getEmergencyNumberListTestMode() {
8573 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8574 "getEmergencyNumberListTestMode");
8575
8576 final long identity = Binder.clearCallingIdentity();
8577 try {
8578 Set<String> emergencyNumbers = new HashSet<>();
8579 for (Phone phone: PhoneFactory.getPhones()) {
8580 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8581 if (tracker != null) {
8582 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8583 emergencyNumbers.add(num.getNumber());
8584 }
8585 }
8586 }
8587 return new ArrayList<>(emergencyNumbers);
8588 } finally {
8589 Binder.restoreCallingIdentity(identity);
8590 }
8591 }
8592
chen xud6b45bd2018-10-30 22:27:10 -07008593 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008594 public int getEmergencyNumberDbVersion(int subId) {
8595 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8596
8597 final long identity = Binder.clearCallingIdentity();
8598 try {
8599 final Phone phone = getPhone(subId);
8600 if (phone == null) {
8601 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8602 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8603 }
8604 return phone.getEmergencyNumberDbVersion();
8605 } finally {
8606 Binder.restoreCallingIdentity(identity);
8607 }
8608 }
8609
8610 @Override
8611 public void notifyOtaEmergencyNumberDbInstalled() {
8612 enforceModifyPermission();
8613
8614 final long identity = Binder.clearCallingIdentity();
8615 try {
8616 for (Phone phone: PhoneFactory.getPhones()) {
8617 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8618 if (tracker != null) {
8619 tracker.updateOtaEmergencyNumberDatabase();
8620 }
8621 }
8622 } finally {
8623 Binder.restoreCallingIdentity(identity);
8624 }
8625 }
8626
8627 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008628 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008629 enforceActiveEmergencySessionPermission();
8630
8631 final long identity = Binder.clearCallingIdentity();
8632 try {
8633 for (Phone phone: PhoneFactory.getPhones()) {
8634 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8635 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008636 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8637 }
8638 }
8639 } finally {
8640 Binder.restoreCallingIdentity(identity);
8641 }
8642 }
8643
8644 @Override
8645 public void resetOtaEmergencyNumberDbFilePath() {
8646 enforceActiveEmergencySessionPermission();
8647
8648 final long identity = Binder.clearCallingIdentity();
8649 try {
8650 for (Phone phone: PhoneFactory.getPhones()) {
8651 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8652 if (tracker != null) {
8653 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008654 }
8655 }
8656 } finally {
8657 Binder.restoreCallingIdentity(identity);
8658 }
8659 }
8660
8661 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008662 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8663 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8664 Phone phone = getPhone(subId);
8665 if (phone == null) {
8666 return null;
8667 }
8668 final long identity = Binder.clearCallingIdentity();
8669 try {
8670 UiccProfile profile = UiccController.getInstance()
8671 .getUiccProfileForPhone(phone.getPhoneId());
8672 if (profile != null) {
8673 return profile.getCertsFromCarrierPrivilegeAccessRules();
8674 }
8675 } finally {
8676 Binder.restoreCallingIdentity(identity);
8677 }
8678 return null;
8679 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008680
8681 /**
8682 * Enable or disable a modem stack.
8683 */
8684 @Override
8685 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8686 enforceModifyPermission();
8687
8688 final long identity = Binder.clearCallingIdentity();
8689 try {
8690 Phone phone = PhoneFactory.getPhone(slotIndex);
8691 if (phone == null) {
8692 return false;
8693 } else {
8694 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8695 }
8696 } finally {
8697 Binder.restoreCallingIdentity(identity);
8698 }
8699 }
Michelecea4cf22018-12-21 15:00:11 -08008700
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008701 /**
8702 * Whether a modem stack is enabled or not.
8703 */
8704 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008705 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8706 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008707 Phone phone = PhoneFactory.getPhone(slotIndex);
8708 if (phone == null) return false;
8709
8710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008711 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8712 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008713 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8714 }
8715
8716 final long identity = Binder.clearCallingIdentity();
8717 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008718 try {
8719 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8720 } catch (NoSuchElementException ex) {
8721 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8722 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008723 } finally {
8724 Binder.restoreCallingIdentity(identity);
8725 }
8726 }
8727
Michelecea4cf22018-12-21 15:00:11 -08008728 @Override
Michele0ea7d782019-03-19 14:58:42 -07008729 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008730 enforceModifyPermission();
8731
8732 final long identity = Binder.clearCallingIdentity();
8733 try {
8734 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008735 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008736 .commit();
8737 } finally {
8738 Binder.restoreCallingIdentity(identity);
8739 }
8740 }
8741
8742 @Override
Michele0ea7d782019-03-19 14:58:42 -07008743 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008744 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008746 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8747 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008748 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008749 }
Michelecea4cf22018-12-21 15:00:11 -08008750
8751 final long identity = Binder.clearCallingIdentity();
8752 try {
Michele0ea7d782019-03-19 14:58:42 -07008753 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008754 } finally {
8755 Binder.restoreCallingIdentity(identity);
8756 }
8757 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008758
Michele0ea7d782019-03-19 14:58:42 -07008759 @TelephonyManager.IsMultiSimSupportedResult
8760 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008761 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8762 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8763 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008764 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8765 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008766 }
8767 // Check if the hardware supports multisim functionality. If usage of multisim is not
8768 // supported by the modem, indicate that it is restricted.
8769 PhoneCapability staticCapability =
8770 mPhoneConfigurationManager.getStaticPhoneCapability();
8771 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008772 loge("isMultiSimSupportedInternal: no static configuration available");
8773 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008774 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008775 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008776 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8777 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008778 }
8779 // Check if support of multiple SIMs is restricted by carrier
8780 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008781 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008782 }
8783
Michele0ea7d782019-03-19 14:58:42 -07008784 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008785 }
8786
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008787 /**
8788 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008789 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8790 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8791 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008792 * @param numOfSims number of active sims we want to switch to
8793 */
8794 @Override
8795 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008796 if (numOfSims == 1) {
8797 enforceModifyPermission();
8798 } else {
8799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8800 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8801 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008802 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008803
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008804 try {
Michele30b57b22019-03-01 12:01:14 -08008805 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008806 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008807 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8808 return;
8809 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008810 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8811 } finally {
8812 Binder.restoreCallingIdentity(identity);
8813 }
8814 }
8815
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008816 @Override
8817 public boolean isApplicationOnUicc(int subId, int appType) {
8818 enforceReadPrivilegedPermission("isApplicationOnUicc");
8819 Phone phone = getPhone(subId);
8820 if (phone == null) {
8821 return false;
8822 }
8823 final long identity = Binder.clearCallingIdentity();
8824 try {
8825 UiccCard uiccCard = phone.getUiccCard();
8826 if (uiccCard == null) {
8827 return false;
8828 }
8829 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8830 if (uiccProfile == null) {
8831 return false;
8832 }
8833 if (TelephonyManager.APPTYPE_SIM <= appType
8834 && appType <= TelephonyManager.APPTYPE_ISIM) {
8835 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8836 }
8837 return false;
8838 } finally {
8839 Binder.restoreCallingIdentity(identity);
8840 }
8841 }
8842
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008843 /**
chen xub4baa772019-04-03 10:23:41 -07008844 * Get whether making changes to modem configurations will trigger reboot.
8845 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008846 */
8847 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008848 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8849 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008851 mApp, subId, callingPackage, callingFeatureId,
8852 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008853 return false;
8854 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008855 final long identity = Binder.clearCallingIdentity();
8856 try {
8857 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8858 } finally {
8859 Binder.restoreCallingIdentity(identity);
8860 }
8861 }
8862
Nathan Harold29f5f052019-02-15 13:41:57 -08008863 private void updateModemStateMetrics() {
8864 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8865 // TODO: check the state for each modem if the api is ready.
8866 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8867 }
8868
Pengquan Meng3889a572019-01-23 11:16:29 -08008869 @Override
8870 public int[] getSlotsMapping() {
8871 enforceReadPrivilegedPermission("getSlotsMapping");
8872
8873 final long identity = Binder.clearCallingIdentity();
8874 try {
8875 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8876 // All logical slots should have a mapping to a physical slot.
8877 int[] logicalSlotsMapping = new int[phoneCount];
8878 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8879 for (int i = 0; i < slotInfos.length; i++) {
8880 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8881 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8882 }
8883 }
8884 return logicalSlotsMapping;
8885 } finally {
8886 Binder.restoreCallingIdentity(identity);
8887 }
8888 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008889
8890 /**
8891 * Get the IRadio HAL Version
8892 */
8893 @Override
8894 public int getRadioHalVersion() {
8895 Phone phone = getDefaultPhone();
8896 if (phone == null) return -1;
8897 HalVersion hv = phone.getHalVersion();
8898 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8899 return hv.major * 100 + hv.minor;
8900 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008901
8902 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008903 * Get the current calling package name.
8904 * @return the current calling package name
8905 */
8906 @Override
8907 public String getCurrentPackageName() {
8908 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8909 }
8910
8911 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008912 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8913 * corresponding network requests on a subId.
8914 *
8915 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008916 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008917 * 2) APN is un-metered for this subscription, or
8918 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008919 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008920 *
8921 * @return whether data is allowed for a apn type.
8922 *
8923 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008924 */
8925 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008926 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008927 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8928 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008929
8930 // Now that all security checks passes, perform the operation as ourselves.
8931 final long identity = Binder.clearCallingIdentity();
8932 try {
8933 Phone phone = getPhone(subId);
8934 if (phone == null) return false;
8935
Jack Yu41407ee2019-05-13 16:54:09 -07008936 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008937 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8938 } finally {
8939 Binder.restoreCallingIdentity(identity);
8940 }
8941 }
8942
8943 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008944 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008945 enforceReadPrivilegedPermission("isApnMetered");
8946
8947 // Now that all security checks passes, perform the operation as ourselves.
8948 final long identity = Binder.clearCallingIdentity();
8949 try {
8950 Phone phone = getPhone(subId);
8951 if (phone == null) return true; // By default return true.
8952
Jack Yu41407ee2019-05-13 16:54:09 -07008953 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008954 } finally {
8955 Binder.restoreCallingIdentity(identity);
8956 }
8957 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008958
8959 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008960 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8961 int subscriptionId, IBooleanConsumer resultCallback) {
8962 enforceModifyPermission();
8963 long token = Binder.clearCallingIdentity();
8964 try {
8965 Phone phone = getPhone(subscriptionId);
8966 if (phone == null) {
8967 try {
8968 if (resultCallback != null) {
8969 resultCallback.accept(false);
8970 }
8971 } catch (RemoteException e) {
8972 // ignore
8973 }
8974 return;
8975 }
8976 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8977 Pair.create(specifiers, (x) -> {
8978 try {
8979 if (resultCallback != null) {
8980 resultCallback.accept(x);
8981 }
8982 } catch (RemoteException e) {
8983 // ignore
8984 }
8985 });
8986 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8987 } finally {
8988 Binder.restoreCallingIdentity(token);
8989 }
8990 }
8991
8992 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008993 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8994 TelephonyPermissions
8995 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8996 mApp, subId, "getSystemSelectionChannels");
8997 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8998 final long identity = Binder.clearCallingIdentity();
8999 try {
9000 List<RadioAccessSpecifier> specifiers =
9001 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9002 null, subId, workSource);
9003 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9004 return specifiers;
9005 } finally {
9006 Binder.restoreCallingIdentity(identity);
9007 }
9008 }
9009
9010 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009011 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009012 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009013 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9014 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9015 if (iccRecords == null) {
9016 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9017 return false;
9018 }
9019 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9020 }
9021
9022 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009023 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9024 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009025 if (callingPackage == null) {
9026 callingPackage = getCurrentPackageName();
9027 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009028 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9029 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009030 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9031 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009032 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9033 }
9034 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9035 Intent intent = new Intent();
9036 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9037 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9038 // Bring up choose default SMS subscription dialog right now
9039 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9040 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9041 mApp.startActivity(intent);
9042 }
chen xud5ca2d52019-05-28 15:20:57 -07009043
9044 @Override
9045 public String getMmsUAProfUrl(int subId) {
9046 //TODO investigate if this API should require proper permission check in R b/133791609
9047 final long identity = Binder.clearCallingIdentity();
9048 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009049 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9050 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9051 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9052 return carrierUAProfUrl;
9053 }
chen xud5ca2d52019-05-28 15:20:57 -07009054 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9055 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9056 } finally {
9057 Binder.restoreCallingIdentity(identity);
9058 }
9059 }
9060
9061 @Override
9062 public String getMmsUserAgent(int subId) {
9063 //TODO investigate if this API should require proper permission check in R b/133791609
9064 final long identity = Binder.clearCallingIdentity();
9065 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009066 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9067 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9068 if (!TextUtils.isEmpty(carrierUserAgent)) {
9069 return carrierUserAgent;
9070 }
chen xud5ca2d52019-05-28 15:20:57 -07009071 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9072 .getString(com.android.internal.R.string.config_mms_user_agent);
9073 } finally {
9074 Binder.restoreCallingIdentity(identity);
9075 }
9076 }
Jack Yub07d4972019-05-28 16:12:25 -07009077
9078 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009079 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9080 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9081
9082 final long identity = Binder.clearCallingIdentity();
9083 try {
9084 Phone phone = getPhone(subscriptionId);
9085 if (phone == null) return false;
9086
9087 switch (policy) {
9088 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9089 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9090 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9091 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9092 default:
9093 throw new IllegalArgumentException(policy + " is not a valid policy");
9094 }
9095 } finally {
9096 Binder.restoreCallingIdentity(identity);
9097 }
9098 }
9099
9100 @Override
9101 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9102 boolean enabled) {
9103 enforceModifyPermission();
9104
9105 final long identity = Binder.clearCallingIdentity();
9106 try {
9107 Phone phone = getPhone(subscriptionId);
9108 if (phone == null) return;
9109
9110 switch (policy) {
9111 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9112 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9113 break;
9114 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9115 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9116 break;
9117 default:
9118 throw new IllegalArgumentException(policy + " is not a valid policy");
9119 }
9120 } finally {
9121 Binder.restoreCallingIdentity(identity);
9122 }
9123 }
9124
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009125 /**
Hall Liub48cf452020-09-25 11:13:49 -07009126 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009127 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9128 * otherwise.
9129 */
9130 @Override
9131 public void setCepEnabled(boolean isCepEnabled) {
9132 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9133
9134 final long identity = Binder.clearCallingIdentity();
9135 try {
9136 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9137 for (Phone phone : PhoneFactory.getPhones()) {
9138 Phone defaultPhone = phone.getImsPhone();
9139 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9140 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9141 ImsPhoneCallTracker imsPhoneCallTracker =
9142 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9143 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9144 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9145 + imsPhone.getMsisdn());
9146 }
9147 }
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
9151 }
allenwtsu46dcc572020-01-08 18:24:03 +08009152
9153 /**
9154 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9155 *
9156 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9157 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9158 * before being read.
9159 */
9160 @Override
9161 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9162 isCompressed) {
9163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9164 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009165 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9166 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9167 }
9168 if (!isImsAvailableOnDevice()) {
9169 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9170 "IMS not available on device.");
9171 }
9172
9173 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009174 try {
Hui Wang068ab862020-10-31 05:12:53 +00009175 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9176 } finally {
9177 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009178 }
9179 }
zoey chenf95ca592019-12-30 16:11:23 +08009180
9181 @Override
9182 public boolean isIccLockEnabled(int subId) {
9183 enforceReadPrivilegedPermission("isIccLockEnabled");
9184
9185 // Now that all security checks passes, perform the operation as ourselves.
9186 final long identity = Binder.clearCallingIdentity();
9187 try {
9188 Phone phone = getPhone(subId);
9189 if (phone != null && phone.getIccCard() != null) {
9190 return phone.getIccCard().getIccLockEnabled();
9191 } else {
9192 return false;
9193 }
9194 } finally {
9195 Binder.restoreCallingIdentity(identity);
9196 }
9197 }
9198
9199 /**
zoey chene02881a2019-12-30 16:11:23 +08009200 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009201 *
zoey chene02881a2019-12-30 16:11:23 +08009202 * @return an integer representing the status of IccLock enabled or disabled in the following
9203 * three cases:
9204 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9205 * successfully.
9206 * - Positive number and zero for remaining password attempts.
9207 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009208 *
9209 */
9210 @Override
9211 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9212 enforceModifyPermission();
9213
9214 Phone phone = getPhone(subId);
9215 if (phone == null) {
9216 return 0;
9217 }
9218 // Now that all security checks passes, perform the operation as ourselves.
9219 final long identity = Binder.clearCallingIdentity();
9220 try {
9221 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9222 new Pair<Boolean, String>(enabled, password), phone, null);
9223 return attemptsRemaining;
9224
9225 } catch (Exception e) {
9226 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9227 } finally {
9228 Binder.restoreCallingIdentity(identity);
9229 }
9230 return 0;
9231 }
9232
9233 /**
9234 * Change the ICC password used in ICC pin lock.
9235 *
zoey chene02881a2019-12-30 16:11:23 +08009236 * @return an integer representing the status of IccLock changed in the following three cases:
9237 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9238 * - Positive number and zero for remaining password attempts.
9239 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009240 *
9241 */
9242 @Override
9243 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9244 enforceModifyPermission();
9245
9246 Phone phone = getPhone(subId);
9247 if (phone == null) {
9248 return 0;
9249 }
9250 // Now that all security checks passes, perform the operation as ourselves.
9251 final long identity = Binder.clearCallingIdentity();
9252 try {
9253 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9254 new Pair<String, String>(oldPassword, newPassword), phone, null);
9255 return attemptsRemaining;
9256
9257 } catch (Exception e) {
9258 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9259 } finally {
9260 Binder.restoreCallingIdentity(identity);
9261 }
9262 return 0;
9263 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009264
Peter Wangdafb9ac2020-01-15 14:13:38 -08009265 /**
9266 * Request for receiving user activity notification
9267 */
9268 @Override
9269 public void requestUserActivityNotification() {
9270 if (!mNotifyUserActivity.get()
9271 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9272 mNotifyUserActivity.set(true);
9273 }
9274 }
9275
9276 /**
9277 * Called when userActivity is signalled in the power manager.
9278 * This is safe to call from any thread, with any window manager locks held or not.
9279 */
9280 @Override
9281 public void userActivity() {
9282 // ***************************************
9283 // * Inherited from PhoneWindowManager *
9284 // ***************************************
9285 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9286 // WITH ITS LOCKS HELD.
9287 //
9288 // This code must be VERY careful about the locks
9289 // it acquires.
9290 // In fact, the current code acquires way too many,
9291 // and probably has lurking deadlocks.
9292
9293 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9294 throw new SecurityException("Only the OS may call notifyUserActivity()");
9295 }
9296
9297 if (mNotifyUserActivity.getAndSet(false)) {
9298 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9299 USER_ACTIVITY_NOTIFICATION_DELAY);
9300 }
9301 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009302
Malcolm Chen884180b2020-04-13 11:59:40 -07009303 @Override
9304 public boolean canConnectTo5GInDsdsMode() {
9305 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9306 }
Jack Yud10cdd42020-09-28 20:28:01 -07009307
9308 @Override
9309 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9310 String callingFeatureId) {
9311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9312 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9313 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9314 }
9315
9316 Phone phone = getPhone(subId);
9317 if (phone == null) {
9318 throw new RuntimeException("phone is not available");
9319 }
9320 // Now that all security checks passes, perform the operation as ourselves.
9321 final long identity = Binder.clearCallingIdentity();
9322 try {
9323 return phone.getEquivalentHomePlmns();
9324 } finally {
9325 Binder.restoreCallingIdentity(identity);
9326 }
9327 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009328
Hui Wang0866fcc2020-10-12 12:14:23 -07009329 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009330 public boolean isRadioInterfaceCapabilitySupported(
9331 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9332 RadioInterfaceCapabilities radioInterfaceCapabilities =
9333 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9334 if (radioInterfaceCapabilities == null) {
9335 throw new RuntimeException("radio interface capabilities are not available");
9336 } else {
9337 return radioInterfaceCapabilities.isSupported(capability);
9338 }
9339 }
9340
9341 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009342 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9343 UaSecurityProtocolIdentifier securityProtocol,
9344 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9345 throws RemoteException {
9346 enforceModifyPermission();
9347 if (DBG) {
9348 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9349 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9350 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9351 }
9352
9353 if (!SubscriptionManager.isValidSubscriptionId(subId)
9354 || appType < TelephonyManager.APPTYPE_UNKNOWN
9355 || appType > TelephonyManager.APPTYPE_ISIM
9356 || nafUrl == null || securityProtocol == null || callback == null) {
9357 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9358 if (callback != null) {
9359 try {
9360 callback.onAuthenticationFailure(
9361 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9362 } catch (RemoteException exception) {
9363 log("Fail to notify onAuthenticationFailure due to " + exception);
9364 }
9365 return;
9366 }
9367 }
9368
9369 final long token = Binder.clearCallingIdentity();
9370 try {
9371 getGbaManager(subId).bootstrapAuthenticationRequest(
9372 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9373 forceBootStrapping, callback));
9374 } finally {
9375 Binder.restoreCallingIdentity(token);
9376 }
9377 }
9378
Jack Nudelman24d51a52020-11-24 12:08:04 -08009379 /**
9380 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9381 * requested radio power state will actually be set. See {@link
9382 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9383 *
9384 * @param subId the subscription ID of the phone requesting to set the radio power state.
9385 * @param enable {@code true} if trying to turn radio on.
9386 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9387 * false}.
9388 */
9389 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9390 Phone phone = getPhone(subId);
9391 if (phone != null) {
9392 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9393 return true;
9394 }
9395 return false;
9396 }
9397
9398 private int handleDataThrottlingRequest(int subId,
9399 DataThrottlingRequest dataThrottlingRequest) {
9400 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9401 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9402 if (!setRadioPowerForThermal(subId, true)) {
9403 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9404 }
9405
9406 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9407
9408 int thermalMitigationResult =
9409 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9410 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9411 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9412 }
9413 return thermalMitigationResult;
9414 }
9415
9416 /**
9417 * Thermal mitigation request to control functionalities at modem.
9418 *
9419 * @param subId the id of the subscription.
9420 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9421 *
9422 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9423 */
9424 @Override
9425 @ThermalMitigationResult
9426 public int sendThermalMitigationRequest(
9427 int subId,
9428 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9429 enforceModifyPermission();
9430
9431 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9432 final long identity = Binder.clearCallingIdentity();
9433
9434 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9435 try {
9436 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9437 switch (thermalMitigationAction) {
9438 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9439 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009440 handleDataThrottlingRequest(subId,
9441 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009442 break;
9443 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9444 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9445 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9446 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9447 }
9448
9449 // Ensure that radio is on. If not able to power on due to phone being
9450 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9451 if (!setRadioPowerForThermal(subId, true)) {
9452 thermalMitigationResult =
9453 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9454 break;
9455 }
9456
9457 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9458 false);
9459 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9460 break;
9461 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9462 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9463 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9464 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9465 }
9466
9467 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9468 if (registry != null) {
9469 TelephonyConnectionService service =
9470 registry.getTelephonyConnectionService();
9471 Phone phone = getPhone(subId);
9472 if (phone == null) {
9473 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009474 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009475 break;
9476 }
9477
9478 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009479 != TelephonyManager.CALL_STATE_IDLE
9480 || phone.isInEmergencySmsMode() || phone.isInEcm()
9481 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009482 String errorMessage = "Phone state is not valid. call state = "
9483 + PhoneConstantConversions.convertCallState(phone.getState())
9484 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9485 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9486 errorMessage += service == null
9487 ? " TelephonyConnectionService is null"
9488 : " isEmergencyCallPending = "
9489 + service.isEmergencyCallPending();
9490 Log.e(LOG_TAG, errorMessage);
9491 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009492 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009493 break;
9494 }
9495 } else {
9496 thermalMitigationResult =
9497 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9498 break;
9499 }
9500
9501 // Turn radio off. If not able to power off due to phone being unavailable,
9502 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9503 if (!setRadioPowerForThermal(subId, false)) {
9504 thermalMitigationResult =
9505 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9506 break;
9507 }
9508 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009509 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009510 break;
9511 default:
9512 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9513 + "not exist. Requested action: " + thermalMitigationAction);
9514 }
9515 } catch (IllegalArgumentException e) {
9516 throw e;
9517 } catch (Exception e) {
9518 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9519 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9520 } finally {
9521 Binder.restoreCallingIdentity(identity);
9522 }
9523
9524 if (DBG) {
9525 log("thermalMitigationRequest returning with thermalMitigationResult: "
9526 + thermalMitigationResult);
9527 }
9528
9529 return thermalMitigationResult;
9530 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009531
9532 /**
9533 * Set the GbaService Package Name that Telephony will bind to.
9534 *
9535 * @param subId The sim that the GbaService is associated with.
9536 * @param packageName The name of the package to be replaced with.
9537 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9538 */
9539 @Override
9540 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9541 enforceModifyPermission();
9542
9543 final long identity = Binder.clearCallingIdentity();
9544 try {
9545 return getGbaManager(subId).overrideServicePackage(packageName);
9546 } finally {
9547 Binder.restoreCallingIdentity(identity);
9548 }
9549 }
9550
9551 /**
9552 * Return the package name of the currently bound GbaService.
9553 *
9554 * @param subId The sim that the GbaService is associated with.
9555 * @return the package name of the GbaService configuration, null if GBA is not supported.
9556 */
9557 @Override
9558 public String getBoundGbaService(int subId) {
9559 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9560
9561 final long identity = Binder.clearCallingIdentity();
9562 try {
9563 return getGbaManager(subId).getServicePackage();
9564 } finally {
9565 Binder.restoreCallingIdentity(identity);
9566 }
9567 }
9568
9569 /**
9570 * Set the release time for telephony to unbind GbaService.
9571 *
9572 * @param subId The sim that the GbaService is associated with.
9573 * @param interval The release time to unbind GbaService by millisecond.
9574 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9575 */
9576 @Override
9577 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9578 enforceModifyPermission();
9579
9580 final long identity = Binder.clearCallingIdentity();
9581 try {
9582 return getGbaManager(subId).overrideReleaseTime(interval);
9583 } finally {
9584 Binder.restoreCallingIdentity(identity);
9585 }
9586 }
9587
9588 /**
9589 * Return the release time for telephony to unbind GbaService.
9590 *
9591 * @param subId The sim that the GbaService is associated with.
9592 * @return The release time to unbind GbaService by millisecond.
9593 */
9594 @Override
9595 public int getGbaReleaseTime(int subId) {
9596 enforceReadPrivilegedPermission("getGbaReleaseTime");
9597
9598 final long identity = Binder.clearCallingIdentity();
9599 try {
9600 return getGbaManager(subId).getReleaseTime();
9601 } finally {
9602 Binder.restoreCallingIdentity(identity);
9603 }
9604 }
9605
9606 private GbaManager getGbaManager(int subId) {
9607 GbaManager instance = GbaManager.getInstance(subId);
9608 if (instance == null) {
9609 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9610 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9611 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9612 }
9613 return instance;
9614 }
Hui Wang068ab862020-10-31 05:12:53 +00009615
9616 /**
9617 * indicate whether the device and the carrier can support
9618 * RCS VoLTE single registration.
9619 */
9620 @Override
9621 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9622 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9623
9624 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9625 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9626 }
9627
9628 final long identity = Binder.clearCallingIdentity();
9629 try {
9630 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9631 if (rpm != null) {
9632 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9633 }
9634 return false;
9635 } finally {
9636 Binder.restoreCallingIdentity(identity);
9637 }
9638 }
9639
9640 /**
9641 * Register RCS provisioning callback.
9642 */
9643 @Override
9644 public void registerRcsProvisioningChangedCallback(int subId,
9645 IRcsConfigCallback callback) {
9646 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9647
9648 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9649 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9650 }
9651 if (!isImsAvailableOnDevice()) {
9652 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9653 "IMS not available on device.");
9654 }
9655
9656 final long identity = Binder.clearCallingIdentity();
9657 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009658 if (!RcsProvisioningMonitor.getInstance()
9659 .registerRcsProvisioningChangedCallback(subId, callback)) {
9660 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9661 "Service not available for the subscription.");
9662 }
Hui Wang068ab862020-10-31 05:12:53 +00009663 } finally {
9664 Binder.restoreCallingIdentity(identity);
9665 }
9666 }
9667
9668 /**
9669 * Unregister RCS provisioning callback.
9670 */
9671 @Override
9672 public void unregisterRcsProvisioningChangedCallback(int subId,
9673 IRcsConfigCallback callback) {
9674 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9675
9676 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9677 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9678 }
9679 if (!isImsAvailableOnDevice()) {
9680 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9681 "IMS not available on device.");
9682 }
9683
9684 final long identity = Binder.clearCallingIdentity();
9685 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009686 RcsProvisioningMonitor.getInstance()
9687 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009688 } finally {
9689 Binder.restoreCallingIdentity(identity);
9690 }
9691 }
9692
9693 /**
9694 * trigger RCS reconfiguration.
9695 */
9696 public void triggerRcsReconfiguration(int subId) {
9697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9698 mApp, subId, "triggerRcsReconfiguration");
9699
9700 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9701 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9702 }
9703 if (!isImsAvailableOnDevice()) {
9704 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9705 "IMS not available on device.");
9706 }
9707
9708 final long identity = Binder.clearCallingIdentity();
9709 try {
9710 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9711 } finally {
9712 Binder.restoreCallingIdentity(identity);
9713 }
9714 }
9715
9716 /**
9717 * Provide the client configuration parameters of the RCS application.
9718 */
9719 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9721 mApp, subId, "setRcsClientConfiguration");
9722
9723 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9724 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9725 }
9726 if (!isImsAvailableOnDevice()) {
9727 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9728 "IMS not available on device.");
9729 }
9730
9731 final long identity = Binder.clearCallingIdentity();
9732
9733 try {
9734 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9735 if (configBinder == null) {
9736 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9737 } else {
9738 configBinder.setRcsClientConfiguration(rcc);
9739 }
9740 } catch (RemoteException e) {
9741 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9742 } finally {
9743 Binder.restoreCallingIdentity(identity);
9744 }
9745 }
9746
9747 /**
9748 * Overrides the config of RCS VoLTE single registration enabled for the device.
9749 */
9750 @Override
9751 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9752 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9753 "setDeviceSingleRegistrationEnabledOverride");
9754 enforceModifyPermission();
9755
9756 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9757 : Boolean.parseBoolean(enabledStr);
9758 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9759 }
9760
9761 /**
9762 * Gets the config of RCS VoLTE single registration enabled for the device.
9763 */
9764 @Override
9765 public boolean getDeviceSingleRegistrationEnabled() {
9766 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9767 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9768 }
9769
9770 /**
9771 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9772 */
9773 @Override
9774 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9775 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9776 "setCarrierSingleRegistrationEnabledOverride");
9777 enforceModifyPermission();
9778
9779 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9780 : Boolean.parseBoolean(enabledStr);
9781 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9782 subId, enabled);
9783 }
9784
9785 /**
9786 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9787 */
9788 @Override
9789 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9790 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9791 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9792 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009793
9794 /**
9795 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9796 * their mobile plan.
9797 */
9798 @Override
9799 public String getMobileProvisioningUrl() {
9800 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9801 final long identity = Binder.clearCallingIdentity();
9802 try {
9803 return getDefaultPhone().getMobileProvisioningUrl();
9804 } finally {
9805 Binder.restoreCallingIdentity(identity);
9806 }
9807 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009808
9809 @Override
9810 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9811 String callingPackage) {
9812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9813 mApp, subId, "setSignalStrengthUpdateRequest");
9814
9815 final int callingUid = Binder.getCallingUid();
9816 // Verify that tha callingPackage belongs to the calling UID
9817 mApp.getSystemService(AppOpsManager.class)
9818 .checkPackage(callingUid, callingPackage);
9819
9820 validateSignalStrengthUpdateRequest(request, callingUid);
9821
9822 final long identity = Binder.clearCallingIdentity();
9823 try {
9824 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9825 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9826
9827 if (result instanceof IllegalStateException) {
9828 throw (IllegalStateException) result;
9829 }
9830 } finally {
9831 Binder.restoreCallingIdentity(identity);
9832 }
9833 }
9834
9835 @Override
9836 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9837 String callingPackage) {
9838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9839 mApp, subId, "clearSignalStrengthUpdateRequest");
9840
9841 final int callingUid = Binder.getCallingUid();
9842 // Verify that tha callingPackage belongs to the calling UID
9843 mApp.getSystemService(AppOpsManager.class)
9844 .checkPackage(callingUid, callingPackage);
9845
9846 final long identity = Binder.clearCallingIdentity();
9847 try {
9848 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9849 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9850
9851 if (result instanceof IllegalStateException) {
9852 throw (IllegalStateException) result;
9853 }
9854 } finally {
9855 Binder.restoreCallingIdentity(identity);
9856 }
9857 }
9858
9859 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9860 int callingUid) {
9861 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9862 // phone/system process do not have further restriction on request
9863 return;
9864 }
9865
9866 // Applications has restrictions on how to use the request:
9867 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9868 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9869 // This is not system caller which has been checked above
9870 throw new IllegalArgumentException(
9871 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9872 }
9873
9874 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9875 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9876 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9877 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9878 || info.isEnabled()) {
9879 throw new IllegalArgumentException(
9880 "Only system can set hide fields in SignalThresholdInfo");
9881 }
9882
9883 // Thresholds length for each RAN need in range. This has been validated in
9884 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9885 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9886 final int[] thresholds = info.getThresholds();
9887 Objects.requireNonNull(thresholds);
9888 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9889 || thresholds.length
9890 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9891 throw new IllegalArgumentException(
9892 "thresholds length is out of range: " + thresholds.length);
9893 }
9894 }
9895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009896}