blob: 278d6486928659779b4ea059acbd9ae57151c0eb [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
Shuo Qian479dd9e2021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger4df7e242021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070032import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070033import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.content.Context;
35import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070036import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070037import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080038import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070039import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.net.Uri;
41import android.os.AsyncResult;
42import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080043import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Bundle;
45import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.Looper;
48import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070049import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080050import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070051import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070052import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080053import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080054import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070055import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070056import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080057import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070059import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070060import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070061import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070062import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080063import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070064import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090065import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080066import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080067import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070068import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070069import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080070import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080071import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070072import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080073import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070074import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080075import android.telephony.CellIdentityCdma;
76import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070078import android.telephony.CellInfoGsm;
79import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070080import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080081import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070082import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070083import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070084import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080085import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070086import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080087import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070088import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080089import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080090import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070091import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080092import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080094import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080095import android.telephony.SignalStrengthUpdateRequest;
96import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080097import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080098import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080099import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700100import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700101import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800102import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800103import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800104import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000105import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700106import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800108import android.telephony.data.ApnSetting;
109import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700110import android.telephony.gba.GbaAuthRequest;
111import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700112import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000114import android.telephony.ims.RcsClientConfiguration;
Brad Ebingerd4c5bde2021-02-12 06:18:28 +0000115import android.telephony.ims.RcsContactUceCapability;
Brad Ebinger774ba362019-10-22 17:36:18 -0700116import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700117import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800118import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700119import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800120import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700121import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000122import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700123import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800125import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800126import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800127import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800129import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700130import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800132import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800133
Andrew Lee312e8172014-10-23 17:01:36 -0700134import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800135import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800136import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWang51ee2b12021-05-27 22:44:54 +0800137import com.android.internal.annotations.VisibleForTesting;
sqian80370722020-01-29 15:02:51 -0800138import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700140import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700141import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800142import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700143import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700144import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800145import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700147import com.android.internal.telephony.GbaManager;
Shuo Qian479dd9e2021-02-22 18:32:21 -0800148import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800149import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800150import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700151import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800153import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800155import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700156import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700157import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700158import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700160import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800161import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700162import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700163import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700164import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700165import com.android.internal.telephony.RIL;
SongFerngWang522637d2021-03-02 22:09:29 +0800166import com.android.internal.telephony.RILConstants;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800167import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700168import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700169import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800171import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800172import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800173import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700174import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800175import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700176import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800177import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700178import com.android.internal.telephony.imsphone.ImsPhone;
179import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800180import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900181import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800183import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800185import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700186import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800187import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800189import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000190import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800191import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700192import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700193import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800194import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700195import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700196import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800197import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700198import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700199import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800200import com.android.services.telephony.TelecomAccountRegistry;
201import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800202import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800203
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700204import java.io.FileDescriptor;
205import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800208import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800209import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800210import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100211import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800212import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700213import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800214import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800215import java.util.Set;
SongFerngWangc63cf522021-03-31 22:08:45 +0800216import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800217import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800218import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219
220/**
221 * Implementation of the ITelephony interface.
222 */
Santos Cordon117fee72014-05-16 17:56:12 -0700223public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 private static final String LOG_TAG = "PhoneInterfaceManager";
225 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
226 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800227 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228
229 // Message codes used with mMainThreadHandler
230 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700231 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
232 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700233 private static final int CMD_OPEN_CHANNEL = 9;
234 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
235 private static final int CMD_CLOSE_CHANNEL = 11;
236 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800237 private static final int CMD_NV_READ_ITEM = 13;
238 private static final int EVENT_NV_READ_ITEM_DONE = 14;
239 private static final int CMD_NV_WRITE_ITEM = 15;
240 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
241 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
242 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700243 private static final int CMD_RESET_MODEM_CONFIG = 19;
244 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800245 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
246 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800247 private static final int CMD_SEND_ENVELOPE = 25;
248 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000249 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
250 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700251 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
252 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
253 private static final int CMD_EXCHANGE_SIM_IO = 31;
254 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800255 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
256 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700257 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
258 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700259 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
260 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700261 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
262 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
263 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
264 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700265 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
266 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
267 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
268 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700269 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800270 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
271 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000272 private static final int CMD_SWITCH_SLOTS = 50;
273 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700274 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
275 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
276 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
277 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
278 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
279 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
280 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
281 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700282 private static final int CMD_GET_ALL_CELL_INFO = 60;
283 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
284 private static final int CMD_GET_CELL_LOCATION = 62;
285 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700286 private static final int CMD_MODEM_REBOOT = 64;
287 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700288 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
289 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800290 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
291 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700292 private static final int CMD_GET_MODEM_STATUS = 70;
293 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700294 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
295 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700296 private static final int CMD_ERASE_MODEM_CONFIG = 74;
297 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800298 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
299 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
300 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
301 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800302 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
303 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800304 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800305 private static final int CMD_GET_CALL_FORWARDING = 83;
306 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
307 private static final int CMD_SET_CALL_FORWARDING = 85;
308 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
309 private static final int CMD_GET_CALL_WAITING = 87;
310 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
311 private static final int CMD_SET_CALL_WAITING = 89;
312 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700313 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
314 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
315 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
316 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700317 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
318 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800319 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
320 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800321 private static final int CMD_SET_DATA_THROTTLING = 99;
322 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800323 private static final int CMD_SET_SIM_POWER = 101;
324 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800325 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
326 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
327 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
328 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800329 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
330 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000331 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800333 // Parameters of select command.
334 private static final int SELECT_COMMAND = 0xA4;
335 private static final int SELECT_P1 = 0x04;
336 private static final int SELECT_P2 = 0;
337 private static final int SELECT_P3 = 0x10;
338
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 /** The singleton instance. */
340 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800341 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
Wink Saville3ab207e2014-11-20 13:07:20 -0800343 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800344 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800345 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700346 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800347 private AppOpsManager mAppOps;
348 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800349 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800350 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700351 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800352 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
Peter Wangdafb9ac2020-01-15 14:13:38 -0800354 /** User Activity */
355 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800356 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
357
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700358 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
359
Derek Tan97ebb422014-09-05 16:55:38 -0700360 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
361 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800362 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800363 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700364
Michelecea4cf22018-12-21 15:00:11 -0800365 // String to store multi SIM allowed
366 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
367
Derek Tan740e1672017-06-27 14:56:27 -0700368 // The AID of ISD-R.
369 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
370
yinxub1bed742017-04-17 11:45:04 -0700371 private NetworkScanRequestTracker mNetworkScanRequestTracker;
372
David Kelly5e06a7f2018-03-12 14:10:59 +0000373 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
374 private static final int MANUFACTURER_CODE_LENGTH = 8;
375
Jack Nudelman24d51a52020-11-24 12:08:04 -0800376 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800377 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800378
Derek Tan89e89d42014-07-08 17:00:10 -0700379 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700380 * Experiment flag to enable erase modem config on reset network, default value is false
381 */
382 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
383 "reset_network_erase_modem_config_enabled";
384
Rambo Wang0f050d82021-02-12 11:43:36 -0800385 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
386
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700387 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700388 * A request object to use for transmitting data to an ICC.
389 */
390 private static final class IccAPDUArgument {
391 public int channel, cla, command, p1, p2, p3;
392 public String data;
393
394 public IccAPDUArgument(int channel, int cla, int command,
395 int p1, int p2, int p3, String data) {
396 this.channel = channel;
397 this.cla = cla;
398 this.command = command;
399 this.p1 = p1;
400 this.p2 = p2;
401 this.p3 = p3;
402 this.data = data;
403 }
404 }
405
406 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700407 * A request object to use for transmitting data to an ICC.
408 */
409 private static final class ManualNetworkSelectionArgument {
410 public OperatorInfo operatorInfo;
411 public boolean persistSelection;
412
413 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
414 this.operatorInfo = operatorInfo;
415 this.persistSelection = persistSelection;
416 }
417 }
418
419 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
421 * request after sending. The main thread will notify the request when it is complete.
422 */
423 private static final class MainThreadRequest {
424 /** The argument to use for the request */
425 public Object argument;
426 /** The result of the request that is run on the main thread */
427 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800428 // The subscriber id that this request applies to. Defaults to
429 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
430 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431
Nathan Harold92bed182018-10-12 18:16:49 -0700432 // In cases where subId is unavailable, the caller needs to specify the phone.
433 public Phone phone;
434
vagdeviaf9a5b92018-08-15 16:01:53 -0700435 public WorkSource workSource;
436
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 public MainThreadRequest(Object argument) {
438 this.argument = argument;
439 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800440
Nathan Harold92bed182018-10-12 18:16:49 -0700441 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
442 this.argument = argument;
443 if (phone != null) {
444 this.phone = phone;
445 }
446 this.workSource = workSource;
447 }
448
vagdeviaf9a5b92018-08-15 16:01:53 -0700449 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800450 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800451 if (subId != null) {
452 this.subId = subId;
453 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700454 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 }
457
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800458 private static final class IncomingThirdPartyCallArgs {
459 public final ComponentName component;
460 public final String callId;
461 public final String callerDisplayName;
462
463 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
464 String callerDisplayName) {
465 this.component = component;
466 this.callId = callId;
467 this.callerDisplayName = callerDisplayName;
468 }
469 }
470
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471 /**
472 * A handler that processes messages on the main thread in the phone process. Since many
473 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
474 * inbound binder threads to the main thread in the phone process. The Binder thread
475 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
476 * on, which will be notified when the operation completes and will contain the result of the
477 * request.
478 *
479 * <p>If a MainThreadRequest object is provided in the msg.obj field,
480 * note that request.result must be set to something non-null for the calling thread to
481 * unblock.
482 */
483 private final class MainThreadHandler extends Handler {
484 @Override
485 public void handleMessage(Message msg) {
486 MainThreadRequest request;
487 Message onCompleted;
488 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800491 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492
493 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 case CMD_HANDLE_USSD_REQUEST: {
495 request = (MainThreadRequest) msg.obj;
496 final Phone phone = getPhoneFromRequest(request);
497 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
498 String ussdRequest = ussdObject.first;
499 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700500
Pengquan Menga1bb6272018-09-06 09:59:22 -0700501 if (!isUssdApiAllowed(request.subId)) {
502 // Carrier does not support use of this API, return failure.
503 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
504 UssdResponse response = new UssdResponse(ussdRequest, null);
505 Bundle returnData = new Bundle();
506 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
507 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700508
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 request.result = true;
510 notifyRequester(request);
511 return;
512 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700513
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 try {
515 request.result = phone != null
516 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
517 } catch (CallStateException cse) {
518 request.result = false;
519 }
520 // Wake up the requesting thread
521 notifyRequester(request);
522 break;
pkanwar32d516d2016-10-14 19:37:38 -0700523 }
524
Yorke Lee716f67e2015-06-17 15:39:16 -0700525 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700527 final Phone phone = getPhoneFromRequest(request);
528 request.result = phone != null ?
529 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
530 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700533 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700537 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800539 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 if (uiccCard == null) {
541 loge("iccTransmitApduLogicalChannel: No UICC");
542 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700544 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
546 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 iccArgument.channel, iccArgument.cla, iccArgument.command,
549 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 break;
553
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 ar = (AsyncResult) msg.obj;
556 request = (MainThreadRequest) ar.userObj;
557 if (ar.exception == null && ar.result != null) {
558 request.result = ar.result;
559 } else {
560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
561 if (ar.result == null) {
562 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800563 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800565 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 } else {
567 loge("iccTransmitApduLogicalChannel: Unknown exception");
568 }
569 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 break;
572
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
574 request = (MainThreadRequest) msg.obj;
575 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800576 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 if (uiccCard == null) {
578 loge("iccTransmitApduBasicChannel: No UICC");
579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 } else {
582 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
583 request);
584 uiccCard.iccTransmitApduBasicChannel(
585 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
586 iccArgument.p3, iccArgument.data, onCompleted);
587 }
588 break;
589
590 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
591 ar = (AsyncResult) msg.obj;
592 request = (MainThreadRequest) ar.userObj;
593 if (ar.exception == null && ar.result != null) {
594 request.result = ar.result;
595 } else {
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
597 if (ar.result == null) {
598 loge("iccTransmitApduBasicChannel: Empty response");
599 } else if (ar.exception instanceof CommandException) {
600 loge("iccTransmitApduBasicChannel: CommandException: " +
601 ar.exception);
602 } else {
603 loge("iccTransmitApduBasicChannel: Unknown exception");
604 }
605 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 break;
608
609 case CMD_EXCHANGE_SIM_IO:
610 request = (MainThreadRequest) msg.obj;
611 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800612 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 if (uiccCard == null) {
614 loge("iccExchangeSimIO: No UICC");
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 } else {
618 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
619 request);
620 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
621 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
622 iccArgument.data, onCompleted);
623 }
624 break;
625
626 case EVENT_EXCHANGE_SIM_IO_DONE:
627 ar = (AsyncResult) msg.obj;
628 request = (MainThreadRequest) ar.userObj;
629 if (ar.exception == null && ar.result != null) {
630 request.result = ar.result;
631 } else {
632 request.result = new IccIoResult(0x6f, 0, (byte[])null);
633 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 break;
636
Derek Tan4d5e5c12014-02-04 11:54:58 -0800637 case CMD_SEND_ENVELOPE:
638 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800639 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 if (uiccCard == null) {
641 loge("sendEnvelopeWithStatus: No UICC");
642 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 } else {
645 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
646 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
647 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800648 break;
649
650 case EVENT_SEND_ENVELOPE_DONE:
651 ar = (AsyncResult) msg.obj;
652 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700653 if (ar.exception == null && ar.result != null) {
654 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800655 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700656 request.result = new IccIoResult(0x6F, 0, (byte[])null);
657 if (ar.result == null) {
658 loge("sendEnvelopeWithStatus: Empty response");
659 } else if (ar.exception instanceof CommandException) {
660 loge("sendEnvelopeWithStatus: CommandException: " +
661 ar.exception);
662 } else {
663 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
664 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800665 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800667 break;
668
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 case CMD_OPEN_CHANNEL:
670 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800671 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800672 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700673 if (uiccCard == null) {
674 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800675 request.result = new IccOpenLogicalChannelResponse(-1,
676 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 } else {
679 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800680 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
681 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 break;
684
685 case EVENT_OPEN_CHANNEL_DONE:
686 ar = (AsyncResult) msg.obj;
687 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700690 int[] result = (int[]) ar.result;
691 int channelId = result[0];
692 byte[] selectResponse = null;
693 if (result.length > 1) {
694 selectResponse = new byte[result.length - 1];
695 for (int i = 1; i < result.length; ++i) {
696 selectResponse[i - 1] = (byte) result[i];
697 }
698 }
699 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700700 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 if (ar.result == null) {
703 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 if (ar.exception != null) {
706 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
707 }
708
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700709 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700710 if (ar.exception instanceof CommandException) {
711 CommandException.Error error =
712 ((CommandException) (ar.exception)).getCommandError();
713 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700714 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700715 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700716 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700717 }
718 }
719 openChannelResp = new IccOpenLogicalChannelResponse(
720 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700722 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700723 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 break;
725
726 case CMD_CLOSE_CHANNEL:
727 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800728 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 if (uiccCard == null) {
730 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900731 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 } else {
734 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
735 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
736 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 break;
738
739 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800740 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
741 break;
742
743 case CMD_NV_READ_ITEM:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800746 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
747 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800748 break;
749
750 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700751 ar = (AsyncResult) msg.obj;
752 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800753 if (ar.exception == null && ar.result != null) {
754 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800756 request.result = "";
757 if (ar.result == null) {
758 loge("nvReadItem: Empty response");
759 } else if (ar.exception instanceof CommandException) {
760 loge("nvReadItem: CommandException: " +
761 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800763 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 }
765 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700766 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 break;
768
Jake Hambye994d462014-02-03 13:10:13 -0800769 case CMD_NV_WRITE_ITEM:
770 request = (MainThreadRequest) msg.obj;
771 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
772 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800773 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700774 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800775 break;
776
777 case EVENT_NV_WRITE_ITEM_DONE:
778 handleNullReturnEvent(msg, "nvWriteItem");
779 break;
780
781 case CMD_NV_WRITE_CDMA_PRL:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
787 case EVENT_NV_WRITE_CDMA_PRL_DONE:
788 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
789 break;
790
chen xu6dac5ab2018-10-26 17:39:23 -0700791 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800792 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700793 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800794 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800795 break;
796
chen xu6dac5ab2018-10-26 17:39:23 -0700797 case EVENT_RESET_MODEM_CONFIG_DONE:
798 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800799 break;
800
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700801 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
804 request);
805 Phone phone = getPhoneFromRequest(request);
806 if (phone != null) {
807 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
808 } else {
809 loge("isNRDualConnectivityEnabled: No phone object");
810 request.result = false;
811 notifyRequester(request);
812 }
813 break;
814 }
815
816 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
817 ar = (AsyncResult) msg.obj;
818 request = (MainThreadRequest) ar.userObj;
819 if (ar.exception == null && ar.result != null) {
820 request.result = ar.result;
821 } else {
822 // request.result must be set to something non-null
823 // for the calling thread to unblock
824 if (request.result != null) {
825 request.result = ar.result;
826 } else {
827 request.result = false;
828 }
829 if (ar.result == null) {
830 loge("isNRDualConnectivityEnabled: Empty response");
831 } else if (ar.exception instanceof CommandException) {
832 loge("isNRDualConnectivityEnabled: CommandException: "
833 + ar.exception);
834 } else {
835 loge("isNRDualConnectivityEnabled: Unknown exception");
836 }
837 }
838 notifyRequester(request);
839 break;
840
841 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
842 request = (MainThreadRequest) msg.obj;
843 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
844 Phone phone = getPhoneFromRequest(request);
845 if (phone != null) {
846 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
847 request.workSource);
848 } else {
849 loge("enableNrDualConnectivity: No phone object");
850 request.result =
851 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
852 notifyRequester(request);
853 }
854 break;
855 }
856
857 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
858 ar = (AsyncResult) msg.obj;
859 request = (MainThreadRequest) ar.userObj;
860 if (ar.exception == null) {
861 request.result =
862 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
863 } else {
864 request.result =
865 TelephonyManager
866 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
867 if (ar.exception instanceof CommandException) {
868 CommandException.Error error =
869 ((CommandException) (ar.exception)).getCommandError();
870 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
871 request.result =
872 TelephonyManager
873 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000874 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
875 request.result =
876 TelephonyManager
877 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700878 }
879 loge("enableNrDualConnectivity" + ": CommandException: "
880 + ar.exception);
881 } else {
882 loge("enableNrDualConnectivity" + ": Unknown exception");
883 }
884 }
885 notifyRequester(request);
886 break;
887 }
888
SongFerngWang9e060372020-12-21 16:41:52 +0800889 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800890 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800891 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
892 request);
893 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800894 break;
895
SongFerngWang9e060372020-12-21 16:41:52 +0800896 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result; // Integer
901 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530902 // request.result must be set to something non-null
903 // for the calling thread to unblock
904 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800906 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800908 loge("getAllowedNetworkTypesBitmask: CommandException: "
909 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800911 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800912 }
913 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700914 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800915 break;
916
SongFerngWang9e060372020-12-21 16:41:52 +0800917 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800919 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
920 request);
921 Pair<Integer, Long> reasonWithNetworkTypes =
922 (Pair<Integer, Long>) request.argument;
923 getPhoneFromRequest(request).setAllowedNetworkTypes(
924 reasonWithNetworkTypes.first,
925 reasonWithNetworkTypes.second,
926 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800927 break;
928
SongFerngWang9e060372020-12-21 16:41:52 +0800929 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
930 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800931 break;
932
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000933 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
934 request = (MainThreadRequest)msg.obj;
935 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800936 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000937 break;
938
939 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
940 ar = (AsyncResult)msg.obj;
941 request = (MainThreadRequest)ar.userObj;
942 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700943 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000944 break;
945
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800946 case CMD_SET_VOICEMAIL_NUMBER:
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
949 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800950 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
951 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800952 break;
953
954 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
955 handleNullReturnEvent(msg, "setVoicemailNumber");
956 break;
957
Stuart Scott54788802015-03-30 13:18:01 -0700958 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
961 request);
962 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
963 break;
964
965 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
966 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
967 break;
968
Shishir Agrawal302c8692015-06-19 13:49:39 -0700969 case CMD_PERFORM_NETWORK_SCAN:
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
972 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
973 break;
974
Hall Liua1acea22020-09-18 19:04:59 -0700975 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800976 request = (MainThreadRequest) msg.obj;
977 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700978 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
979 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
980 request.argument;
981 int callForwardingReason = args.first;
982 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800983 break;
Hall Liua1acea22020-09-18 19:04:59 -0700984 }
985 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700988 TelephonyManager.CallForwardingInfoCallback callback =
989 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
990 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800991 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700992 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800993 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
994 for (CallForwardInfo callForwardInfo : callForwardInfos) {
995 // Service Class is a bit mask per 3gpp 27.007. Search for
996 // any service for voice call.
997 if ((callForwardInfo.serviceClass
998 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700999 callForwardingInfo = new CallForwardingInfo(true,
1000 callForwardInfo.reason,
1001 callForwardInfo.number,
1002 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -08001003 break;
1004 }
1005 }
1006 // Didn't find a call forward info for voice call.
1007 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -07001008 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1009 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001010 }
Hall Liua1acea22020-09-18 19:04:59 -07001011 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001012 } else {
1013 if (ar.result == null) {
1014 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1015 }
1016 if (ar.exception != null) {
1017 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1018 }
Hall Liuae527aa2020-09-29 17:10:18 -07001019 int errorCode = TelephonyManager
1020 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001021 if (ar.exception instanceof CommandException) {
1022 CommandException.Error error =
1023 ((CommandException) (ar.exception)).getCommandError();
1024 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001025 errorCode = TelephonyManager
1026 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001027 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001028 errorCode = TelephonyManager
1029 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001030 }
1031 }
Hall Liua1acea22020-09-18 19:04:59 -07001032 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001033 }
sqian80370722020-01-29 15:02:51 -08001034 break;
Hall Liua1acea22020-09-18 19:04:59 -07001035 }
sqian80370722020-01-29 15:02:51 -08001036
Hall Liua1acea22020-09-18 19:04:59 -07001037 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001038 request = (MainThreadRequest) msg.obj;
1039 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001040 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001041 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001042 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1043 request.argument).first;
1044 request.phone.setCallForwardingOption(
1045 callForwardingInfoToSet.isEnabled()
1046 ? CommandsInterface.CF_ACTION_ENABLE
1047 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001048 callForwardingInfoToSet.getReason(),
1049 callForwardingInfoToSet.getNumber(),
1050 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1051 break;
Hall Liua1acea22020-09-18 19:04:59 -07001052 }
sqian80370722020-01-29 15:02:51 -08001053
Hall Liua1acea22020-09-18 19:04:59 -07001054 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001057 Consumer<Integer> callback =
1058 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1059 request.argument).second;
1060 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001061 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001062 int errorCode = TelephonyManager.CallForwardingInfoCallback
1063 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001064 if (ar.exception instanceof CommandException) {
1065 CommandException.Error error =
1066 ((CommandException) (ar.exception)).getCommandError();
1067 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001068 errorCode = TelephonyManager.CallForwardingInfoCallback
1069 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001070 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001071 errorCode = TelephonyManager.CallForwardingInfoCallback
1072 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001073 }
1074 }
1075 callback.accept(errorCode);
1076 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001077 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001078 }
sqian80370722020-01-29 15:02:51 -08001079 break;
Hall Liua1acea22020-09-18 19:04:59 -07001080 }
sqian80370722020-01-29 15:02:51 -08001081
Hall Liua1acea22020-09-18 19:04:59 -07001082 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001083 request = (MainThreadRequest) msg.obj;
1084 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1085 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1086 break;
Hall Liua1acea22020-09-18 19:04:59 -07001087 }
sqian80370722020-01-29 15:02:51 -08001088
Hall Liua1acea22020-09-18 19:04:59 -07001089 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001090 ar = (AsyncResult) msg.obj;
1091 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001092 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001093 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1094 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001095 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001096 // Service Class is a bit mask per 3gpp 27.007.
1097 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001098 if (callForwardResults.length > 1
1099 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001100 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001101 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001102 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1103 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001104 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001105 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001106 }
1107 } else {
1108 if (ar.result == null) {
1109 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1110 }
1111 if (ar.exception != null) {
1112 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1113 }
1114 if (ar.exception instanceof CommandException) {
1115 CommandException.Error error =
1116 ((CommandException) (ar.exception)).getCommandError();
1117 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1118 callForwardingStatus =
1119 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1120 }
1121 }
1122 }
Hall Liua1acea22020-09-18 19:04:59 -07001123 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001124 break;
Hall Liua1acea22020-09-18 19:04:59 -07001125 }
sqian80370722020-01-29 15:02:51 -08001126
Hall Liua1acea22020-09-18 19:04:59 -07001127 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001128 request = (MainThreadRequest) msg.obj;
1129 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001130 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1131 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001132 break;
Hall Liua1acea22020-09-18 19:04:59 -07001133 }
sqian80370722020-01-29 15:02:51 -08001134
Hall Liua1acea22020-09-18 19:04:59 -07001135 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001136 ar = (AsyncResult) msg.obj;
1137 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001138 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1139 Consumer<Integer> callback =
1140 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1141 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001142 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001143 if (ar.exception instanceof CommandException) {
1144 CommandException.Error error =
1145 ((CommandException) (ar.exception)).getCommandError();
1146 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1147 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1148 } else {
1149 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1150 }
1151 } else {
1152 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1153 }
1154 } else {
1155 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1156 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001157 }
sqian80370722020-01-29 15:02:51 -08001158 break;
Hall Liua1acea22020-09-18 19:04:59 -07001159 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001160 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
1163 CellNetworkScanResult cellScanResult;
1164 if (ar.exception == null && ar.result != null) {
1165 cellScanResult = new CellNetworkScanResult(
1166 CellNetworkScanResult.STATUS_SUCCESS,
1167 (List<OperatorInfo>) ar.result);
1168 } else {
1169 if (ar.result == null) {
1170 loge("getCellNetworkScanResults: Empty response");
1171 }
1172 if (ar.exception != null) {
1173 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1174 }
1175 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1176 if (ar.exception instanceof CommandException) {
1177 CommandException.Error error =
1178 ((CommandException) (ar.exception)).getCommandError();
1179 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1180 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1181 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1182 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1183 }
1184 }
1185 cellScanResult = new CellNetworkScanResult(errorCode, null);
1186 }
1187 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001188 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001189 break;
1190
1191 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1192 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001193 ManualNetworkSelectionArgument selArg =
1194 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001195 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1196 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001197 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1198 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001199 break;
1200
1201 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001202 ar = (AsyncResult) msg.obj;
1203 request = (MainThreadRequest) ar.userObj;
1204 if (ar.exception == null) {
1205 request.result = true;
1206 } else {
1207 request.result = false;
1208 loge("setNetworkSelectionModeManual " + ar.exception);
1209 }
1210 notifyRequester(request);
1211 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001212 break;
1213
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001214 case CMD_GET_MODEM_ACTIVITY_INFO:
1215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001217 if (defaultPhone != null) {
1218 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001219 } else {
1220 ResultReceiver result = (ResultReceiver) request.argument;
1221 Bundle bundle = new Bundle();
1222 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liue8315982020-10-09 19:00:11 -07001223 new ModemActivityInfo(0, 0, 0,
1224 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
sqian1a1be542020-03-05 11:37:28 -08001225 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001226 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001227 break;
1228
Hall Liudf4171d2020-10-14 16:54:44 -07001229 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001230 ar = (AsyncResult) msg.obj;
1231 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001232 ResultReceiver result = (ResultReceiver) request.argument;
1233
Hall Liudf4171d2020-10-14 16:54:44 -07001234 ModemActivityInfo ret = null;
1235 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001236 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001237 // Update the last modem activity info and the result of the request.
1238 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1239 if (isModemActivityInfoValid(info)) {
Hall Liue8315982020-10-09 19:00:11 -07001240 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
sqian1a1be542020-03-05 11:37:28 -08001241 int[] txTimeMs = info.getTransmitTimeMillis();
1242 int[] lastModemTxTimeMs = mLastModemActivityInfo
1243 .getTransmitTimeMillis();
1244 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1245 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1246 }
Hall Liue8315982020-10-09 19:00:11 -07001247 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
sqian1a1be542020-03-05 11:37:28 -08001248 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1249 + mLastModemActivityInfo.getSleepTimeMillis());
1250 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1251 + mLastModemActivityInfo.getIdleTimeMillis());
1252 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1253 mLastModemActivityInfo.setReceiveTimeMillis(
1254 info.getReceiveTimeMillis()
1255 + mLastModemActivityInfo.getReceiveTimeMillis());
1256 }
Hall Liue8315982020-10-09 19:00:11 -07001257 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
sqian1a1be542020-03-05 11:37:28 -08001258 mLastModemActivityInfo.getSleepTimeMillis(),
1259 mLastModemActivityInfo.getIdleTimeMillis(),
1260 mLastModemActivityInfo.getTransmitTimeMillis(),
1261 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001262 } else {
1263 if (ar.result == null) {
1264 loge("queryModemActivityInfo: Empty response");
Hall Liudf4171d2020-10-14 16:54:44 -07001265 error = TelephonyManager.ModemActivityInfoException
1266 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001267 } else if (ar.exception instanceof CommandException) {
1268 loge("queryModemActivityInfo: CommandException: " +
1269 ar.exception);
Hall Liudf4171d2020-10-14 16:54:44 -07001270 error = TelephonyManager.ModemActivityInfoException
1271 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001272 } else {
1273 loge("queryModemActivityInfo: Unknown exception");
Hall Liudf4171d2020-10-14 16:54:44 -07001274 error = TelephonyManager.ModemActivityInfoException
1275 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001276 }
1277 }
sqian1a1be542020-03-05 11:37:28 -08001278 Bundle bundle = new Bundle();
Hall Liudf4171d2020-10-14 16:54:44 -07001279 if (ret != null) {
1280 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1281 } else {
1282 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1283 }
sqian1a1be542020-03-05 11:37:28 -08001284 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001285 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001286 break;
Hall Liudf4171d2020-10-14 16:54:44 -07001287 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001288
Meng Wang1a7c35a2016-05-05 20:56:15 -07001289 case CMD_SET_ALLOWED_CARRIERS:
1290 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001291 CarrierRestrictionRules argument =
1292 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001293 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001294 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001295 break;
1296
1297 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1298 ar = (AsyncResult) msg.obj;
1299 request = (MainThreadRequest) ar.userObj;
1300 if (ar.exception == null && ar.result != null) {
1301 request.result = ar.result;
1302 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001303 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1304 if (ar.exception instanceof CommandException) {
1305 loge("setAllowedCarriers: CommandException: " + ar.exception);
1306 CommandException.Error error =
1307 ((CommandException) (ar.exception)).getCommandError();
1308 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1309 request.result =
1310 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1311 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001312 } else {
1313 loge("setAllowedCarriers: Unknown exception");
1314 }
1315 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001316 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001317 break;
1318
1319 case CMD_GET_ALLOWED_CARRIERS:
1320 request = (MainThreadRequest) msg.obj;
1321 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001322 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001323 break;
1324
1325 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1326 ar = (AsyncResult) msg.obj;
1327 request = (MainThreadRequest) ar.userObj;
1328 if (ar.exception == null && ar.result != null) {
1329 request.result = ar.result;
1330 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001331 request.result = new IllegalStateException(
1332 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001333 if (ar.result == null) {
1334 loge("getAllowedCarriers: Empty response");
1335 } else if (ar.exception instanceof CommandException) {
1336 loge("getAllowedCarriers: CommandException: " +
1337 ar.exception);
1338 } else {
1339 loge("getAllowedCarriers: Unknown exception");
1340 }
1341 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001342 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001343 break;
1344
Nathan Haroldb3014052017-01-25 15:57:32 -08001345 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1346 ar = (AsyncResult) msg.obj;
1347 request = (MainThreadRequest) ar.userObj;
1348 if (ar.exception == null && ar.result != null) {
1349 request.result = ar.result;
1350 } else {
1351 request.result = new IllegalArgumentException(
1352 "Failed to retrieve Forbidden Plmns");
1353 if (ar.result == null) {
1354 loge("getForbiddenPlmns: Empty response");
1355 } else {
1356 loge("getForbiddenPlmns: Unknown exception");
1357 }
1358 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001359 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001360 break;
1361
1362 case CMD_GET_FORBIDDEN_PLMNS:
1363 request = (MainThreadRequest) msg.obj;
1364 uiccCard = getUiccCardFromRequest(request);
1365 if (uiccCard == null) {
1366 loge("getForbiddenPlmns() UiccCard is null");
1367 request.result = new IllegalArgumentException(
1368 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001369 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001370 break;
1371 }
1372 Integer appType = (Integer) request.argument;
1373 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1374 if (uiccApp == null) {
1375 loge("getForbiddenPlmns() no app with specified type -- "
1376 + appType);
1377 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001378 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001379 break;
1380 } else {
1381 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1382 + " specified type -- " + appType);
1383 }
1384 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1385 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1386 onCompleted);
1387 break;
1388
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001389 case CMD_SWITCH_SLOTS:
1390 request = (MainThreadRequest) msg.obj;
1391 int[] physicalSlots = (int[]) request.argument;
1392 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1393 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1394 break;
1395
1396 case EVENT_SWITCH_SLOTS_DONE:
1397 ar = (AsyncResult) msg.obj;
1398 request = (MainThreadRequest) ar.userObj;
1399 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001400 notifyRequester(request);
1401 break;
1402 case CMD_GET_NETWORK_SELECTION_MODE:
1403 request = (MainThreadRequest) msg.obj;
1404 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1405 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1406 break;
1407
1408 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 if (ar.exception != null) {
1412 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1413 } else {
1414 int mode = ((int[]) ar.result)[0];
1415 if (mode == 0) {
1416 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1417 } else {
1418 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1419 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001420 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001421 notifyRequester(request);
1422 break;
1423 case CMD_GET_CDMA_ROAMING_MODE:
1424 request = (MainThreadRequest) msg.obj;
1425 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1426 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1427 break;
1428 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1429 ar = (AsyncResult) msg.obj;
1430 request = (MainThreadRequest) ar.userObj;
1431 if (ar.exception != null) {
1432 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1433 } else {
1434 request.result = ((int[]) ar.result)[0];
1435 }
1436 notifyRequester(request);
1437 break;
1438 case CMD_SET_CDMA_ROAMING_MODE:
1439 request = (MainThreadRequest) msg.obj;
1440 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1441 int mode = (int) request.argument;
1442 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1443 break;
1444 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1445 ar = (AsyncResult) msg.obj;
1446 request = (MainThreadRequest) ar.userObj;
1447 request.result = ar.exception == null;
1448 notifyRequester(request);
1449 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001450 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1451 request = (MainThreadRequest) msg.obj;
1452 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1453 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1454 break;
1455 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1456 ar = (AsyncResult) msg.obj;
1457 request = (MainThreadRequest) ar.userObj;
1458 if (ar.exception != null) {
1459 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1460 } else {
1461 request.result = ((int[]) ar.result)[0];
1462 }
1463 notifyRequester(request);
1464 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001465 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1466 request = (MainThreadRequest) msg.obj;
1467 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1468 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001469 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1470 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001471 break;
1472 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1473 ar = (AsyncResult) msg.obj;
1474 request = (MainThreadRequest) ar.userObj;
1475 request.result = ar.exception == null;
1476 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001477 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001478 case CMD_GET_ALL_CELL_INFO:
1479 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001480 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001481 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001482 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001483 case EVENT_GET_ALL_CELL_INFO_DONE:
1484 ar = (AsyncResult) msg.obj;
1485 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001486 // If a timeout occurs, the response will be null
1487 request.result = (ar.exception == null && ar.result != null)
1488 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 synchronized (request) {
1490 request.notifyAll();
1491 }
1492 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001493 case CMD_REQUEST_CELL_INFO_UPDATE:
1494 request = (MainThreadRequest) msg.obj;
1495 request.phone.requestCellInfoUpdate(request.workSource,
1496 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1497 break;
1498 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
1501 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1502 try {
1503 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001504 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001505 cb.onError(
1506 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1507 ar.exception.getClass().getName(),
1508 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001509 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001510 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001511 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001512 } else {
1513 // use the result as returned
1514 cb.onCellInfo((List<CellInfo>) ar.result);
1515 }
1516 } catch (RemoteException re) {
1517 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1518 }
1519 break;
Sarah Chincc055732020-11-18 13:39:35 -08001520 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001521 request = (MainThreadRequest) msg.obj;
1522 WorkSource ws = (WorkSource) request.argument;
1523 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001524 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001525 break;
Sarah Chincc055732020-11-18 13:39:35 -08001526 }
1527 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 if (ar.exception == null) {
1531 request.result = ar.result;
1532 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001533 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001534 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001535 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001536 }
1537
1538 synchronized (request) {
1539 request.notifyAll();
1540 }
1541 break;
Sarah Chincc055732020-11-18 13:39:35 -08001542 }
chen xu6dac5ab2018-10-26 17:39:23 -07001543 case CMD_MODEM_REBOOT:
1544 request = (MainThreadRequest) msg.obj;
1545 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001546 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001547 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001548 case EVENT_CMD_MODEM_REBOOT_DONE:
1549 handleNullReturnEvent(msg, "rebootModem");
1550 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001551 case CMD_REQUEST_ENABLE_MODEM:
1552 request = (MainThreadRequest) msg.obj;
1553 boolean enable = (boolean) request.argument;
1554 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001555 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001556 PhoneConfigurationManager.getInstance()
1557 .enablePhone(request.phone, enable, onCompleted);
1558 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001559 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001560 ar = (AsyncResult) msg.obj;
1561 request = (MainThreadRequest) ar.userObj;
1562 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001563 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001564 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001565 if ((boolean) request.result) {
1566 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1567 updateModemStateMetrics();
1568 } else {
1569 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1570 + ar.exception);
1571 }
1572 notifyRequester(request);
1573 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001574 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001575 case CMD_GET_MODEM_STATUS:
1576 request = (MainThreadRequest) msg.obj;
1577 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1578 PhoneConfigurationManager.getInstance()
1579 .getPhoneStatusFromModem(request.phone, onCompleted);
1580 break;
1581 case EVENT_GET_MODEM_STATUS_DONE:
1582 ar = (AsyncResult) msg.obj;
1583 request = (MainThreadRequest) ar.userObj;
1584 int id = request.phone.getPhoneId();
1585 if (ar.exception == null && ar.result != null) {
1586 request.result = ar.result;
1587 //update the cache as modem status has changed
1588 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1589 (boolean) request.result);
1590 } else {
1591 // Return true if modem status cannot be retrieved. For most cases,
1592 // modem status is on. And for older version modems, GET_MODEM_STATUS
1593 // and disable modem are not supported. Modem is always on.
1594 // TODO: this should be fixed in R to support a third
1595 // status UNKNOWN b/131631629
1596 request.result = true;
1597 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1598 + ar.exception);
1599 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001600 notifyRequester(request);
1601 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001602 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1603 request = (MainThreadRequest) msg.obj;
1604 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1605 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1606 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1607 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1608 break;
1609 }
1610 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1614 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1615 args.second.accept(ar.exception == null);
1616 notifyRequester(request);
1617 break;
1618 }
Sarah Chincc055732020-11-18 13:39:35 -08001619 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1620 request = (MainThreadRequest) msg.obj;
1621 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1622 Phone phone = getPhoneFromRequest(request);
1623 if (phone != null) {
1624 phone.getSystemSelectionChannels(onCompleted);
1625 } else {
1626 loge("getSystemSelectionChannels: No phone object");
1627 request.result = new ArrayList<RadioAccessSpecifier>();
1628 notifyRequester(request);
1629 }
1630 break;
1631 }
1632 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1633 ar = (AsyncResult) msg.obj;
1634 request = (MainThreadRequest) ar.userObj;
1635 if (ar.exception == null && ar.result != null) {
1636 request.result = ar.result;
1637 } else {
Sarah Chin58691872021-03-13 03:17:40 -08001638 request.result = new IllegalStateException(
1639 "Failed to retrieve system selecton channels");
Sarah Chincc055732020-11-18 13:39:35 -08001640 if (ar.result == null) {
1641 loge("getSystemSelectionChannels: Empty response");
1642 } else {
1643 loge("getSystemSelectionChannels: Unknown exception");
1644 }
1645 }
1646 notifyRequester(request);
1647 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001648 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1649 ar = (AsyncResult) msg.obj;
1650 request = (MainThreadRequest) ar.userObj;
1651 if (ar.exception == null && ar.result != null) {
1652 request.result = ar.result;
1653 } else {
1654 request.result = -1;
1655 loge("Failed to set Forbidden Plmns");
1656 if (ar.result == null) {
1657 loge("setForbidenPlmns: Empty response");
1658 } else if (ar.exception != null) {
1659 loge("setForbiddenPlmns: Exception: " + ar.exception);
1660 request.result = -1;
1661 } else {
1662 loge("setForbiddenPlmns: Unknown exception");
1663 }
1664 }
1665 notifyRequester(request);
1666 break;
1667 case CMD_SET_FORBIDDEN_PLMNS:
1668 request = (MainThreadRequest) msg.obj;
1669 uiccCard = getUiccCardFromRequest(request);
1670 if (uiccCard == null) {
1671 loge("setForbiddenPlmns: UiccCard is null");
1672 request.result = -1;
1673 notifyRequester(request);
1674 break;
1675 }
1676 Pair<Integer, List<String>> setFplmnsArgs =
1677 (Pair<Integer, List<String>>) request.argument;
1678 appType = setFplmnsArgs.first;
1679 List<String> fplmns = setFplmnsArgs.second;
1680 uiccApp = uiccCard.getApplicationByType(appType);
1681 if (uiccApp == null) {
1682 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1683 request.result = -1;
1684 loge("Failed to get UICC App");
1685 notifyRequester(request);
1686 } else {
1687 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1688 ((SIMRecords) uiccApp.getIccRecords())
1689 .setForbiddenPlmns(onCompleted, fplmns);
1690 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001691 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001692 case CMD_ERASE_MODEM_CONFIG:
1693 request = (MainThreadRequest) msg.obj;
1694 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1695 defaultPhone.eraseModemConfig(onCompleted);
1696 break;
1697 case EVENT_ERASE_MODEM_CONFIG_DONE:
1698 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001699 break;
zoey chenf95ca592019-12-30 16:11:23 +08001700
1701 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1702 request = (MainThreadRequest) msg.obj;
1703 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1704 Pair<String, String> changed = (Pair<String, String>) request.argument;
1705 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1706 changed.first, changed.second, onCompleted);
1707 break;
1708 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1709 ar = (AsyncResult) msg.obj;
1710 request = (MainThreadRequest) ar.userObj;
1711 if (ar.exception == null) {
1712 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001713 // If the operation is successful, update the PIN storage
1714 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1715 int phoneId = getPhoneFromRequest(request).getPhoneId();
1716 UiccController.getInstance().getPinStorage()
1717 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001718 } else {
1719 request.result = msg.arg1;
1720 }
1721 notifyRequester(request);
1722 break;
1723
Michele Berionned9fbae52020-11-13 02:36:59 +00001724 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001725 request = (MainThreadRequest) msg.obj;
1726 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1727 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1728 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1729 enabled.first, enabled.second, onCompleted);
1730 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001731 }
zoey chenf95ca592019-12-30 16:11:23 +08001732 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 if (ar.exception == null) {
1736 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001737 // If the operation is successful, update the PIN storage
1738 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1739 int phoneId = getPhoneFromRequest(request).getPhoneId();
1740 if (enabled.first) {
1741 UiccController.getInstance().getPinStorage()
1742 .storePin(enabled.second, phoneId);
1743 } else {
1744 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1745 }
zoey chenf95ca592019-12-30 16:11:23 +08001746 } else {
1747 request.result = msg.arg1;
1748 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001749
1750
zoey chenf95ca592019-12-30 16:11:23 +08001751 notifyRequester(request);
1752 break;
1753
Peter Wangdafb9ac2020-01-15 14:13:38 -08001754 case MSG_NOTIFY_USER_ACTIVITY:
1755 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001756 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001757 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1758 getDefaultPhone().getContext().sendBroadcastAsUser(
1759 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1760 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001761
1762 case CMD_SET_DATA_THROTTLING: {
1763 request = (MainThreadRequest) msg.obj;
1764 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1765 DataThrottlingRequest dataThrottlingRequest =
1766 (DataThrottlingRequest) request.argument;
1767 Phone phone = getPhoneFromRequest(request);
1768 if (phone != null) {
1769 phone.setDataThrottling(onCompleted,
1770 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1771 dataThrottlingRequest.getCompletionDurationMillis());
1772 } else {
1773 loge("setDataThrottling: No phone object");
1774 request.result =
1775 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1776 notifyRequester(request);
1777 }
1778
1779 break;
1780 }
1781 case EVENT_SET_DATA_THROTTLING_DONE:
1782 ar = (AsyncResult) msg.obj;
1783 request = (MainThreadRequest) ar.userObj;
1784
1785 if (ar.exception == null) {
1786 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1787 } else if (ar.exception instanceof CommandException) {
1788 loge("setDataThrottling: CommandException: " + ar.exception);
1789 CommandException.Error error =
1790 ((CommandException) (ar.exception)).getCommandError();
1791
1792 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1793 request.result = TelephonyManager
1794 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1795 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1796 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001797 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1798 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001799 } else {
1800 request.result =
1801 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1802 }
1803 } else {
1804 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1805 }
1806 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1807 notifyRequester(request);
1808 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001809
1810 case CMD_SET_SIM_POWER: {
1811 request = (MainThreadRequest) msg.obj;
1812 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1813 request = (MainThreadRequest) msg.obj;
1814 int stateToSet =
1815 ((Pair<Integer, IIntegerConsumer>)
1816 request.argument).first;
1817 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1818 break;
1819 }
1820 case EVENT_SET_SIM_POWER_DONE: {
1821 ar = (AsyncResult) msg.obj;
1822 request = (MainThreadRequest) ar.userObj;
1823 IIntegerConsumer callback =
1824 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1825 if (ar.exception != null) {
1826 loge("setSimPower exception: " + ar.exception);
1827 int errorCode = TelephonyManager.CallForwardingInfoCallback
1828 .RESULT_ERROR_UNKNOWN;
1829 if (ar.exception instanceof CommandException) {
1830 CommandException.Error error =
1831 ((CommandException) (ar.exception)).getCommandError();
1832 if (error == CommandException.Error.SIM_ERR) {
1833 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1834 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1835 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1836 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1837 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1838 } else {
1839 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1840 }
1841 }
1842 try {
1843 callback.accept(errorCode);
1844 } catch (RemoteException e) {
1845 // Ignore if the remote process is no longer available to call back.
1846 Log.w(LOG_TAG, "setSimPower: callback not available.");
1847 }
1848 } else {
1849 try {
1850 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1851 } catch (RemoteException e) {
1852 // Ignore if the remote process is no longer available to call back.
1853 Log.w(LOG_TAG, "setSimPower: callback not available.");
1854 }
1855 }
1856 break;
1857 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001858 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1859 request = (MainThreadRequest) msg.obj;
1860
1861 final Phone phone = getPhoneFromRequest(request);
1862 if (phone == null || phone.getServiceStateTracker() == null) {
1863 request.result = new IllegalStateException("Phone or SST is null");
1864 notifyRequester(request);
1865 break;
1866 }
1867
1868 Pair<Integer, SignalStrengthUpdateRequest> pair =
1869 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1870 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1871 request);
1872 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1873 request.subId, pair.first /*callingUid*/,
1874 pair.second /*request*/, onCompleted);
1875 break;
1876 }
1877 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1878 ar = (AsyncResult) msg.obj;
1879 request = (MainThreadRequest) ar.userObj;
1880 // request.result will be the exception of ar if present, true otherwise.
1881 // Be cautious not to leave result null which will wait() forever
1882 request.result = ar.exception != null ? ar.exception : true;
1883 notifyRequester(request);
1884 break;
1885 }
1886 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1887 request = (MainThreadRequest) msg.obj;
1888
1889 Phone phone = getPhoneFromRequest(request);
1890 if (phone == null || phone.getServiceStateTracker() == null) {
1891 request.result = new IllegalStateException("Phone or SST is null");
1892 notifyRequester(request);
1893 break;
1894 }
1895
1896 Pair<Integer, SignalStrengthUpdateRequest> pair =
1897 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1898 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1899 request);
1900 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1901 request.subId, pair.first /*callingUid*/,
1902 pair.second /*request*/, onCompleted);
1903 break;
1904 }
1905 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1906 ar = (AsyncResult) msg.obj;
1907 request = (MainThreadRequest) ar.userObj;
1908 request.result = ar.exception != null ? ar.exception : true;
1909 notifyRequester(request);
1910 break;
1911 }
Jordan Liud5366d92020-11-24 14:50:34 -08001912
Michele Berionned9fbae52020-11-13 02:36:59 +00001913 case CMD_PREPARE_UNATTENDED_REBOOT:
1914 request = (MainThreadRequest) msg.obj;
1915 request.result =
1916 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1917 notifyRequester(request);
1918 break;
1919
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 default:
1921 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1922 break;
1923 }
1924 }
Jake Hambye994d462014-02-03 13:10:13 -08001925
Pengquan Menga1bb6272018-09-06 09:59:22 -07001926 private void notifyRequester(MainThreadRequest request) {
1927 synchronized (request) {
1928 request.notifyAll();
1929 }
1930 }
1931
Jake Hambye994d462014-02-03 13:10:13 -08001932 private void handleNullReturnEvent(Message msg, String command) {
1933 AsyncResult ar = (AsyncResult) msg.obj;
1934 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1935 if (ar.exception == null) {
1936 request.result = true;
1937 } else {
1938 request.result = false;
1939 if (ar.exception instanceof CommandException) {
1940 loge(command + ": CommandException: " + ar.exception);
1941 } else {
1942 loge(command + ": Unknown exception");
1943 }
1944 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001945 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948
1949 /**
1950 * Posts the specified command to be executed on the main thread,
1951 * waits for the request to complete, and returns the result.
1952 * @see #sendRequestAsync
1953 */
1954 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001955 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1956 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001957 }
1958
1959 /**
1960 * Posts the specified command to be executed on the main thread,
1961 * waits for the request to complete, and returns the result.
1962 * @see #sendRequestAsync
1963 */
1964 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1965 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001966 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001967 }
1968
1969 /**
1970 * Posts the specified command to be executed on the main thread,
1971 * waits for the request to complete, and returns the result.
1972 * @see #sendRequestAsync
1973 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001974 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001975 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1976 }
1977
1978 /**
1979 * Posts the specified command to be executed on the main thread,
1980 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1981 * if not timeout or null otherwise.
1982 * @see #sendRequestAsync
1983 */
1984 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1985 long timeoutInMs) {
1986 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001987 }
1988
1989 /**
1990 * Posts the specified command to be executed on the main thread,
1991 * waits for the request to complete, and returns the result.
1992 * @see #sendRequestAsync
1993 */
Nathan Harold92bed182018-10-12 18:16:49 -07001994 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001995 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001996 }
1997
1998 /**
1999 * Posts the specified command to be executed on the main thread,
2000 * waits for the request to complete, and returns the result.
2001 * @see #sendRequestAsync
2002 */
2003 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002004 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2005 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002006 }
2007
2008 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002009 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2010 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2011 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002012 * @see #sendRequestAsync
2013 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002014 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2015 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2017 throw new RuntimeException("This method will deadlock if called from the main thread.");
2018 }
2019
Nathan Harold92bed182018-10-12 18:16:49 -07002020 MainThreadRequest request = null;
2021 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2022 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2023 } else if (phone != null) {
2024 request = new MainThreadRequest(argument, phone, workSource);
2025 } else {
2026 request = new MainThreadRequest(argument, subId, workSource);
2027 }
2028
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 Message msg = mMainThreadHandler.obtainMessage(command, request);
2030 msg.sendToTarget();
2031
Rambo Wang0f050d82021-02-12 11:43:36 -08002032
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002034 if (timeoutInMs >= 0) {
2035 // Wait for at least timeoutInMs before returning null request result
2036 long now = SystemClock.elapsedRealtime();
2037 long deadline = now + timeoutInMs;
2038 while (request == null && now < deadline) {
2039 try {
2040 request.wait(deadline - now);
2041 } catch (InterruptedException e) {
2042 // Do nothing, go back and check if request is completed or timeout
2043 } finally {
2044 now = SystemClock.elapsedRealtime();
2045 }
2046 }
2047 } else {
2048 // Wait for the request to complete
2049 while (request.result == null) {
2050 try {
2051 request.wait();
2052 } catch (InterruptedException e) {
2053 // Do nothing, go back and wait until the request is complete
2054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 }
2056 }
2057 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002058 if (request.result == null) {
2059 Log.wtf(LOG_TAG,
2060 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062 return request.result;
2063 }
2064
2065 /**
2066 * Asynchronous ("fire and forget") version of sendRequest():
2067 * Posts the specified command to be executed on the main thread, and
2068 * returns immediately.
2069 * @see #sendRequest
2070 */
2071 private void sendRequestAsync(int command) {
2072 mMainThreadHandler.sendEmptyMessage(command);
2073 }
2074
2075 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002076 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002077 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002078 */
2079 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002080 sendRequestAsync(command, argument, null, null);
2081 }
2082
2083 /**
2084 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2085 * @see {@link #sendRequest(int,Object)}
2086 */
2087 private void sendRequestAsync(
2088 int command, Object argument, Phone phone, WorkSource workSource) {
2089 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002090 Message msg = mMainThreadHandler.obtainMessage(command, request);
2091 msg.sendToTarget();
2092 }
2093
2094 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 * Initialize the singleton PhoneInterfaceManager instance.
2096 * This is only done once, at startup, from PhoneApp.onCreate().
2097 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002098 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 synchronized (PhoneInterfaceManager.class) {
2100 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002101 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 } else {
2103 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2104 }
2105 return sInstance;
2106 }
2107 }
2108
2109 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002110 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerc9c432e2021-05-17 20:54:49 +00002113 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002114 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2116 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002117 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002118 mTelephonySharedPreferences =
2119 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002120 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002121 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002122 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002123 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002124
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125 publish();
2126 }
2127
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002128 private Phone getDefaultPhone() {
2129 Phone thePhone = getPhone(getDefaultSubscription());
2130 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2131 }
2132
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 private void publish() {
2134 if (DBG) log("publish: " + this);
2135
Peter Wangc035ce42020-01-08 21:00:22 -08002136 TelephonyFrameworkInitializer
2137 .getTelephonyServiceManager()
2138 .getTelephonyServiceRegisterer()
2139 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 }
2141
Stuart Scott584921c2015-01-15 17:10:34 -08002142 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002143 if (request.phone != null) {
2144 return request.phone;
2145 } else {
2146 return getPhoneFromSubId(request.subId);
2147 }
2148 }
2149
2150 private Phone getPhoneFromSubId(int subId) {
2151 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2152 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002153 }
2154
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002155 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2156 Phone phone = getPhoneFromRequest(request);
2157 return phone == null ? null :
2158 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2159 }
2160
Wink Saville36469e72014-06-11 15:17:00 -07002161 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002162 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002163 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002166 private void sendEraseModemConfig(Phone phone) {
2167 if (phone != null) {
2168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2169 mApp, phone.getSubId(), "eraseModemConfig");
2170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2173 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2174 } finally {
2175 Binder.restoreCallingIdentity(identity);
2176 }
2177 }
2178 }
2179
Peter Wang050bb052020-01-13 23:33:09 -08002180 private boolean isImsAvailableOnDevice() {
2181 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2182 if (pm == null) {
2183 // For some reason package manger is not available.. This will fail internally anyway,
2184 // so do not throw error and allow.
2185 return true;
2186 }
2187 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2188 }
2189
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002191 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002192 }
2193
Wink Savilleb564aae2014-10-23 10:18:09 -07002194 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 if (DBG) log("dial: " + number);
2196 // No permission check needed here: This is just a wrapper around the
2197 // ACTION_DIAL intent, which is available to any app since it puts up
2198 // the UI before it does anything.
2199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002200 final long identity = Binder.clearCallingIdentity();
2201 try {
2202 String url = createTelUrl(number);
2203 if (url == null) {
2204 return;
2205 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207 // PENDING: should we just silently fail if phone is offhook or ringing?
2208 PhoneConstants.State state = mCM.getState(subId);
2209 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2210 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2211 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2212 mApp.startActivity(intent);
2213 }
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 }
2217 }
2218
2219 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002220 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002221 }
2222
Wink Savilleb564aae2014-10-23 10:18:09 -07002223 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 if (DBG) log("call: " + number);
2225
2226 // This is just a wrapper around the ACTION_CALL intent, but we still
2227 // need to do a permission check since we're calling startActivity()
2228 // from the context of the phone app.
2229 enforceCallPermission();
2230
Jordan Liu1617b712019-07-10 15:06:26 -07002231 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 != AppOpsManager.MODE_ALLOWED) {
2233 return;
2234 }
2235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002236 final long identity = Binder.clearCallingIdentity();
2237 try {
2238 String url = createTelUrl(number);
2239 if (url == null) {
2240 return;
2241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243 boolean isValid = false;
2244 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2245 if (slist != null) {
2246 for (SubscriptionInfo subInfoRecord : slist) {
2247 if (subInfoRecord.getSubscriptionId() == subId) {
2248 isValid = true;
2249 break;
2250 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002251 }
Wink Saville08874612014-08-31 19:19:58 -07002252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002253 if (!isValid) {
2254 return;
2255 }
Wink Saville08874612014-08-31 19:19:58 -07002256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2258 intent.putExtra(SUBSCRIPTION_KEY, subId);
2259 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2260 mApp.startActivity(intent);
2261 } finally {
2262 Binder.restoreCallingIdentity(identity);
2263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 }
2265
Wink Savilleb564aae2014-10-23 10:18:09 -07002266 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002267 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002268 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2269 }
2270
Wink Savilleb564aae2014-10-23 10:18:09 -07002271 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002272 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002273 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2274 }
2275
Wink Savilleb564aae2014-10-23 10:18:09 -07002276 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002278
2279 final long identity = Binder.clearCallingIdentity();
2280 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002281 Phone phone = getPhone(subId);
2282 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002283 checkSimPin.start();
2284 return checkSimPin.unlockSim(null, pin);
2285 } finally {
2286 Binder.restoreCallingIdentity(identity);
2287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 }
2289
Wink Savilleb564aae2014-10-23 10:18:09 -07002290 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292
2293 final long identity = Binder.clearCallingIdentity();
2294 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002295 Phone phone = getPhone(subId);
2296 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002297 checkSimPuk.start();
2298 return checkSimPuk.unlockSim(puk, pin);
2299 } finally {
2300 Binder.restoreCallingIdentity(identity);
2301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 }
2303
2304 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002305 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 * a synchronous one.
2307 */
2308 private static class UnlockSim extends Thread {
2309
2310 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002311 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312
2313 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002314 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2315 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316
2317 // For replies from SimCard interface
2318 private Handler mHandler;
2319
2320 // For async handler to identify request type
2321 private static final int SUPPLY_PIN_COMPLETE = 100;
2322
Michele Berionned9fbae52020-11-13 02:36:59 +00002323 UnlockSim(int phoneId, IccCard simCard) {
2324 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 mSimCard = simCard;
2326 }
2327
2328 @Override
2329 public void run() {
2330 Looper.prepare();
2331 synchronized (UnlockSim.this) {
2332 mHandler = new Handler() {
2333 @Override
2334 public void handleMessage(Message msg) {
2335 AsyncResult ar = (AsyncResult) msg.obj;
2336 switch (msg.what) {
2337 case SUPPLY_PIN_COMPLETE:
2338 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2339 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002340 mRetryCount = msg.arg1;
2341 if (ar.exception != null) {
2342 if (ar.exception instanceof CommandException &&
2343 ((CommandException)(ar.exception)).getCommandError()
2344 == CommandException.Error.PASSWORD_INCORRECT) {
2345 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002346 } //When UiccCardApp dispose,handle message and return exception
2347 else if (ar.exception instanceof CommandException &&
2348 ((CommandException) (ar.exception)).getCommandError()
2349 == CommandException.Error.ABORTED) {
2350 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002351 } else {
2352 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2353 }
2354 } else {
2355 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 mDone = true;
2358 UnlockSim.this.notifyAll();
2359 }
2360 break;
2361 }
2362 }
2363 };
2364 UnlockSim.this.notifyAll();
2365 }
2366 Looper.loop();
2367 }
2368
2369 /*
2370 * Use PIN or PUK to unlock SIM card
2371 *
2372 * If PUK is null, unlock SIM card with PIN
2373 *
2374 * If PUK is not null, unlock SIM card with PUK and set PIN code
2375 */
Wink Saville9de0f752013-10-22 19:04:03 -07002376 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377
2378 while (mHandler == null) {
2379 try {
2380 wait();
2381 } catch (InterruptedException e) {
2382 Thread.currentThread().interrupt();
2383 }
2384 }
2385 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2386
2387 if (puk == null) {
2388 mSimCard.supplyPin(pin, callback);
2389 } else {
2390 mSimCard.supplyPuk(puk, pin, callback);
2391 }
2392
2393 while (!mDone) {
2394 try {
2395 Log.d(LOG_TAG, "wait for done");
2396 wait();
2397 } catch (InterruptedException e) {
2398 // Restore the interrupted status
2399 Thread.currentThread().interrupt();
2400 }
2401 }
2402 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002403 int[] resultArray = new int[2];
2404 resultArray[0] = mResult;
2405 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002406
2407 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2408 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2409 }
2410
Wink Saville9de0f752013-10-22 19:04:03 -07002411 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412 }
2413 }
2414
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002415 /**
2416 * This method has been removed due to privacy and stability concerns.
2417 */
2418 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002420 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2421 return;
Wink Saville36469e72014-06-11 15:17:00 -07002422 }
2423
Nathan Harold1f889d82020-06-04 17:05:26 -07002424 @Override
2425 public void updateServiceLocationWithPackageName(String callingPackage) {
2426 mApp.getSystemService(AppOpsManager.class)
2427 .checkPackage(Binder.getCallingUid(), callingPackage);
2428
Nathan Haroldf096d982020-11-18 17:18:06 -08002429 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002430 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2431 // Callers targeting S have no business invoking this method.
2432 return;
2433 }
2434
2435 LocationAccessPolicy.LocationPermissionResult locationResult =
2436 LocationAccessPolicy.checkLocationPermission(mApp,
2437 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2438 .setCallingPackage(callingPackage)
2439 .setCallingFeatureId(null)
2440 .setCallingPid(Binder.getCallingPid())
2441 .setCallingUid(Binder.getCallingUid())
2442 .setMethod("updateServiceLocation")
2443 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2444 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2445 .build());
2446 // Apps that lack location permission have no business calling this method;
2447 // however, because no permission was declared in the public API, denials must
2448 // all be "soft".
2449 switch (locationResult) {
2450 case DENIED_HARD: /* fall through */
2451 case DENIED_SOFT:
2452 return;
2453 }
2454
2455 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456 final long identity = Binder.clearCallingIdentity();
2457 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002458 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002460 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002461 }
2462 } finally {
2463 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 }
2466
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002467 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002468 @Override
2469 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002470 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002471 }
2472
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002473
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002474 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002475 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2476 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2477 callingFeatureId);
2478 }
2479
2480 @Deprecated
2481 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002482 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002483 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2484 }
2485
2486 @Override
2487 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2488 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002490 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002491 return false;
2492 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493
2494 final long identity = Binder.clearCallingIdentity();
2495 try {
2496 return isRadioOnForSubscriber(subId);
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
2499 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002500 }
2501
2502 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 final long identity = Binder.clearCallingIdentity();
2504 try {
2505 final Phone phone = getPhone(subId);
2506 if (phone != null) {
2507 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2508 } else {
2509 return false;
2510 }
2511 } finally {
2512 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 }
2515
2516 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002517 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 }
Wink Saville36469e72014-06-11 15:17:00 -07002519
Wink Savilleb564aae2014-10-23 10:18:09 -07002520 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002522
2523 final long identity = Binder.clearCallingIdentity();
2524 try {
2525 final Phone phone = getPhone(subId);
2526 if (phone != null) {
2527 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2528 }
2529 } finally {
2530 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002531 }
Wink Saville36469e72014-06-11 15:17:00 -07002532 }
2533
2534 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002535 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002536 }
2537
Wink Savilleb564aae2014-10-23 10:18:09 -07002538 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002539 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002540
2541 final long identity = Binder.clearCallingIdentity();
2542 try {
2543 final Phone phone = getPhone(subId);
2544 if (phone == null) {
2545 return false;
2546 }
2547 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2548 toggleRadioOnOffForSubscriber(subId);
2549 }
2550 return true;
2551 } finally {
2552 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 }
Wink Saville36469e72014-06-11 15:17:00 -07002555
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002556 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002557 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002558 /*
2559 * If any of the Radios are available, it will need to be
2560 * shutdown. So return true if any Radio is available.
2561 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 final long identity = Binder.clearCallingIdentity();
2563 try {
2564 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2565 Phone phone = PhoneFactory.getPhone(i);
2566 if (phone != null && phone.isRadioAvailable()) return true;
2567 }
2568 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2569 return false;
2570 } finally {
2571 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002572 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002573 }
2574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002576 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577 enforceModifyPermission();
2578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2582 logv("Shutting down Phone " + i);
2583 shutdownRadioUsingPhoneId(i);
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002587 }
2588 }
2589
2590 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002591 Phone phone = PhoneFactory.getPhone(phoneId);
2592 if (phone != null && phone.isRadioAvailable()) {
2593 phone.shutdownRadio();
2594 }
2595 }
2596
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002598 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599
2600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2603 if (defaultPhone != null) {
2604 defaultPhone.setRadioPower(turnOn);
2605 return true;
2606 } else {
2607 loge("There's no default phone.");
2608 return false;
2609 }
2610 } finally {
2611 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002612 }
Wink Saville36469e72014-06-11 15:17:00 -07002613 }
2614
Wink Savilleb564aae2014-10-23 10:18:09 -07002615 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617
2618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 final Phone phone = getPhone(subId);
2621 if (phone != null) {
2622 phone.setRadioPower(turnOn);
2623 return true;
2624 } else {
2625 return false;
2626 }
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 }
2631
Wink Saville36469e72014-06-11 15:17:00 -07002632 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002633 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 public boolean enableDataConnectivity() {
2635 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 int subId = mSubscriptionController.getDefaultDataSubId();
2640 final Phone phone = getPhone(subId);
2641 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002642 phone.getDataEnabledSettings().setDataEnabled(
2643 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 return true;
2645 } else {
2646 return false;
2647 }
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 }
2652
Wink Saville36469e72014-06-11 15:17:00 -07002653 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002654 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 public boolean disableDataConnectivity() {
2656 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657
2658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 int subId = mSubscriptionController.getDefaultDataSubId();
2661 final Phone phone = getPhone(subId);
2662 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002663 phone.getDataEnabledSettings().setDataEnabled(
2664 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 return true;
2666 } else {
2667 return false;
2668 }
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 }
2673
Sanket Padawe356d7632015-06-22 14:03:32 -07002674 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002675 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 final Phone phone = getPhone(subId);
2679 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002680 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 } else {
2682 return false;
2683 }
2684 } finally {
2685 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002686 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 }
2688
2689 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002690 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002691 }
2692
pkanwarae03a6b2016-11-06 20:37:09 -08002693 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694 enforceCallPermission();
2695
2696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2699 return;
2700 }
2701 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2702 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
2705 }
pkanwar32d516d2016-10-14 19:37:38 -07002706 };
2707
Wink Savilleb564aae2014-10-23 10:18:09 -07002708 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710
2711 final long identity = Binder.clearCallingIdentity();
2712 try {
2713 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2714 return false;
2715 }
2716 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 }
2721
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002723 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002724 }
2725
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002726 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 Phone phone = PhoneFactory.getPhone(slotIndex);
2730 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2731 PhoneConstantConversions.convertCallState(phone.getState());
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
2734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 }
2736
Sanket Padawe356d7632015-06-22 14:03:32 -07002737 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002738 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002739 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2740 }
2741
2742 @Override
2743 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 final long identity = Binder.clearCallingIdentity();
2745 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002746 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747 if (phone != null) {
2748 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2749 } else {
2750 return PhoneConstantConversions.convertDataState(
2751 PhoneConstants.DataState.DISCONNECTED);
2752 }
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 }
2757
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002759 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002760 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2761 }
2762
2763 @Override
2764 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765 final long identity = Binder.clearCallingIdentity();
2766 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002767 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768 if (phone != null) {
2769 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2770 } else {
2771 return TelephonyManager.DATA_ACTIVITY_NONE;
2772 }
2773 } finally {
2774 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002775 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 }
2777
2778 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002779 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002780 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002781 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002782
2783 LocationAccessPolicy.LocationPermissionResult locationResult =
2784 LocationAccessPolicy.checkLocationPermission(mApp,
2785 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2786 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002787 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002788 .setCallingPid(Binder.getCallingPid())
2789 .setCallingUid(Binder.getCallingUid())
2790 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002791 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002792 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2793 .build());
2794 switch (locationResult) {
2795 case DENIED_HARD:
2796 throw new SecurityException("Not allowed to access cell location");
2797 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002798 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2799 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002800 }
2801
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002802 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002806 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002807 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 } finally {
2809 Binder.restoreCallingIdentity(identity);
2810 }
Svetoslav64fad262015-04-14 14:35:21 -07002811 }
2812
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002813 @Override
Jack Yu01425032020-02-22 19:38:58 -08002814 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002815 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2816 // registered cell info, so return a NULL country instead.
2817 final long identity = Binder.clearCallingIdentity();
2818 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002819 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2820 // Get default phone in this case.
2821 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2822 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002823 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002825 if (phone == null) return "";
2826 ServiceStateTracker sst = phone.getServiceStateTracker();
2827 if (sst == null) return "";
2828 LocaleTracker lt = sst.getLocaleTracker();
2829 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002830 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002831 } finally {
2832 Binder.restoreCallingIdentity(identity);
2833 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002834 }
2835
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002836 /**
2837 * This method was removed due to potential issues caused by performing partial
2838 * updates of service state, and lack of a credible use case.
2839 *
2840 * This has the ability to break the telephony implementation by disabling notification of
2841 * changes in device connectivity. DO NOT USE THIS!
2842 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002843 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 public void enableLocationUpdates() {
2845 mApp.enforceCallingOrSelfPermission(
2846 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002849 /**
2850 * This method was removed due to potential issues caused by performing partial
2851 * updates of service state, and lack of a credible use case.
2852 *
2853 * This has the ability to break the telephony implementation by disabling notification of
2854 * changes in device connectivity. DO NOT USE THIS!
2855 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856 @Override
2857 public void disableLocationUpdates() {
2858 mApp.enforceCallingOrSelfPermission(
2859 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
2862 @Override
2863 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002864 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2865 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002866 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002867 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2868 throw new SecurityException(
2869 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2870 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002871
Jordan Liu1617b712019-07-10 15:06:26 -07002872 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2874 return null;
2875 }
Svetoslav64fad262015-04-14 14:35:21 -07002876
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002877 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002879 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002880 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881
Nathan Haroldf180aac2018-06-01 18:43:55 -07002882 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2883 for (CellInfo ci : info) {
2884 if (ci instanceof CellInfoGsm) {
2885 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2886 } else if (ci instanceof CellInfoWcdma) {
2887 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002889 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002890 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
2892
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002893 private List<CellInfo> getCachedCellInfo() {
2894 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2895 for (Phone phone : PhoneFactory.getPhones()) {
2896 List<CellInfo> info = phone.getAllCellInfo();
2897 if (info != null) cellInfos.addAll(info);
2898 }
2899 return cellInfos;
2900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901
2902 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002903 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002904 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002905 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002906
2907 LocationAccessPolicy.LocationPermissionResult locationResult =
2908 LocationAccessPolicy.checkLocationPermission(mApp,
2909 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2910 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002911 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002912 .setCallingPid(Binder.getCallingPid())
2913 .setCallingUid(Binder.getCallingUid())
2914 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002915 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002916 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2917 .build());
2918 switch (locationResult) {
2919 case DENIED_HARD:
2920 throw new SecurityException("Not allowed to access cell info");
2921 case DENIED_SOFT:
2922 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002923 }
2924
Nathan Haroldf096d982020-11-18 17:18:06 -08002925 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002926 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2927 return getCachedCellInfo();
2928 }
2929
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002930 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002931 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002932 final long identity = Binder.clearCallingIdentity();
2933 try {
2934 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2935 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002936 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002937 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938 if (info != null) cellInfos.addAll(info);
2939 }
2940 return cellInfos;
2941 } finally {
2942 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002943 }
2944 }
2945
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002946 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002947 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2948 String callingFeatureId) {
2949 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2950 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002951 }
2952
2953 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002954 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2955 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002956 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002957 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002958 }
2959
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002960 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2961 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002962 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002963 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002964
2965 LocationAccessPolicy.LocationPermissionResult locationResult =
2966 LocationAccessPolicy.checkLocationPermission(mApp,
2967 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2968 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002969 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002970 .setCallingPid(Binder.getCallingPid())
2971 .setCallingUid(Binder.getCallingUid())
2972 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002973 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2974 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002975 .build());
2976 switch (locationResult) {
2977 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002978 if (TelephonyPermissions
2979 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002980 // Safetynet logging for b/154934934
2981 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2982 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002983 throw new SecurityException("Not allowed to access cell info");
2984 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002985 if (TelephonyPermissions
2986 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002987 // Safetynet logging for b/154934934
2988 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2989 }
Nathan Harold5320c422019-05-09 10:26:08 -07002990 try {
2991 cb.onCellInfo(new ArrayList<CellInfo>());
2992 } catch (RemoteException re) {
2993 // Drop without consequences
2994 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002995 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002996 }
2997
Nathan Harolda939a962019-05-09 10:13:47 -07002998
2999 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003000 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3001
3002 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3003 }
3004
3005 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003007 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003008 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003009
3010 final long identity = Binder.clearCallingIdentity();
3011 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003012 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 } finally {
3014 Binder.restoreCallingIdentity(identity);
3015 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 }
3017
Shishir Agrawala9f32182016-04-12 12:00:16 -07003018 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003019 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003020 Phone phone = PhoneFactory.getPhone(slotIndex);
3021 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003022 return null;
3023 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003024 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003025 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003026 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003027 return null;
3028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003029
3030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 return phone.getImei();
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
3035 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003036 }
3037
3038 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003039 public String getTypeAllocationCodeForSlot(int slotIndex) {
3040 Phone phone = PhoneFactory.getPhone(slotIndex);
3041 String tac = null;
3042 if (phone != null) {
3043 String imei = phone.getImei();
3044 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3045 }
3046 return tac;
3047 }
3048
3049 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003050 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003051 Phone phone = PhoneFactory.getPhone(slotIndex);
3052 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003053 return null;
3054 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003055
Jeff Davidson913390f2018-02-23 17:11:49 -08003056 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003057 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003058 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003059 return null;
3060 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061
3062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 return phone.getMeid();
3065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
Jack Yu2af8d712017-03-15 17:14:14 -07003068 }
3069
3070 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003071 public String getManufacturerCodeForSlot(int slotIndex) {
3072 Phone phone = PhoneFactory.getPhone(slotIndex);
3073 String manufacturerCode = null;
3074 if (phone != null) {
3075 String meid = phone.getMeid();
3076 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3077 }
3078 return manufacturerCode;
3079 }
3080
3081 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003082 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3083 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003084 Phone phone = PhoneFactory.getPhone(slotIndex);
3085 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003086 return null;
3087 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003088 int subId = phone.getSubId();
3089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003090 mApp, subId, callingPackage, callingFeatureId,
3091 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003092 return null;
3093 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094
3095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 return phone.getDeviceSvn();
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003101 }
3102
fionaxu43304da2017-11-27 22:51:16 -08003103 @Override
3104 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 final Phone phone = getPhone(subId);
3108 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
fionaxu43304da2017-11-27 22:51:16 -08003112 }
3113
3114 @Override
3115 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 final Phone phone = getPhone(subId);
3119 return phone == null ? null : phone.getCarrierName();
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
fionaxu43304da2017-11-27 22:51:16 -08003123 }
3124
calvinpanffe225e2018-11-01 19:43:06 +08003125 @Override
chen xu0026ca62019-03-06 15:28:50 -08003126 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003127 final long identity = Binder.clearCallingIdentity();
3128 try {
3129 final Phone phone = getPhone(subId);
3130 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003131 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
3137 @Override
chen xu0026ca62019-03-06 15:28:50 -08003138 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003142 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
3146 }
3147
chen xu651eec72018-11-11 19:03:44 -08003148 @Override
chen xu864e11c2018-12-06 22:10:03 -08003149 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3150 if (!isSubscriptionMccMnc) {
3151 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3152 }
chen xu651eec72018-11-11 19:03:44 -08003153 final Phone phone = PhoneFactory.getPhone(slotIndex);
3154 if (phone == null) {
3155 return TelephonyManager.UNKNOWN_CARRIER_ID;
3156 }
3157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3160 } finally {
3161 Binder.restoreCallingIdentity(identity);
3162 }
3163 }
3164
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 //
3166 // Internal helper methods.
3167 //
3168
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003169 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003170 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3171 *
3172 * @throws SecurityException if the caller does not have the required permission
3173 */
3174 private void enforceModifyPermission() {
3175 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3176 }
3177
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003178 /**
3179 * Make sure the caller is system.
3180 *
3181 * @throws SecurityException if the caller is not system.
3182 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003183 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003184 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3185 throw new SecurityException("Caller must be system");
3186 }
3187 }
3188
Shuo Qianf2b2df42019-11-13 17:43:31 -08003189 private void enforceActiveEmergencySessionPermission() {
3190 mApp.enforceCallingOrSelfPermission(
3191 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3192 }
3193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003194 /**
3195 * Make sure the caller has the CALL_PHONE permission.
3196 *
3197 * @throws SecurityException if the caller does not have the required permission
3198 */
3199 private void enforceCallPermission() {
3200 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3201 }
3202
paulhu423b5f22019-08-23 19:17:33 +08003203 private void enforceSettingsPermission() {
3204 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003205 }
3206
Michele Berionned9fbae52020-11-13 02:36:59 +00003207 private void enforceRebootPermission() {
3208 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3209 }
3210
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 private String createTelUrl(String number) {
3212 if (TextUtils.isEmpty(number)) {
3213 return null;
3214 }
3215
Jake Hambye994d462014-02-03 13:10:13 -08003216 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003217 }
3218
Ihab Awadf9e92732013-12-05 18:02:52 -08003219 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003220 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3221 }
3222
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003223 private static void logv(String msg) {
3224 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3225 }
3226
Ihab Awadf9e92732013-12-05 18:02:52 -08003227 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003228 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3229 }
3230
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003231 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003232 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003233 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003234 }
3235
Sanket Padawe356d7632015-06-22 14:03:32 -07003236 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003237 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003238 final long identity = Binder.clearCallingIdentity();
3239 try {
3240 final Phone phone = PhoneFactory.getPhone(slotIndex);
3241 if (phone == null) {
3242 return PhoneConstants.PHONE_TYPE_NONE;
3243 } else {
3244 return phone.getPhoneType();
3245 }
3246 } finally {
3247 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003249 }
3250
3251 /**
3252 * Returns the CDMA ERI icon index to display
3253 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003254 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003255 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3256 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3257 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003258 }
3259
Sanket Padawe356d7632015-06-22 14:03:32 -07003260 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003261 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3262 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003264 mApp, subId, callingPackage, callingFeatureId,
3265 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003266 return -1;
3267 }
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) {
3273 return phone.getCdmaEriIconIndex();
3274 } else {
3275 return -1;
3276 }
3277 } finally {
3278 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 }
3281
3282 /**
3283 * Returns the CDMA ERI icon mode,
3284 * 0 - ON
3285 * 1 - FLASHING
3286 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003287 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003288 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3289 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3290 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003291 }
3292
Sanket Padawe356d7632015-06-22 14:03:32 -07003293 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003294 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3295 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003297 mApp, subId, callingPackage, callingFeatureId,
3298 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003299 return -1;
3300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003301
3302 final long identity = Binder.clearCallingIdentity();
3303 try {
3304 final Phone phone = getPhone(subId);
3305 if (phone != null) {
3306 return phone.getCdmaEriIconMode();
3307 } else {
3308 return -1;
3309 }
3310 } finally {
3311 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003313 }
3314
3315 /**
3316 * Returns the CDMA ERI text,
3317 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003318 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003319 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3320 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3321 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003322 }
3323
Sanket Padawe356d7632015-06-22 14:03:32 -07003324 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003325 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3326 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003328 mApp, subId, callingPackage, callingFeatureId,
3329 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003330 return null;
3331 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332
3333 final long identity = Binder.clearCallingIdentity();
3334 try {
3335 final Phone phone = getPhone(subId);
3336 if (phone != null) {
3337 return phone.getCdmaEriText();
3338 } else {
3339 return null;
3340 }
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003344 }
3345
3346 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003347 * Returns the CDMA MDN.
3348 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003349 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003350 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3352 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003357 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358 return phone.getLine1Number();
3359 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003360 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003361 return null;
3362 }
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003365 }
3366 }
3367
3368 /**
3369 * Returns the CDMA MIN.
3370 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003371 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003372 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3374 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003375
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 final Phone phone = getPhone(subId);
3379 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3380 return phone.getCdmaMin();
3381 } else {
3382 return null;
3383 }
3384 } finally {
3385 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003386 }
3387 }
3388
Hall Liud892bec2018-11-30 14:51:45 -08003389 @Override
3390 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3391 INumberVerificationCallback callback, String callingPackage) {
3392 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3393 != PERMISSION_GRANTED) {
3394 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3395 }
3396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3397
3398 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3399 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003400 throw new SecurityException("Calling package must be configured in the device config: "
3401 + "calling package: " + callingPackage
3402 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003403 }
3404
3405 if (range == null) {
3406 throw new NullPointerException("Range must be non-null");
3407 }
3408
3409 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003410 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003411
3412 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3413 }
3414
Junda Liuca05d5d2014-08-14 22:36:34 -07003415 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003416 * Returns true if CDMA provisioning needs to run.
3417 */
3418 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419 final long identity = Binder.clearCallingIdentity();
3420 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003421 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003425 }
3426
3427 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003428 * Sets the voice mail number of a given subId.
3429 */
3430 @Override
3431 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003432 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3433 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3438 new Pair<String, String>(alphaTag, number), new Integer(subId));
3439 return success;
3440 } finally {
3441 Binder.restoreCallingIdentity(identity);
3442 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003443 }
3444
Ta-wei Yen87c49842016-05-13 21:19:52 -07003445 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003446 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3447 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003448 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3449 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003450 if (!TextUtils.equals(callingPackage, systemDialer)) {
3451 throw new SecurityException("caller must be system dialer");
3452 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003453
3454 final long identity = Binder.clearCallingIdentity();
3455 try {
3456 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3457 if (phoneAccountHandle == null) {
3458 return null;
3459 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003460 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003463 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003464 }
3465
3466 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003467 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3468 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003469 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003471 mApp, subId, callingPackage, callingFeatureId,
3472 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003473 return null;
3474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003475
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003476 final long identity = Binder.clearCallingIdentity();
3477 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003482 }
3483
3484 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003485 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3486 VisualVoicemailSmsFilterSettings settings) {
3487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003492 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003496 }
3497
3498 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003499 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003501
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003505 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003509 }
3510
3511 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003512 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3513 String callingPackage, int subId) {
3514 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003519 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520 } finally {
3521 Binder.restoreCallingIdentity(identity);
3522 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003523 }
3524
3525 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003526 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003527 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003532 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003536 }
3537
3538 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003539 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3540 String callingAttributionTag, int subId, String number, int port, String text,
3541 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003543 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003544 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003545 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003546 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3547 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003548 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003549
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003550 /**
fionaxu0152e512016-11-14 13:36:14 -08003551 * Sets the voice activation state of a given subId.
3552 */
3553 @Override
3554 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3556 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 final Phone phone = getPhone(subId);
3561 if (phone != null) {
3562 phone.setVoiceActivationState(activationState);
3563 } else {
3564 loge("setVoiceActivationState fails with invalid subId: " + subId);
3565 }
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003568 }
3569 }
3570
3571 /**
3572 * Sets the data activation state of a given subId.
3573 */
3574 @Override
3575 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3577 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578
3579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 final Phone phone = getPhone(subId);
3582 if (phone != null) {
3583 phone.setDataActivationState(activationState);
3584 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003585 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586 }
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003589 }
3590 }
3591
3592 /**
3593 * Returns the voice activation state of a given subId.
3594 */
3595 @Override
3596 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003597 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598
fionaxu0152e512016-11-14 13:36:14 -08003599 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 if (phone != null) {
3603 return phone.getVoiceActivationState();
3604 } else {
3605 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3606 }
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003609 }
3610 }
3611
3612 /**
3613 * Returns the data activation state of a given subId.
3614 */
3615 @Override
3616 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003617 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003618
fionaxu0152e512016-11-14 13:36:14 -08003619 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 if (phone != null) {
3623 return phone.getDataActivationState();
3624 } else {
3625 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3626 }
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003629 }
3630 }
3631
3632 /**
Wink Saville36469e72014-06-11 15:17:00 -07003633 * Returns the unread count of voicemails for a subId
3634 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003635 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003636 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3637 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003639 mApp, subId, callingPackage, callingFeatureId,
3640 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003641 return 0;
3642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 final Phone phone = getPhone(subId);
3646 if (phone != null) {
3647 return phone.getVoiceMessageCount();
3648 } else {
3649 return 0;
3650 }
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003654 }
3655
3656 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003657 * returns true, if the device is in a state where both voice and data
3658 * are supported simultaneously. This can change based on location or network condition.
3659 */
3660 @Override
3661 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 final Phone phone = getPhone(subId);
3665 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003669 }
3670
3671 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003672 * Send the dialer code if called from the current default dialer or the caller has
3673 * carrier privilege.
3674 * @param inputCode The dialer code to send
3675 */
3676 @Override
3677 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003678 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003679 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003680 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3681 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003682 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003683 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003684 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003689 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
fionaxu235cc5e2017-03-06 22:25:57 -08003693 }
3694
Pengquan Menga1bb6272018-09-06 09:59:22 -07003695 @Override
3696 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003697 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07003698 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003699 mApp, subId, "getNetworkSelectionMode");
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 if (!isActiveSubscription(subId)) {
3703 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3704 }
3705 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003708 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003709 }
3710
Brad Ebinger35c841c2018-10-01 10:40:55 -07003711 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003712 public boolean isInEmergencySmsMode() {
3713 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3714 final long identity = Binder.clearCallingIdentity();
3715 try {
3716 for (Phone phone : PhoneFactory.getPhones()) {
3717 if (phone.isInEmergencySmsMode()) {
3718 return true;
3719 }
3720 }
3721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
3724 return false;
3725 }
3726
shilu366312e2019-12-17 09:28:10 -08003727 /**
3728 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3729 * @param subId The subscription to use to check the configuration.
3730 * @param c The callback that will be used to send the result.
3731 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003732 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003733 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3734 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003735 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003736 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003737
Brad Ebinger77b832e2019-10-17 17:03:22 -07003738 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3739 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3740 "IMS not available on device.");
3741 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 final long token = Binder.clearCallingIdentity();
3743 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003744 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003745 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003747 } catch (ImsException e) {
3748 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003749 } finally {
3750 Binder.restoreCallingIdentity(token);
3751 }
3752 }
3753
shilu366312e2019-12-17 09:28:10 -08003754 /**
3755 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3756 * @param subId The subscription to use to check the configuration.
3757 * @param c The callback that will be used to send the result.
3758 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003759 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003760 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003761 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003762 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003763 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3764 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3765 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003766 final long token = Binder.clearCallingIdentity();
3767 try {
3768 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3769 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3770 .removeRegistrationCallbackForSubscription(c, subId);
3771 } catch (ImsException e) {
3772 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3773 + "is inactive, ignoring unregister.");
3774 // If the subscription is no longer active, just return, since the callback
3775 // will already have been removed internally.
3776 } finally {
3777 Binder.restoreCallingIdentity(token);
3778 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003779 }
3780
Brad Ebinger774ba362019-10-22 17:36:18 -07003781 /**
3782 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3783 */
3784 @Override
3785 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3786 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3787 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3788 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3789 "IMS not available on device.");
3790 }
3791 final long token = Binder.clearCallingIdentity();
3792 try {
3793 Phone phone = getPhone(subId);
3794 if (phone == null) {
3795 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3796 + subId + "'");
3797 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3798 }
3799 phone.getImsRegistrationState(regState -> {
3800 try {
3801 consumer.accept((regState == null)
3802 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3803 } catch (RemoteException e) {
3804 // Ignore if the remote process is no longer available to call back.
3805 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3806 }
3807 });
3808 } finally {
3809 Binder.restoreCallingIdentity(token);
3810 }
3811 }
3812
3813 /**
3814 * Get the transport type for the IMS service registration state.
3815 */
3816 @Override
3817 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003818 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003819 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003820 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3821 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3822 "IMS not available on device.");
3823 }
3824 final long token = Binder.clearCallingIdentity();
3825 try {
3826 Phone phone = getPhone(subId);
3827 if (phone == null) {
3828 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3829 + subId + "'");
3830 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3831 }
3832 phone.getImsRegistrationTech(regTech -> {
3833 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3834 int regTechConverted = (regTech == null)
3835 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3836 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3837 regTechConverted);
3838 try {
3839 consumer.accept(regTechConverted);
3840 } catch (RemoteException e) {
3841 // Ignore if the remote process is no longer available to call back.
3842 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3843 }
3844 });
3845 } finally {
3846 Binder.restoreCallingIdentity(token);
3847 }
3848 }
3849
shilu366312e2019-12-17 09:28:10 -08003850 /**
3851 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3852 * @param subId The subscription to use to check the configuration.
3853 * @param c The callback that will be used to send the result.
3854 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003855 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003856 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3857 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003858 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003859 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003860 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3861 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3862 "IMS not available on device.");
3863 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003864 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3865 final long token = Binder.clearCallingIdentity();
3866 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003867 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003869 } catch (ImsException e) {
3870 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003871 } finally {
3872 Binder.restoreCallingIdentity(token);
3873 }
3874 }
3875
shilu366312e2019-12-17 09:28:10 -08003876 /**
3877 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3878 * @param subId The subscription to use to check the configuration.
3879 * @param c The callback that will be used to send the result.
3880 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003881 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003882 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003883 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003884 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003885 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3886 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3887 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003888
3889 final long token = Binder.clearCallingIdentity();
3890 try {
3891 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3892 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003893 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003894 } catch (ImsException e) {
3895 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3896 + "is inactive, ignoring unregister.");
3897 // If the subscription is no longer active, just return, since the callback
3898 // will already have been removed internally.
3899 } finally {
3900 Binder.restoreCallingIdentity(token);
3901 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 }
3903
3904 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003905 public boolean isCapable(int subId, int capability, int regTech) {
3906 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3908 final long token = Binder.clearCallingIdentity();
3909 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003910 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003911 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003912 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3914 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003915 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003916 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3917 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003918 } finally {
3919 Binder.restoreCallingIdentity(token);
3920 }
3921 }
3922
3923 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003924 public boolean isAvailable(int subId, int capability, int regTech) {
3925 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003926 final long token = Binder.clearCallingIdentity();
3927 try {
3928 Phone phone = getPhone(subId);
3929 if (phone == null) return false;
3930 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003931 } catch (com.android.ims.ImsException e) {
3932 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3933 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003934 } finally {
3935 Binder.restoreCallingIdentity(token);
3936 }
3937 }
3938
Brad Ebinger77b832e2019-10-17 17:03:22 -07003939 /**
3940 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3941 * subscription.
3942 * @param subId The subscription to use to check the configuration.
3943 * @param callback The callback that will be used to send the result.
3944 * @param capability The MmTelFeature capability that will be used to send the result.
3945 * @param transportType The transport type of the MmTelFeature capability.
3946 */
3947 @Override
3948 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3949 int transportType) {
3950 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3951 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3952 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3953 "IMS not available on device.");
3954 }
3955 final long token = Binder.clearCallingIdentity();
3956 try {
3957 int slotId = getSlotIndex(subId);
3958 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3959 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3960 + subId + "'");
3961 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3962 }
3963 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3964 transportType, aBoolean -> {
3965 try {
3966 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3967 } catch (RemoteException e) {
3968 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3969 + "running. Ignore");
3970 }
3971 });
3972 } finally {
3973 Binder.restoreCallingIdentity(token);
3974 }
3975 }
3976
shilu366312e2019-12-17 09:28:10 -08003977 /**
3978 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3979 * @param subId The subscription to use to check the configuration.
3980 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 @Override
3982 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003983 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003984 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003985
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3987 final long token = Binder.clearCallingIdentity();
3988 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003989 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003991 } catch (ImsException e) {
3992 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 } finally {
3994 Binder.restoreCallingIdentity(token);
3995 }
3996 }
3997
3998 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003999 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004001 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004002 final long identity = Binder.clearCallingIdentity();
4003 try {
4004 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004005 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004007 } catch (ImsException e) {
4008 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
4012 }
4013
shilu366312e2019-12-17 09:28:10 -08004014 /**
4015 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4016 * @param subId The subscription to use to check the configuration.
4017 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004018 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004019 public boolean isVtSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004020 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004021 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004025 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4026 } catch (ImsException e) {
4027 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
4031 }
4032
4033 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004034 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004036 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004040 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004048 /**
4049 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4050 * @param subId The subscription to use to check the configuration.
4051 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 @Override
4053 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004054 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004055 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 final long identity = Binder.clearCallingIdentity();
4057 try {
4058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004059 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004061 } catch (ImsException e) {
4062 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 } finally {
4064 Binder.restoreCallingIdentity(identity);
4065 }
4066 }
4067
4068 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004069 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004071 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004075 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004076 } catch (ImsException e) {
4077 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 } finally {
4079 Binder.restoreCallingIdentity(identity);
4080 }
4081 }
4082
shilu366312e2019-12-17 09:28:10 -08004083 /**
4084 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4085 * @param subId The subscription to use to check the configuration.
4086 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 @Override
4088 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004089 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004090 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 final long identity = Binder.clearCallingIdentity();
4092 try {
4093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004094 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004095 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004096 } catch (ImsException e) {
4097 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 } finally {
4099 Binder.restoreCallingIdentity(identity);
4100 }
4101 }
4102
4103 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004104 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004106 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 final long identity = Binder.clearCallingIdentity();
4108 try {
4109 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004110 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004112 } catch (ImsException e) {
4113 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 } finally {
4115 Binder.restoreCallingIdentity(identity);
4116 }
4117 }
4118
4119 @Override
4120 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4122 "setVoWiFiNonPersistent");
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004126 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004127 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004128 } catch (ImsException e) {
4129 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
4133 }
4134
shilu366312e2019-12-17 09:28:10 -08004135 /**
4136 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4137 * @param subId The subscription to use to check the configuration.
4138 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 @Override
4140 public int getVoWiFiModeSetting(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004141 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004142 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004146 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004148 } catch (ImsException e) {
4149 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 } finally {
4151 Binder.restoreCallingIdentity(identity);
4152 }
4153 }
4154
4155 @Override
4156 public void setVoWiFiModeSetting(int subId, int mode) {
4157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4158 "setVoWiFiModeSetting");
4159 final long identity = Binder.clearCallingIdentity();
4160 try {
4161 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004162 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004163 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004164 } catch (ImsException e) {
4165 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
4169 }
4170
4171 @Override
4172 public int getVoWiFiRoamingModeSetting(int subId) {
4173 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4174 final long identity = Binder.clearCallingIdentity();
4175 try {
4176 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004177 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004178 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004179 } catch (ImsException e) {
4180 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
4184 }
4185
4186 @Override
4187 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4188 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4189 "setVoWiFiRoamingModeSetting");
4190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004193 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004195 } catch (ImsException e) {
4196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 } finally {
4198 Binder.restoreCallingIdentity(identity);
4199 }
4200 }
4201
4202 @Override
4203 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4205 "setRttCapabilityEnabled");
4206 final long identity = Binder.clearCallingIdentity();
4207 try {
4208 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004209 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4210 } catch (ImsException e) {
4211 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 } finally {
4213 Binder.restoreCallingIdentity(identity);
4214 }
4215 }
4216
shilu366312e2019-12-17 09:28:10 -08004217 /**
4218 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4219 * @param subId The subscription to use to check the configuration.
4220 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 @Override
4222 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004223 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004224 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 final long identity = Binder.clearCallingIdentity();
4226 try {
4227 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004228 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004230 } catch (ImsException e) {
4231 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 } finally {
4233 Binder.restoreCallingIdentity(identity);
4234 }
4235 }
4236
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004237 @Override
4238 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4239 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4240 final long identity = Binder.clearCallingIdentity();
4241 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004242 if (!isImsAvailableOnDevice()) {
4243 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4244 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004245 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004246 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004247 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004248 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004249 } catch (ImsException e) {
4250 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
4254 }
4255
4256 @Override
4257 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4258 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4259 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004260 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4261 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4262 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004263 try {
4264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004265 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004266 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004267 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004268 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4269 + "is inactive, ignoring unregister.");
4270 // If the subscription is no longer active, just return, since the callback will already
4271 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004272 } finally {
4273 Binder.restoreCallingIdentity(identity);
4274 }
4275 }
4276
allenwtsu99c623b2020-01-03 18:24:23 +08004277
4278 private void checkModifyPhoneStatePermission(int subId, String message) {
4279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4280 message);
4281 }
4282
4283 private boolean isImsProvisioningRequired(int subId, int capability,
4284 boolean isMmtelCapability) {
4285 Phone phone = getPhone(subId);
4286 if (phone == null) {
4287 loge("phone instance null for subid " + subId);
4288 return false;
4289 }
4290 if (isMmtelCapability) {
4291 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4292 return false;
4293 }
4294 } else {
4295 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4296 return false;
4297 }
4298 }
4299 return true;
4300 }
4301
4302 @Override
4303 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4304 boolean isProvisioned) {
4305 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4306
4307 final long identity = Binder.clearCallingIdentity();
4308 try {
4309 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4310 if (!isImsProvisioningRequired(subId, capability, false)) {
4311 return;
4312 }
4313
4314 // this capability requires provisioning, route to the correct API.
4315 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4316 switch (capability) {
4317 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4318 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4319 ims.setEabProvisioned(isProvisioned);
4320 break;
4321 default: {
4322 throw new IllegalArgumentException("Tried to set provisioning for "
4323 + "rcs capability '" + capability + "', which does not require "
4324 + "provisioning.");
4325 }
4326 }
4327 } finally {
4328 Binder.restoreCallingIdentity(identity);
4329 }
4330
4331 }
4332
4333
4334 @Override
4335 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4336 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4340 if (!isImsProvisioningRequired(subId, capability, false)) {
4341 return true;
4342 }
4343
4344 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4345 switch (capability) {
4346 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4347 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4348 return ims.isEabProvisionedOnDevice();
4349
4350 default: {
4351 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4352 + "capability '" + capability + "', which does not require "
4353 + "provisioning.");
4354 }
4355 }
4356
4357 } finally {
4358 Binder.restoreCallingIdentity(identity);
4359 }
4360 }
4361
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004362 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004363 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4364 boolean isProvisioned) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004365 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4366 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004367 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4368 }
allenwtsu99c623b2020-01-03 18:24:23 +08004369 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004370 final long identity = Binder.clearCallingIdentity();
4371 try {
4372 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004373 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004374 return;
4375 }
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004376 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4377 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4378 loge("setImsProvisioningStatusForCapability: called for technology that does "
4379 + "not support provisioning - " + tech);
4380 return;
4381 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004382
4383 // this capability requires provisioning, route to the correct API.
4384 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4385 switch (capability) {
4386 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4387 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4388 ims.setVolteProvisioned(isProvisioned);
4389 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4390 ims.setWfcProvisioned(isProvisioned);
4391 }
4392 break;
4393 }
4394 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4395 // There is currently no difference in VT provisioning type.
4396 ims.setVtProvisioned(isProvisioned);
4397 break;
4398 }
4399 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4400 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4401 // change the capability of the feature instead if needed.
4402 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4403 == isProvisioned) {
4404 // No change in provisioning.
4405 return;
4406 }
4407 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4408 try {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004409 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004410 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004411 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4412 + ", Exception" + e.getMessage());
4413 }
4414 break;
4415 }
4416 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004417 throw new IllegalArgumentException("Tried to set provisioning for "
4418 + "MmTel capability '" + capability + "', which does not require "
4419 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004420 }
4421 }
4422
4423 } finally {
4424 Binder.restoreCallingIdentity(identity);
4425 }
4426 }
4427
4428 @Override
4429 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004430 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4431 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004432 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4433 }
4434 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4435 final long identity = Binder.clearCallingIdentity();
4436 try {
4437 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004438 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004439 return true;
4440 }
4441
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004442 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4443 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4444 loge("getImsProvisioningStatusForCapability: called for technology that does "
4445 + "not support provisioning - " + tech);
4446 return true;
4447 }
4448
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004449 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4450 switch (capability) {
4451 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4452 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4453 return ims.isVolteProvisionedOnDevice();
4454 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4455 return ims.isWfcProvisionedOnDevice();
4456 }
4457 // This should never happen, since we are checking tech above to make sure it
4458 // is either LTE or IWLAN.
4459 throw new IllegalArgumentException("Invalid radio technology for voice "
4460 + "capability.");
4461 }
4462 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4463 // There is currently no difference in VT provisioning type.
4464 return ims.isVtProvisionedOnDevice();
4465 }
4466 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4467 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4468 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4469 }
4470 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004471 throw new IllegalArgumentException(
4472 "Tried to get provisioning for MmTel capability '" + capability
4473 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004474 }
4475 }
4476
4477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
4480 }
4481
4482 @Override
4483 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4484 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4485 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4486 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4487 }
4488 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4489 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4490 return (provisionedBits & capability) > 0;
4491 }
4492
4493 @Override
4494 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4495 boolean isProvisioned) {
4496 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4497 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4498 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4499 }
4500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4501 "setProvisioningStatusForCapability");
4502 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4503 // If the current provisioning status for capability already matches isProvisioned,
4504 // do nothing.
4505 if (((provisionedBits & capability) > 0) == isProvisioned) {
4506 return;
4507 }
4508 if (isProvisioned) {
4509 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4510 } else {
4511 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4512 }
4513 }
4514
4515 /**
4516 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4517 * technology. The bitfield should mirror the bitfield defined by
4518 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4519 */
4520 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4521 String key = getMmTelProvisioningKey(subId, tech);
4522 // Default is no capabilities are provisioned.
4523 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4524 }
4525
4526 /**
4527 * Sets the MmTel capability provisioning bitfield (defined by
4528 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4529 * technology specified.
4530 *
4531 * Note: This is a synchronous command and should not be called on UI thread.
4532 */
4533 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4534 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4535 String key = getMmTelProvisioningKey(subId, tech);
4536 editor.putInt(key, newField);
4537 editor.commit();
4538 }
4539
4540 private static String getMmTelProvisioningKey(int subId, int tech) {
4541 // resulting key is provision_ims_mmtel_{subId}_{tech}
4542 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4543 }
4544
4545 /**
4546 * Query CarrierConfig to see if the specified capability requires provisioning for the
4547 * carrier associated with the subscription id.
4548 */
4549 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4550 int capability) {
4551 CarrierConfigManager configManager = new CarrierConfigManager(context);
4552 PersistableBundle c = configManager.getConfigForSubId(subId);
4553 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004554 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004555 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4556 false);
4557 boolean requireVoiceVtProvisioning = c.getBoolean(
4558 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4559
4560 // First check to make sure that the capability requires provisioning.
4561 switch (capability) {
4562 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4563 // intentional fallthrough
4564 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4565 if (requireVoiceVtProvisioning) {
4566 // Voice and Video requires provisioning
4567 return true;
4568 }
4569 break;
4570 }
4571 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4572 if (requireUtProvisioning) {
4573 // UT requires provisioning
4574 return true;
4575 }
4576 break;
4577 }
4578 }
4579 return false;
4580 }
4581
allenwtsu99c623b2020-01-03 18:24:23 +08004582 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4583 int capability) {
4584 CarrierConfigManager configManager = new CarrierConfigManager(context);
4585 PersistableBundle c = configManager.getConfigForSubId(subId);
4586
4587 boolean requireRcsProvisioning = c.getBoolean(
4588 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4589
4590 // First check to make sure that the capability requires provisioning.
4591 switch (capability) {
4592 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4593 // intentional fallthrough
4594 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4595 if (requireRcsProvisioning) {
4596 // OPTION or PRESENCE requires provisioning
4597 return true;
4598 }
4599 break;
4600 }
4601 }
4602 return false;
4603 }
4604
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004605 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004606 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004607 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4608 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4609 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004610 enforceReadPrivilegedPermission("getImsProvisioningInt");
4611 final long identity = Binder.clearCallingIdentity();
4612 try {
4613 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004614 int slotId = getSlotIndex(subId);
4615 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4616 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4617 + subId + "' for key:" + key);
4618 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4619 }
calvinpan9cfff472021-02-08 19:59:36 +08004620 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004621 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004622 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4623 + subId + "' for key:" + key);
4624 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004625 } finally {
4626 Binder.restoreCallingIdentity(identity);
4627 }
4628 }
4629
4630 @Override
4631 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4633 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4634 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004635 enforceReadPrivilegedPermission("getImsProvisioningString");
4636 final long identity = Binder.clearCallingIdentity();
4637 try {
4638 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004639 int slotId = getSlotIndex(subId);
4640 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4641 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4642 + subId + "' for key:" + key);
4643 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4644 }
calvinpan9cfff472021-02-08 19:59:36 +08004645 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004646 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004647 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4648 + subId + "' for key:" + key);
4649 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004650 } finally {
4651 Binder.restoreCallingIdentity(identity);
4652 }
4653 }
4654
4655 @Override
4656 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4658 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4659 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4661 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004662 final long identity = Binder.clearCallingIdentity();
4663 try {
4664 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665 int slotId = getSlotIndex(subId);
4666 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4667 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4668 + subId + "' for key:" + key);
4669 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4670 }
calvinpan9cfff472021-02-08 19:59:36 +08004671 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4672 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004673 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004674 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004675 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004676 } finally {
4677 Binder.restoreCallingIdentity(identity);
4678 }
4679 }
4680
4681 @Override
4682 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004683 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4684 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4685 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4687 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004688 final long identity = Binder.clearCallingIdentity();
4689 try {
4690 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004691 int slotId = getSlotIndex(subId);
4692 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4693 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4694 + subId + "' for key:" + key);
4695 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4696 }
calvinpan9cfff472021-02-08 19:59:36 +08004697 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4698 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004699 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004700 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004701 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004702 } finally {
4703 Binder.restoreCallingIdentity(identity);
4704 }
4705 }
4706
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004707 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004708 int slotId = SubscriptionManager.getSlotIndex(subId);
4709 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004710 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4711 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004712 }
4713 return slotId;
4714 }
4715
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004716 private int getSlotIndex(int subId) {
4717 int slotId = SubscriptionManager.getSlotIndex(subId);
4718 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4719 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4720 }
4721 return slotId;
4722 }
4723
Wink Saville36469e72014-06-11 15:17:00 -07004724 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004725 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004726 */
4727 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004728 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4729 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004730 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004731 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004732 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004733 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004734 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004735 mApp, subId, callingPackage, callingFeatureId,
4736 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004737 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4738 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740 final long identity = Binder.clearCallingIdentity();
4741 try {
4742 final Phone phone = getPhone(subId);
4743 if (phone != null) {
4744 return phone.getServiceState().getDataNetworkType();
4745 } else {
4746 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4747 }
4748 } finally {
4749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004751 }
4752
4753 /**
4754 * Returns the data network type
4755 */
4756 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004757 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004758 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4759 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004760 }
4761
4762 /**
4763 * Returns the data network type for a subId
4764 */
4765 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004766 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4767 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004769 mApp, subId, callingPackage, callingFeatureId,
4770 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004771 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4772 }
4773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 final Phone phone = getPhone(subId);
4777 if (phone != null) {
4778 return phone.getServiceState().getDataNetworkType();
4779 } else {
4780 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4781 }
4782 } finally {
4783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004785 }
4786
4787 /**
Wink Saville36469e72014-06-11 15:17:00 -07004788 * Returns the Voice network type for a subId
4789 */
4790 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004791 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4792 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004794 mApp, subId, callingPackage, callingFeatureId,
4795 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004796 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4797 }
4798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 final long identity = Binder.clearCallingIdentity();
4800 try {
4801 final Phone phone = getPhone(subId);
4802 if (phone != null) {
4803 return phone.getServiceState().getVoiceNetworkType();
4804 } else {
4805 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4806 }
4807 } finally {
4808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004810 }
4811
4812 /**
4813 * @return true if a ICC card is present
4814 */
4815 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004816 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004817 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4818 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004819 }
4820
4821 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004822 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004823 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004824 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004825 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004826 final long identity = Binder.clearCallingIdentity();
4827 try {
4828 final Phone phone = PhoneFactory.getPhone(slotIndex);
4829 if (phone != null) {
4830 return phone.getIccCard().hasIccCard();
4831 } else {
4832 return false;
4833 }
4834 } finally {
4835 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004837 }
4838
4839 /**
4840 * Return if the current radio is LTE on CDMA. This
4841 * is a tri-state return value as for a period of time
4842 * the mode may be unknown.
4843 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004844 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004845 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004846 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004847 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004848 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004849 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4850 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4851 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004852 }
4853
Sanket Padawe356d7632015-06-22 14:03:32 -07004854 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004855 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4856 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004857 try {
4858 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4859 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004860 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4861 }
4862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004863 final long identity = Binder.clearCallingIdentity();
4864 try {
4865 final Phone phone = getPhone(subId);
4866 if (phone == null) {
4867 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4868 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004869 return TelephonyProperties.lte_on_cdma_device()
4870 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 }
4872 } finally {
4873 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004874 }
Wink Saville36469e72014-06-11 15:17:00 -07004875 }
4876
Wink Saville36469e72014-06-11 15:17:00 -07004877 /**
4878 * {@hide}
4879 * Returns Default subId, 0 in the case of single standby.
4880 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004881 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004882 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004883 }
4884
Shishir Agrawala9f32182016-04-12 12:00:16 -07004885 private int getSlotForDefaultSubscription() {
4886 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4887 }
4888
Wink Savilleb564aae2014-10-23 10:18:09 -07004889 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004890 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004891 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004892
Pengquan Menge92a50d2018-09-21 15:54:48 -07004893 private boolean isActiveSubscription(int subId) {
4894 return mSubscriptionController.isActiveSubId(subId);
4895 }
4896
Ihab Awadf2177b72013-11-25 13:33:23 -08004897 /**
4898 * @see android.telephony.TelephonyManager.WifiCallingChoices
4899 */
4900 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004901 final long identity = Binder.clearCallingIdentity();
4902 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004903 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4905 getWhenToMakeWifiCallsDefaultPreference());
4906 } finally {
4907 Binder.restoreCallingIdentity(identity);
4908 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004909 }
4910
4911 /**
4912 * @see android.telephony.TelephonyManager.WifiCallingChoices
4913 */
4914 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004915 final long identity = Binder.clearCallingIdentity();
4916 try {
4917 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004918 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004919 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004923 }
4924
Sailesh Nepald1e68152013-12-12 19:08:02 -08004925 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004926 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004927 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004928 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004929
Jordan Liu4c733742019-02-28 12:03:40 -08004930 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4931 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4932 if (phoneId == -1) {
4933 throw new IllegalArgumentException("Given slot index: " + slotIndex
4934 + " does not correspond to an active phone");
4935 }
4936 return PhoneFactory.getPhone(phoneId);
4937 }
4938
Shishir Agrawal566b7612013-10-28 14:41:00 -07004939 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004940 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4941 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4943 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004945 if (DBG) {
4946 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4947 }
4948 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4949 p2);
4950 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004951
Jordan Liu4c733742019-02-28 12:03:40 -08004952
4953 @Override
4954 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4955 int slotIndex, String callingPackage, String aid, int p2) {
4956 enforceModifyPermission();
4957 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4958 if (DBG) {
4959 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4960 }
4961 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4962 callingPackage, aid, p2);
4963 }
4964
4965 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4966 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 final long identity = Binder.clearCallingIdentity();
4968 try {
4969 if (TextUtils.equals(ISDR_AID, aid)) {
4970 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004971 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4972 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 if (bestComponent == null
4974 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4975 loge("The calling package is not allowed to access ISD-R.");
4976 throw new SecurityException(
4977 "The calling package is not allowed to access ISD-R.");
4978 }
Derek Tan740e1672017-06-27 14:56:27 -07004979 }
Derek Tan740e1672017-06-27 14:56:27 -07004980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004981 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004982 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4983 null /* workSource */);
4984 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 return response;
4986 } finally {
4987 Binder.restoreCallingIdentity(identity);
4988 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004989 }
4990
4991 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004992 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4994 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004995 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4996 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4997 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004998
Jordan Liu4c733742019-02-28 12:03:40 -08004999 @Override
5000 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5001 enforceModifyPermission();
5002 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5003 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5004 channel);
5005 }
5006
5007 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008 final long identity = Binder.clearCallingIdentity();
5009 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 if (channel < 0) {
5011 return false;
5012 }
Jordan Liu4c733742019-02-28 12:03:40 -08005013 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5014 null /* workSource */);
5015 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 return success;
5017 } finally {
5018 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005019 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005020 }
5021
5022 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005023 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005024 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5026 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005027 if (DBG) {
5028 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5029 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5030 + p3 + " data=" + data);
5031 }
5032 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5033 command, p1, p2, p3, data);
5034 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005035
Jordan Liu4c733742019-02-28 12:03:40 -08005036 @Override
5037 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5038 int command, int p1, int p2, int p3, String data) {
5039 enforceModifyPermission();
5040 if (DBG) {
5041 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5042 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5043 + p3 + " data=" + data);
5044 }
5045 return iccTransmitApduLogicalChannelWithPermission(
5046 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5047 data);
5048 }
5049
5050 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5051 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 final long identity = Binder.clearCallingIdentity();
5053 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005054 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005055 return "";
5056 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005057
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005059 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5060 null /* workSource */);
5061 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 // Append the returned status code to the end of the response payload.
5064 String s = Integer.toHexString(
5065 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5066 if (response.payload != null) {
5067 s = IccUtils.bytesToHexString(response.payload) + s;
5068 }
5069 return s;
5070 } finally {
5071 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005072 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005073 }
Jake Hambye994d462014-02-03 13:10:13 -08005074
Evan Charltonc66da362014-05-16 14:06:40 -07005075 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005076 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5077 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5079 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005081 if (DBG) {
5082 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5083 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5084 }
5085 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5086 cla, command, p1, p2, p3, data);
5087 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005088
Jordan Liu4c733742019-02-28 12:03:40 -08005089 @Override
5090 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5091 int command, int p1, int p2, int p3, String data) {
5092 enforceModifyPermission();
5093 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5094 if (DBG) {
5095 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5096 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5097 + " data=" + data);
5098 }
5099
5100 return iccTransmitApduBasicChannelWithPermission(
5101 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5102 p2, p3, data);
5103 }
5104
5105 // open APDU basic channel assuming the caller has sufficient permissions
5106 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5107 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 final long identity = Binder.clearCallingIdentity();
5109 try {
5110 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5111 && TextUtils.equals(ISDR_AID, data)) {
5112 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005113 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5114 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 if (bestComponent == null
5116 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5117 loge("The calling package is not allowed to select ISD-R.");
5118 throw new SecurityException(
5119 "The calling package is not allowed to select ISD-R.");
5120 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005121 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005124 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5125 null /* workSource */);
5126 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 // Append the returned status code to the end of the response payload.
5129 String s = Integer.toHexString(
5130 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5131 if (response.payload != null) {
5132 s = IccUtils.bytesToHexString(response.payload) + s;
5133 }
5134 return s;
5135 } finally {
5136 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005137 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005138 }
5139
5140 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005141 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005142 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5144 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146 final long identity = Binder.clearCallingIdentity();
5147 try {
5148 if (DBG) {
5149 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5150 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5151 }
5152
5153 IccIoResult response =
5154 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5155 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5156 subId);
5157
5158 if (DBG) {
5159 log("Exchange SIM_IO [R]" + response);
5160 }
5161
5162 byte[] result = null;
5163 int length = 2;
5164 if (response.payload != null) {
5165 length = 2 + response.payload.length;
5166 result = new byte[length];
5167 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5168 } else {
5169 result = new byte[length];
5170 }
5171
5172 result[length - 1] = (byte) response.sw2;
5173 result[length - 2] = (byte) response.sw1;
5174 return result;
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005177 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005178 }
5179
Nathan Haroldb3014052017-01-25 15:57:32 -08005180 /**
5181 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5182 * on a particular subscription
5183 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005184 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5185 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005186 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005187 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005188 return null;
5189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190
5191 final long identity = Binder.clearCallingIdentity();
5192 try {
5193 if (appType != TelephonyManager.APPTYPE_USIM
5194 && appType != TelephonyManager.APPTYPE_SIM) {
5195 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5196 return null;
5197 }
5198 Object response = sendRequest(
5199 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5200 if (response instanceof String[]) {
5201 return (String[]) response;
5202 }
yincheng zhaod698b842019-09-06 17:06:54 -07005203 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005205 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 } finally {
5207 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005208 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005209 }
5210
yincheng zhaod698b842019-09-06 17:06:54 -07005211 /**
5212 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5213 * subscription.
5214 *
5215 * @param subId the id of the subscription.
5216 * @param appType the uicc app type, must be USIM or SIM.
5217 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5218 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005219 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005220 * @return number of fplmns that is successfully written to the SIM.
5221 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005222 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5223 String callingFeatureId) {
5224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5225 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005226 if (DBG) logv("no permissions for setForbiddenplmns");
5227 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5228 }
5229 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5230 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5231 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5232 }
5233 if (fplmns == null) {
5234 throw new IllegalArgumentException("Fplmn List provided is null");
5235 }
5236 for (String fplmn : fplmns) {
5237 if (!CellIdentity.isValidPlmn(fplmn)) {
5238 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5239 }
5240 }
5241 final long identity = Binder.clearCallingIdentity();
5242 try {
5243 Object response = sendRequest(
5244 CMD_SET_FORBIDDEN_PLMNS,
5245 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5246 subId);
5247 return (int) response;
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
5251 }
5252
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005253 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005254 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5256 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 final long identity = Binder.clearCallingIdentity();
5259 try {
5260 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5261 if (response.payload == null) {
5262 return "";
5263 }
Evan Charltonc66da362014-05-16 14:06:40 -07005264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265 // Append the returned status code to the end of the response payload.
5266 String s = Integer.toHexString(
5267 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5268 s = IccUtils.bytesToHexString(response.payload) + s;
5269 return s;
5270 } finally {
5271 Binder.restoreCallingIdentity(identity);
5272 }
Evan Charltonc66da362014-05-16 14:06:40 -07005273 }
5274
Jake Hambye994d462014-02-03 13:10:13 -08005275 /**
5276 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5277 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5278 *
5279 * @param itemID the ID of the item to read
5280 * @return the NV item as a String, or null on error.
5281 */
5282 @Override
5283 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005284 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5286 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287
5288 final long identity = Binder.clearCallingIdentity();
5289 try {
5290 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005291 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5293 return value;
5294 } finally {
5295 Binder.restoreCallingIdentity(identity);
5296 }
Jake Hambye994d462014-02-03 13:10:13 -08005297 }
5298
5299 /**
5300 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5301 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5302 *
5303 * @param itemID the ID of the item to read
5304 * @param itemValue the value to write, as a String
5305 * @return true on success; false on any failure
5306 */
5307 @Override
5308 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5311 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312
5313 final long identity = Binder.clearCallingIdentity();
5314 try {
5315 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5316 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005317 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005318 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5319 return success;
5320 } finally {
5321 Binder.restoreCallingIdentity(identity);
5322 }
Jake Hambye994d462014-02-03 13:10:13 -08005323 }
5324
5325 /**
5326 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5327 * Used for device configuration by some CDMA operators.
5328 *
5329 * @param preferredRoamingList byte array containing the new PRL
5330 * @return true on success; false on any failure
5331 */
5332 @Override
5333 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5335 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336
5337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5340 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5341 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5342 return success;
5343 } finally {
5344 Binder.restoreCallingIdentity(identity);
5345 }
Jake Hambye994d462014-02-03 13:10:13 -08005346 }
5347
5348 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005349 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005350 * Used for device configuration by some CDMA operators.
5351 *
chen xu6dac5ab2018-10-26 17:39:23 -07005352 * @param slotIndex - device slot.
5353 *
Jake Hambye994d462014-02-03 13:10:13 -08005354 * @return true on success; false on any failure
5355 */
5356 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005357 public boolean resetModemConfig(int slotIndex) {
5358 Phone phone = PhoneFactory.getPhone(slotIndex);
5359 if (phone != null) {
5360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5361 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362
chen xu6dac5ab2018-10-26 17:39:23 -07005363 final long identity = Binder.clearCallingIdentity();
5364 try {
5365 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5366 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5367 return success;
5368 } finally {
5369 Binder.restoreCallingIdentity(identity);
5370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 }
chen xu6dac5ab2018-10-26 17:39:23 -07005372 return false;
5373 }
5374
5375 /**
5376 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5377 *
5378 * @param slotIndex - device slot.
5379 *
5380 * @return true on success; false on any failure
5381 */
5382 @Override
5383 public boolean rebootModem(int slotIndex) {
5384 Phone phone = PhoneFactory.getPhone(slotIndex);
5385 if (phone != null) {
5386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5387 mApp, phone.getSubId(), "rebootModem");
5388
5389 final long identity = Binder.clearCallingIdentity();
5390 try {
5391 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5392 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5393 return success;
5394 } finally {
5395 Binder.restoreCallingIdentity(identity);
5396 }
5397 }
5398 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005399 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005400
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005401 public String[] getPcscfAddress(String apnType, String callingPackage,
5402 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005403 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5405 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005406 return new String[0];
5407 }
5408
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409 final long identity = Binder.clearCallingIdentity();
5410 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005411 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412 } finally {
5413 Binder.restoreCallingIdentity(identity);
5414 }
Wink Saville36469e72014-06-11 15:17:00 -07005415 }
5416
Brad Ebinger51f743a2017-01-23 13:50:20 -08005417 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005418 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5419 * {@link #disableIms(int)}.
5420 * @param slotIndex device slot.
5421 */
5422 public void resetIms(int slotIndex) {
5423 enforceModifyPermission();
5424
5425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 if (mImsResolver == null) {
5428 // may happen if the does not support IMS.
5429 return;
5430 }
5431 mImsResolver.disableIms(slotIndex);
5432 mImsResolver.enableIms(slotIndex);
5433 } finally {
5434 Binder.restoreCallingIdentity(identity);
5435 }
5436 }
5437
5438 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005439 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5440 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005441 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005442 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005443 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444
5445 final long identity = Binder.clearCallingIdentity();
5446 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005447 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005448 // may happen if the device does not support IMS.
5449 return;
5450 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005451 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452 } finally {
5453 Binder.restoreCallingIdentity(identity);
5454 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005455 }
5456
5457 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005458 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5459 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005460 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005461 public void disableIms(int slotId) {
5462 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005463
5464 final long identity = Binder.clearCallingIdentity();
5465 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005466 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005467 // may happen if the device does not support IMS.
5468 return;
5469 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005470 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005474 }
5475
5476 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005477 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5478 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005479 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005480 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005481 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483
5484 final long identity = Binder.clearCallingIdentity();
5485 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005486 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005487 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5488 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005489 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005490 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 } finally {
5492 Binder.restoreCallingIdentity(identity);
5493 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005494 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005495 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005496 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5497 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005498 @Override
5499 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005500 enforceModifyPermission();
5501
5502 final long identity = Binder.clearCallingIdentity();
5503 try {
5504 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005505 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005506 } finally {
5507 Binder.restoreCallingIdentity(identity);
5508 }
5509 }
5510
5511 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005512 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005513 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005514 */
5515 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5516 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517
5518 final long identity = Binder.clearCallingIdentity();
5519 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005520 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005521 // may happen if the device does not support IMS.
5522 return null;
5523 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005524 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005528 }
5529
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005530 /**
5531 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005532 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005533 */
5534 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5535 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005539 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005540 // may happen if the device does not support IMS.
5541 return null;
5542 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005543 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005547 }
5548
Brad Ebinger884c07b2018-02-15 16:17:40 -08005549 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005550 * Sets the ImsService Package Name that Telephony will bind to.
5551 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005552 * @param slotIndex the slot ID that the ImsService should bind for.
5553 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005554 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005555 * @param featureTypes An integer array of feature types associated with a packageName.
5556 * @param packageName The name of the package that the current configuration will be replaced
5557 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005558 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005559 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005560 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5561 int[] featureTypes, String packageName) {
5562 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5563 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5565 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005566 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005567
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005568 final long identity = Binder.clearCallingIdentity();
5569 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005570 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005571 // may happen if the device does not support IMS.
5572 return false;
5573 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005574 Map<Integer, String> featureConfig = new HashMap<>();
5575 for (int featureType : featureTypes) {
5576 featureConfig.put(featureType, packageName);
5577 }
5578 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5579 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 } finally {
5581 Binder.restoreCallingIdentity(identity);
5582 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005583 }
5584
5585 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005586 * Clears any carrier ImsService overrides for the slot index specified that were previously
5587 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5588 *
5589 * This should only be used for testing.
5590 *
5591 * @param slotIndex the slot ID that the ImsService should bind for.
5592 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5593 */
5594 @Override
5595 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5596 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5597 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5598 "clearCarrierImsServiceOverride");
5599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5600 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5601 "clearCarrierImsServiceOverride");
5602
5603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 if (mImsResolver == null) {
5606 // may happen if the device does not support IMS.
5607 return false;
5608 }
5609 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5610 } finally {
5611 Binder.restoreCallingIdentity(identity);
5612 }
5613 }
5614
5615 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005616 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005617 *
5618 * @param slotId The slot that the ImsService is associated with.
5619 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5620 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005621 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005622 * @return the package name of the ImsService configuration.
5623 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005624 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5625 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005626 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005627 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005628 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005629 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5630 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632 final long identity = Binder.clearCallingIdentity();
5633 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005634 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005635 // may happen if the device does not support IMS.
5636 return "";
5637 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005638 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005639 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5640 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005644 }
5645
Brad Ebinger77b832e2019-10-17 17:03:22 -07005646 /**
5647 * Get the MmTelFeature state associated with the requested subscription id.
5648 * @param subId The subscription that the MmTelFeature is associated with.
5649 * @param callback A callback with an integer containing the
5650 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5651 */
5652 @Override
5653 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5654 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5655 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5656 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5657 "IMS not available on device.");
5658 }
5659 final long token = Binder.clearCallingIdentity();
5660 try {
5661 int slotId = getSlotIndex(subId);
5662 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5663 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5664 + subId + "'");
5665 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5666 }
5667 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5668 try {
5669 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5670 } catch (RemoteException e) {
5671 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5672 + "Ignore");
5673 }
5674 });
5675 } finally {
5676 Binder.restoreCallingIdentity(token);
5677 }
5678 }
5679
Daniel Brightbb5840b2021-01-12 15:48:18 -08005680 /**
5681 * Sets the ims registration state on all valid {@link Phone}s.
5682 */
5683 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685
5686 final long identity = Binder.clearCallingIdentity();
5687 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005688 // NOTE: Before S, this method only set the default phone.
5689 for (final Phone phone : PhoneFactory.getPhones()) {
5690 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5691 phone.setImsRegistrationState(registered);
5692 }
5693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 } finally {
5695 Binder.restoreCallingIdentity(identity);
5696 }
Wink Saville36469e72014-06-11 15:17:00 -07005697 }
5698
5699 /**
Stuart Scott54788802015-03-30 13:18:01 -07005700 * Set the network selection mode to automatic.
5701 *
5702 */
5703 @Override
5704 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5706 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707
5708 final long identity = Binder.clearCallingIdentity();
5709 try {
shilufc958392020-01-20 11:36:01 -08005710 if (!isActiveSubscription(subId)) {
5711 return;
5712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005714 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5715 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
Stuart Scott54788802015-03-30 13:18:01 -07005719 }
5720
Jack Yud10cdd42020-09-28 20:28:01 -07005721 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005722 * Ask the radio to connect to the input network and change selection mode to manual.
5723 *
5724 * @param subId the id of the subscription.
5725 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5726 * the operator to attach to.
5727 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5728 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5729 * normal network selection next time.
5730 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005731 */
5732 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005733 public boolean setNetworkSelectionModeManual(
5734 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5736 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005737
5738 if (!isActiveSubscription(subId)) {
5739 return false;
5740 }
5741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 final long identity = Binder.clearCallingIdentity();
5743 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005744 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005746 if (DBG) {
5747 log("setNetworkSelectionModeManual: subId: " + subId
5748 + " operator: " + operatorInfo);
5749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5751 } finally {
5752 Binder.restoreCallingIdentity(identity);
5753 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005754 }
shilu84f6e8b2019-12-19 13:58:01 -08005755 /**
5756 * Get the manual network selection
5757 *
5758 * @param subId the id of the subscription.
5759 *
5760 * @return the previously saved user selected PLMN
5761 */
5762 @Override
5763 public String getManualNetworkSelectionPlmn(int subId) {
5764 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005765 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005766 mApp, subId, "getManualNetworkSelectionPlmn");
5767
5768 final long identity = Binder.clearCallingIdentity();
5769 try {
5770 if (!isActiveSubscription(subId)) {
5771 return "";
5772 }
5773
5774 final Phone phone = getPhone(subId);
5775 if (phone == null) {
5776 return "";
5777 }
5778 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5779 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5780 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5781 } finally {
5782 Binder.restoreCallingIdentity(identity);
5783 }
5784 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005785
5786 /**
5787 * Scans for available networks.
5788 */
5789 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005790 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5791 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5793 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005794 LocationAccessPolicy.LocationPermissionResult locationResult =
5795 LocationAccessPolicy.checkLocationPermission(mApp,
5796 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5797 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005798 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005799 .setCallingPid(Binder.getCallingPid())
5800 .setCallingUid(Binder.getCallingUid())
5801 .setMethod("getCellNetworkScanResults")
5802 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07005803 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5804 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005805 .build());
5806 switch (locationResult) {
5807 case DENIED_HARD:
5808 throw new SecurityException("Not allowed to access scan results -- location");
5809 case DENIED_SOFT:
5810 return null;
5811 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812
Pengquan Menga1bb6272018-09-06 09:59:22 -07005813 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 try {
5815 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005816 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 } finally {
5819 Binder.restoreCallingIdentity(identity);
5820 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005821 }
5822
5823 /**
sqian80370722020-01-29 15:02:51 -08005824 * Get the call forwarding info, given the call forwarding reason.
5825 */
5826 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005827 public void getCallForwarding(int subId, int callForwardingReason,
5828 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005829 enforceReadPrivilegedPermission("getCallForwarding");
5830 long identity = Binder.clearCallingIdentity();
5831 try {
5832 if (DBG) {
5833 log("getCallForwarding: subId " + subId
5834 + " callForwardingReason" + callForwardingReason);
5835 }
Hall Liua1acea22020-09-18 19:04:59 -07005836
5837 Phone phone = getPhone(subId);
5838 if (phone == null) {
5839 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005840 callback.onError(
5841 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005842 } catch (RemoteException e) {
5843 // ignore
5844 }
5845 return;
5846 }
5847
5848 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5849 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5850 @Override
5851 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5852 try {
5853 callback.onCallForwardingInfoAvailable(info);
5854 } catch (RemoteException e) {
5855 // ignore
5856 }
5857 }
5858
5859 @Override
5860 public void onError(int error) {
5861 try {
5862 callback.onError(error);
5863 } catch (RemoteException e) {
5864 // ignore
5865 }
5866 }
5867 });
5868 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
5872 }
5873
5874 /**
5875 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5876 * reason, the number to forward, and the timeout before the forwarding is attempted.
5877 */
5878 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005879 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5880 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005881 enforceModifyPermission();
5882 long identity = Binder.clearCallingIdentity();
5883 try {
5884 if (DBG) {
5885 log("setCallForwarding: subId " + subId
5886 + " callForwardingInfo" + callForwardingInfo);
5887 }
Hall Liua1acea22020-09-18 19:04:59 -07005888
5889 Phone phone = getPhone(subId);
5890 if (phone == null) {
5891 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005892 callback.accept(
5893 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005894 } catch (RemoteException e) {
5895 // ignore
5896 }
5897 return;
5898 }
5899
5900 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5901 FunctionalUtils.ignoreRemoteException(callback::accept));
5902
5903 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005904 } finally {
5905 Binder.restoreCallingIdentity(identity);
5906 }
5907 }
5908
5909 /**
Hall Liua1acea22020-09-18 19:04:59 -07005910 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005911 */
5912 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005913 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWangc63cf522021-03-31 22:08:45 +08005914 enforceReadPrivilegedPermission("getCallWaitingStatus");
sqian80370722020-01-29 15:02:51 -08005915 long identity = Binder.clearCallingIdentity();
5916 try {
Hall Liua1acea22020-09-18 19:04:59 -07005917 Phone phone = getPhone(subId);
5918 if (phone == null) {
5919 try {
5920 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5921 } catch (RemoteException e) {
5922 // ignore
5923 }
5924 return;
5925 }
SongFerngWangc63cf522021-03-31 22:08:45 +08005926 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5927 PersistableBundle c = configManager.getConfigForSubId(subId);
5928 boolean requireUssd = c.getBoolean(
5929 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005930
sqian80370722020-01-29 15:02:51 -08005931 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWangc63cf522021-03-31 22:08:45 +08005932 if (requireUssd) {
5933 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5934 getSubscriptionCarrierId(subId));
5935 String newUssdCommand = "";
5936 try {
5937 newUssdCommand = carrierXmlParser.getFeature(
5938 CarrierXmlParser.FEATURE_CALL_WAITING)
5939 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
5940 } catch (NullPointerException e) {
5941 loge("Failed to generate USSD number" + e);
5942 }
5943 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5944 mMainThreadHandler, callback, carrierXmlParser,
5945 CarrierXmlParser.SsEntry.SSAction.QUERY);
5946 final String ussdCommand = newUssdCommand;
5947 Executors.newSingleThreadExecutor().execute(() -> {
5948 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5949 });
5950 } else {
5951 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
5952 callback::accept);
5953 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
5954 }
sqian80370722020-01-29 15:02:51 -08005955 } finally {
5956 Binder.restoreCallingIdentity(identity);
5957 }
5958 }
5959
5960 /**
Hall Liua1acea22020-09-18 19:04:59 -07005961 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005962 */
5963 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005964 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005965 enforceModifyPermission();
5966 long identity = Binder.clearCallingIdentity();
5967 try {
Hall Liua1acea22020-09-18 19:04:59 -07005968 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5969
5970 Phone phone = getPhone(subId);
5971 if (phone == null) {
5972 try {
5973 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5974 } catch (RemoteException e) {
5975 // ignore
5976 }
5977 return;
5978 }
5979
SongFerngWangc63cf522021-03-31 22:08:45 +08005980 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5981 PersistableBundle c = configManager.getConfigForSubId(subId);
5982 boolean requireUssd = c.getBoolean(
5983 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005984
SongFerngWangc63cf522021-03-31 22:08:45 +08005985 if (DBG) log("getCallWaitingStatus: subId " + subId);
5986 if (requireUssd) {
5987 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5988 getSubscriptionCarrierId(subId));
5989 CarrierXmlParser.SsEntry.SSAction ssAction =
5990 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
5991 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
5992 String newUssdCommand = "";
5993 try {
5994 newUssdCommand = carrierXmlParser.getFeature(
5995 CarrierXmlParser.FEATURE_CALL_WAITING)
5996 .makeCommand(ssAction, null);
5997 } catch (NullPointerException e) {
5998 loge("Failed to generate USSD number" + e);
5999 }
6000 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6001 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6002 final String ussdCommand = newUssdCommand;
6003 Executors.newSingleThreadExecutor().execute(() -> {
6004 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6005 });
6006 } else {
6007 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6008 FunctionalUtils.ignoreRemoteException(callback::accept));
6009
6010 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6011 }
sqian80370722020-01-29 15:02:51 -08006012 } finally {
6013 Binder.restoreCallingIdentity(identity);
6014 }
6015 }
6016
6017 /**
yinxub1bed742017-04-17 11:45:04 -07006018 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006019 *
yinxub1bed742017-04-17 11:45:04 -07006020 * @param subId id of the subscription
6021 * @param request contains the radio access networks with bands/channels to scan
6022 * @param messenger callback messenger for scan results or errors
6023 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006024 * @return the id of the requested scan which can be used to stop the scan.
6025 */
6026 @Override
6027 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006028 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6030 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006031 LocationAccessPolicy.LocationPermissionResult locationResult =
6032 LocationAccessPolicy.checkLocationPermission(mApp,
6033 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6034 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006035 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006036 .setCallingPid(Binder.getCallingPid())
6037 .setCallingUid(Binder.getCallingUid())
6038 .setMethod("requestNetworkScan")
6039 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6040 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006041 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07006042 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6043 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006044 if (e != null) {
6045 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6046 throw e;
6047 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006048 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006049 return TelephonyScanManager.INVALID_SCAN_ID;
6050 }
6051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 }
Hall Liu912dfd32019-04-25 14:02:26 -07006053 int callingUid = Binder.getCallingUid();
6054 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006055 final long identity = Binder.clearCallingIdentity();
6056 try {
6057 return mNetworkScanRequestTracker.startNetworkScan(
6058 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006059 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006060 } finally {
6061 Binder.restoreCallingIdentity(identity);
6062 }
yinxu504e1392017-04-12 16:03:22 -07006063 }
6064
Hall Liub2ac8ef2019-02-28 15:56:23 -08006065 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07006066 NetworkScanRequest request, int subId, String callingPackage) {
6067 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006068 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6069 boolean hasNetworkScanPermission =
6070 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6071 == PERMISSION_GRANTED;
6072
6073 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6074 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6075 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006076 }
6077
6078 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6079 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006080 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6081 return new SecurityException("Specific channels must not be"
6082 + " scanned without location access.");
6083 }
6084 }
6085 }
6086
Hall Liub2ac8ef2019-02-28 15:56:23 -08006087 return null;
6088 }
6089
yinxu504e1392017-04-12 16:03:22 -07006090 /**
6091 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006092 *
6093 * @param subId id of the subscription
6094 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006095 */
6096 @Override
6097 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6099 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100
Hall Liu912dfd32019-04-25 14:02:26 -07006101 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 final long identity = Binder.clearCallingIdentity();
6103 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006104 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006105 } finally {
6106 Binder.restoreCallingIdentity(identity);
6107 }
yinxu504e1392017-04-12 16:03:22 -07006108 }
6109
6110 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006111 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006112 *
SongFerngWang9e060372020-12-21 16:41:52 +08006113 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006114 */
6115 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006116 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006117 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006118 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006119 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120
6121 final long identity = Binder.clearCallingIdentity();
6122 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006123 if (DBG) log("getAllowedNetworkTypesBitmask");
6124 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6125 int networkTypesBitmask = (result != null ? result[0] : -1);
6126 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6127 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 } finally {
6129 Binder.restoreCallingIdentity(identity);
6130 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006131 }
6132
6133 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006134 * Get the allowed network types for certain reason.
6135 *
6136 * @param subId the id of the subscription.
6137 * @param reason the reason the allowed network type change is taking place
6138 * @return the allowed network types.
6139 */
6140 @Override
6141 public long getAllowedNetworkTypesForReason(int subId,
6142 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006143 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006144 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006145 final long identity = Binder.clearCallingIdentity();
6146 try {
6147 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6148 } finally {
6149 Binder.restoreCallingIdentity(identity);
6150 }
6151 }
6152
6153 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006154 * Enable/Disable E-UTRA-NR Dual Connectivity
6155 * @param subId subscription id of the sim card
6156 * @param nrDualConnectivityState expected NR dual connectivity state
6157 * This can be passed following states
6158 * <ol>
6159 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6160 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6161 * <li>Disable NR dual connectivity and force secondary cell to be released
6162 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6163 * </ol>
6164 * @return operation result.
6165 */
6166 @Override
6167 public int setNrDualConnectivityState(int subId,
6168 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6170 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006171 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006172 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6173 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6174 }
6175
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006176 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6177 final long identity = Binder.clearCallingIdentity();
6178 try {
6179 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6180 nrDualConnectivityState, subId,
6181 workSource);
6182 if (DBG) log("enableNRDualConnectivity result: " + result);
6183 return result;
6184 } finally {
6185 Binder.restoreCallingIdentity(identity);
6186 }
6187 }
6188
6189 /**
6190 * Is E-UTRA-NR Dual Connectivity enabled
6191 * @return true if dual connectivity is enabled else false
6192 */
6193 @Override
6194 public boolean isNrDualConnectivityEnabled(int subId) {
6195 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006196 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006197 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006198 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006199 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6200 return false;
6201 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006202 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6203 final long identity = Binder.clearCallingIdentity();
6204 try {
6205 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6206 null, subId, workSource);
6207 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6208 return isEnabled;
6209 } finally {
6210 Binder.restoreCallingIdentity(identity);
6211 }
6212 }
6213
6214 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006215 * Set the allowed network types of the device and
6216 * provide the reason triggering the allowed network change.
6217 *
6218 * @param subId the id of the subscription.
6219 * @param reason the reason the allowed network type change is taking place
6220 * @param allowedNetworkTypes the allowed network types.
6221 * @return true on success; false on any failure.
6222 */
6223 @Override
6224 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006225 @TelephonyManager.AllowedNetworkTypesReason int reason,
6226 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6228 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006229 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWangc2d3ccc2021-04-15 19:46:33 +08006230 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6231 return false;
6232 }
6233 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6234 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang9e060372020-12-21 16:41:52 +08006235 return false;
6236 }
6237
SongFerngWang522637d2021-03-02 22:09:29 +08006238 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6239 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6240
6241
6242 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6243 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6244 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006245 }
SongFerngWang522637d2021-03-02 22:09:29 +08006246
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006247 final long identity = Binder.clearCallingIdentity();
6248 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006249 Boolean success = (Boolean) sendRequest(
6250 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6251 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6252
6253 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6254 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006255 } finally {
6256 Binder.restoreCallingIdentity(identity);
6257 }
6258 }
6259
6260 /**
Miaoa84611c2019-03-15 09:21:10 +08006261 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006262 *
Miaoa84611c2019-03-15 09:21:10 +08006263 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006264 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006265 * @hide
6266 */
6267 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006268 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006269 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006271 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 try {
Miaoa84611c2019-03-15 09:21:10 +08006273 if (phone != null) {
6274 return phone.hasMatchedTetherApnSetting();
6275 } else {
6276 return false;
6277 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 } finally {
6279 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006280 }
Junda Liu475951f2014-11-07 16:45:03 -08006281 }
6282
6283 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006284 * Enable or disable always reporting signal strength changes from radio.
6285 *
6286 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6287 */
6288 @Override
6289 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6290 enforceModifyPermission();
6291 enforceSystemCaller();
6292
6293 final long identity = Binder.clearCallingIdentity();
6294 final Phone phone = getPhone(subId);
6295 try {
6296 if (phone != null) {
6297 if (DBG) {
6298 log("setAlwaysReportSignalStrength: subId=" + subId
6299 + " isEnable=" + isEnable);
6300 }
6301 phone.setAlwaysReportSignalStrength(isEnable);
6302 } else {
6303 loge("setAlwaysReportSignalStrength: no phone found for subId="
6304 + subId);
6305 }
6306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
6309 }
6310
6311 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006312 * Get the user enabled state of Mobile Data.
6313 *
6314 * TODO: remove and use isUserDataEnabled.
6315 * This can't be removed now because some vendor codes
6316 * calls through ITelephony directly while they should
6317 * use TelephonyManager.
6318 *
6319 * @return true on enabled
6320 */
6321 @Override
6322 public boolean getDataEnabled(int subId) {
6323 return isUserDataEnabled(subId);
6324 }
6325
6326 /**
6327 * Get whether mobile data is enabled per user setting.
6328 *
6329 * There are other factors deciding whether mobile data is actually enabled, but they are
6330 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006331 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006332 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006333 *
6334 * @return {@code true} if data is enabled else {@code false}
6335 */
6336 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006337 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006338 try {
6339 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6340 null);
6341 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6343 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006344 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345
6346 final long identity = Binder.clearCallingIdentity();
6347 try {
6348 int phoneId = mSubscriptionController.getPhoneId(subId);
6349 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6350 Phone phone = PhoneFactory.getPhone(phoneId);
6351 if (phone != null) {
6352 boolean retVal = phone.isUserDataEnabled();
6353 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6354 return retVal;
6355 } else {
6356 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6357 return false;
6358 }
6359 } finally {
6360 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006361 }
6362 }
6363
6364 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006365 * Checks if the device is capable of mobile data by considering whether whether the
6366 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6367 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006368 *
Shuo Qian985d1232020-01-08 14:30:06 -08006369 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006370 */
6371 @Override
6372 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006373 try {
6374 try {
6375 mApp.enforceCallingOrSelfPermission(
6376 android.Manifest.permission.ACCESS_NETWORK_STATE,
6377 null);
6378 } catch (Exception e) {
6379 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6380 "isDataEnabled");
6381 }
6382 } catch (Exception e) {
6383 enforceReadPrivilegedPermission("isDataEnabled");
6384 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385
6386 final long identity = Binder.clearCallingIdentity();
6387 try {
6388 int phoneId = mSubscriptionController.getPhoneId(subId);
6389 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6390 Phone phone = PhoneFactory.getPhone(phoneId);
6391 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006392 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6394 return retVal;
6395 } else {
6396 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6397 return false;
6398 }
6399 } finally {
6400 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006401 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006402 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006403
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006404 /**
6405 * Check if data is enabled for a specific reason
6406 * @param subId Subscription index
6407 * @param reason the reason the data enable change is taking place
6408 * @return {@code true} if the overall data is enabled; {@code false} if not.
6409 */
6410 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006411 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006412 @TelephonyManager.DataEnabledReason int reason) {
6413 try {
6414 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6415 null);
6416 } catch (Exception e) {
6417 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006418 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006419 }
6420
6421
6422 final long identity = Binder.clearCallingIdentity();
6423 try {
6424 int phoneId = mSubscriptionController.getPhoneId(subId);
6425 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006426 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006427 + " reason=" + reason);
6428 }
6429 Phone phone = PhoneFactory.getPhone(phoneId);
6430 if (phone != null) {
6431 boolean retVal;
6432 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6433 retVal = phone.isUserDataEnabled();
6434 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006435 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006436 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006437 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006438 return retVal;
6439 } else {
6440 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006441 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006442 + subId + " retVal=false");
6443 }
6444 return false;
6445 }
6446 } finally {
6447 Binder.restoreCallingIdentity(identity);
6448 }
6449 }
6450
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006451 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006452 Phone phone) {
Sarah Chinca45c312021-04-09 10:37:15 -07006453 if (uid == Process.PHONE_UID) {
6454 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6455 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liuce478d22020-07-13 12:13:03 -07006456 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6457 }
6458
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006459 //load access rules from carrier configs, and check those as well: b/139133814
6460 SubscriptionController subController = SubscriptionController.getInstance();
6461 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6462 || subController == null) return privilegeFromSim;
6463
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006464 PackageManager pkgMgr = phone.getContext().getPackageManager();
6465 String[] packages = pkgMgr.getPackagesForUid(uid);
6466
6467 final long identity = Binder.clearCallingIdentity();
6468 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006469 int subId = phone.getSubId();
6470 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6471 // A test override is in place for the privileges for this subId, so don't try to
6472 // read the subscription privileges.
6473 return privilegeFromSim;
6474 }
6475 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006476 SubscriptionManager subManager = (SubscriptionManager)
6477 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6478 for (String pkg : packages) {
6479 if (subManager.canManageSubscription(subInfo, pkg)) {
6480 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6481 }
6482 }
6483 return privilegeFromSim;
6484 } finally {
6485 Binder.restoreCallingIdentity(identity);
6486 }
6487 }
6488
6489 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6490 String pkgName) {
6491 //load access rules from carrier configs, and check those as well: b/139133814
6492 SubscriptionController subController = SubscriptionController.getInstance();
6493 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6494 || subController == null) return privilegeFromSim;
6495
6496 final long identity = Binder.clearCallingIdentity();
6497 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006498 int subId = phone.getSubId();
6499 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6500 // A test override is in place for the privileges for this subId, so don't try to
6501 // read the subscription privileges.
6502 return privilegeFromSim;
6503 }
6504 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006505 SubscriptionManager subManager = (SubscriptionManager)
6506 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6507 return subManager.canManageSubscription(subInfo, pkgName)
6508 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
6512 }
6513
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006514 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006515 public int getCarrierPrivilegeStatus(int subId) {
6516 final Phone phone = getPhone(subId);
6517 if (phone == null) {
6518 loge("getCarrierPrivilegeStatus: Invalid subId");
6519 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6520 }
6521 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006522 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006523 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006524 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6525 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006526
6527 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6528 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006529 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006530 }
Junda Liu29340342014-07-10 15:23:27 -07006531
6532 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006533 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006534 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006535 final Phone phone = getPhone(subId);
6536 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006537 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006538 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6539 }
6540 UiccProfile profile =
6541 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6542 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006543 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006544 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6545 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006546 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006547 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006548 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006549 }
6550
6551 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006552 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6553 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006554 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006555 }
6556
6557 int phoneId = SubscriptionManager.getPhoneId(subId);
6558 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006559 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006560 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006561 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6562 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006563 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6564 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6565 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006566 }
6567
6568 @Override
6569 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006570 if (TextUtils.isEmpty(pkgName))
6571 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006572 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6573 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6574 UiccCard card = UiccController.getInstance().getUiccCard(i);
6575 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006576 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006577 continue;
6578 }
6579
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006580 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6581 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6582 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006583 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6584 break;
6585 }
6586 }
6587
6588 return result;
Junda Liu29340342014-07-10 15:23:27 -07006589 }
Derek Tan89e89d42014-07-08 17:00:10 -07006590
6591 @Override
Junda Liue64de782015-04-16 17:19:16 -07006592 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6593 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6594 loge("phoneId " + phoneId + " is not valid.");
6595 return null;
6596 }
6597 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006598 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006599 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006600 return null ;
6601 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006602 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006603 }
6604
Amith Yamasani6e118872016-02-19 12:53:51 -08006605 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006606 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006607 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006608 List<String> privilegedPackages = new ArrayList<>();
6609 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006610 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6611 // has UICC in that slot.
6612 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006613 if (card.hasCarrierPrivilegeRules()) {
6614 if (packages == null) {
6615 // Only check packages in user 0 for now
6616 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006617 PackageManager.MATCH_DISABLED_COMPONENTS
6618 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006619 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006620 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006621 }
6622 for (int p = packages.size() - 1; p >= 0; p--) {
6623 PackageInfo pkgInfo = packages.get(p);
6624 if (pkgInfo != null && pkgInfo.packageName != null
6625 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006626 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006627 privilegedPackages.add(pkgInfo.packageName);
6628 }
6629 }
6630 }
6631 }
6632 return privilegedPackages;
6633 }
6634
chen xuf7e9fe82019-05-09 19:31:02 -07006635 @Override
6636 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006637 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6638
6639 final long identity = Binder.clearCallingIdentity();
6640
chen xuf7e9fe82019-05-09 19:31:02 -07006641 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006642 try {
6643 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6644 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6645 }
6646 } finally {
6647 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006648 }
6649 return privilegedPackages;
6650 }
6651
Wink Savilleb564aae2014-10-23 10:18:09 -07006652 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006653 final Phone phone = getPhone(subId);
6654 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006655 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006656 return null;
6657 }
6658 String iccId = card.getIccId();
6659 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006660 return null;
6661 }
6662 return iccId;
6663 }
6664
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006665 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006666 public void setCallComposerStatus(int subId, int status) {
6667 enforceModifyPermission();
6668
6669 final long identity = Binder.clearCallingIdentity();
6670 try {
6671 Phone phone = getPhone(subId);
6672 if (phone != null) {
6673 Phone defaultPhone = phone.getImsPhone();
6674 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6675 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6676 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006677 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6678 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006679 }
6680 }
Shuo Qiand8782462020-12-22 19:10:14 -08006681 } catch (ImsException e) {
6682 throw new ServiceSpecificException(e.getCode());
6683 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006684 Binder.restoreCallingIdentity(identity);
6685 }
6686 }
6687
6688 @Override
6689 public int getCallComposerStatus(int subId) {
6690 enforceReadPrivilegedPermission("getCallComposerStatus");
6691
6692 final long identity = Binder.clearCallingIdentity();
6693 try {
6694 Phone phone = getPhone(subId);
6695 if (phone != null) {
6696 Phone defaultPhone = phone.getImsPhone();
6697 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6698 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6699 return imsPhone.getCallComposerStatus();
6700 }
6701 }
6702 } finally {
6703 Binder.restoreCallingIdentity(identity);
6704 }
6705 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6706 }
6707
6708 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006709 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6710 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006711 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006712 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 final long identity = Binder.clearCallingIdentity();
6715 try {
6716 final String iccId = getIccId(subId);
6717 final Phone phone = getPhone(subId);
6718 if (phone == null) {
6719 return false;
6720 }
6721 final String subscriberId = phone.getSubscriberId();
6722
6723 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006724 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 + subscriberId + " to " + number);
6726 }
6727
6728 if (TextUtils.isEmpty(iccId)) {
6729 return false;
6730 }
6731
6732 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6733
6734 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6735 if (alphaTag == null) {
6736 editor.remove(alphaTagPrefKey);
6737 } else {
6738 editor.putString(alphaTagPrefKey, alphaTag);
6739 }
6740
6741 // Record both the line number and IMSI for this ICCID, since we need to
6742 // track all merged IMSIs based on line number
6743 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6744 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6745 if (number == null) {
6746 editor.remove(numberPrefKey);
6747 editor.remove(subscriberPrefKey);
6748 } else {
6749 editor.putString(numberPrefKey, number);
6750 editor.putString(subscriberPrefKey, subscriberId);
6751 }
6752
6753 editor.commit();
6754 return true;
6755 } finally {
6756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006757 }
Derek Tan7226c842014-07-02 17:42:23 -07006758 }
6759
6760 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006761 public String getLine1NumberForDisplay(int subId, String callingPackage,
6762 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006763 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006765 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006766 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006767 return null;
6768 }
Derek Tan97ebb422014-09-05 16:55:38 -07006769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770 final long identity = Binder.clearCallingIdentity();
6771 try {
6772 String iccId = getIccId(subId);
6773 if (iccId != null) {
6774 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6775 if (DBG_MERGE) {
6776 log("getLine1NumberForDisplay returning "
6777 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6778 }
6779 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6782 return null;
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006785 }
Derek Tan7226c842014-07-02 17:42:23 -07006786 }
6787
6788 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006789 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6790 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006791 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006792 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006793 return null;
6794 }
Derek Tan97ebb422014-09-05 16:55:38 -07006795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 final long identity = Binder.clearCallingIdentity();
6797 try {
6798 String iccId = getIccId(subId);
6799 if (iccId != null) {
6800 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6801 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6802 }
6803 return null;
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006806 }
Derek Tan7226c842014-07-02 17:42:23 -07006807 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006808
6809 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006810 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6811 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006812 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6813 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006815 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006816 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006817 return null;
6818 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006819
Jordan Liub49b04b2019-05-06 14:45:15 -07006820 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6821 // the process, where TelephonyManager was instantiated.
6822 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006823 final long identity = Binder.clearCallingIdentity();
6824 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006825 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826 final TelephonyManager tele = TelephonyManager.from(context);
6827 final SubscriptionManager sub = SubscriptionManager.from(context);
6828
6829 // Figure out what subscribers are currently active
6830 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831
Jordan Liub49b04b2019-05-06 14:45:15 -07006832 // Only consider subs which match the current subId
6833 // This logic can be simplified. See b/131189269 for progress.
6834 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006835 activeSubscriberIds.add(tele.getSubscriberId(subId));
6836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006837
6838 // First pass, find a number override for an active subscriber
6839 String mergeNumber = null;
6840 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6841 for (String key : prefs.keySet()) {
6842 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6843 final String subscriberId = (String) prefs.get(key);
6844 if (activeSubscriberIds.contains(subscriberId)) {
6845 final String iccId = key.substring(
6846 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6847 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6848 mergeNumber = (String) prefs.get(numberKey);
6849 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006850 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851 + " for active subscriber " + subscriberId);
6852 }
6853 if (!TextUtils.isEmpty(mergeNumber)) {
6854 break;
6855 }
6856 }
6857 }
6858 }
6859
6860 // Shortcut when no active merged subscribers
6861 if (TextUtils.isEmpty(mergeNumber)) {
6862 return null;
6863 }
6864
6865 // Second pass, find all subscribers under that line override
6866 final ArraySet<String> result = new ArraySet<>();
6867 for (String key : prefs.keySet()) {
6868 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6869 final String number = (String) prefs.get(key);
6870 if (mergeNumber.equals(number)) {
6871 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6872 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6873 final String subscriberId = (String) prefs.get(subscriberKey);
6874 if (!TextUtils.isEmpty(subscriberId)) {
6875 result.add(subscriberId);
6876 }
6877 }
6878 }
6879 }
6880
6881 final String[] resultArray = result.toArray(new String[result.size()]);
6882 Arrays.sort(resultArray);
6883 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006884 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6886 }
6887 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006888 } finally {
6889 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006890 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006891 }
6892
6893 @Override
zoey chen38003472019-12-13 17:16:31 +08006894 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6895 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006896
6897 final long identity = Binder.clearCallingIdentity();
6898 try {
6899 final TelephonyManager telephonyManager = mApp.getSystemService(
6900 TelephonyManager.class);
6901 String subscriberId = telephonyManager.getSubscriberId(subId);
6902 if (subscriberId == null) {
6903 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006904 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006905 + subId);
6906 }
6907 return null;
6908 }
6909
6910 final SubscriptionInfo info = SubscriptionController.getInstance()
6911 .getSubscriptionInfo(subId);
6912 final ParcelUuid groupUuid = info.getGroupUuid();
6913 // If it doesn't belong to any group, return just subscriberId of itself.
6914 if (groupUuid == null) {
6915 return new String[]{subscriberId};
6916 }
6917
6918 // Get all subscriberIds from the group.
6919 final List<String> mergedSubscriberIds = new ArrayList<>();
6920 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006921 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006922 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006923 for (SubscriptionInfo subInfo : groupInfos) {
6924 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6925 if (subscriberId != null) {
6926 mergedSubscriberIds.add(subscriberId);
6927 }
6928 }
6929
6930 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6931 } finally {
6932 Binder.restoreCallingIdentity(identity);
6933
6934 }
6935 }
6936
6937 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006938 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006939 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006940 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006941
6942 final long identity = Binder.clearCallingIdentity();
6943 try {
6944 final Phone phone = getPhone(subId);
6945 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6946 } finally {
6947 Binder.restoreCallingIdentity(identity);
6948 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006949 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006950
6951 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006952 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006953 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6954 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006955 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6956 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006957
6958 final long identity = Binder.clearCallingIdentity();
6959 try {
6960 final Phone phone = getPhone(subId);
6961 if (phone == null) {
6962 return false;
6963 }
6964 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6965 cdmaNonRoamingList);
6966 } finally {
6967 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006968 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006969 }
6970
6971 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006972 @Deprecated
6973 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6974 enforceModifyPermission();
6975
6976 int returnValue = 0;
6977 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006978 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006979 if(result.exception == null) {
6980 if (result.result != null) {
6981 byte[] responseData = (byte[])(result.result);
6982 if(responseData.length > oemResp.length) {
6983 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6984 responseData.length + "bytes. Buffer Size is " +
6985 oemResp.length + "bytes.");
6986 }
6987 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6988 returnValue = responseData.length;
6989 }
6990 } else {
6991 CommandException ex = (CommandException) result.exception;
6992 returnValue = ex.getCommandError().ordinal();
6993 if(returnValue > 0) returnValue *= -1;
6994 }
6995 } catch (RuntimeException e) {
6996 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6997 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6998 if(returnValue > 0) returnValue *= -1;
6999 }
7000
7001 return returnValue;
7002 }
7003
7004 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007005 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007006 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007007 try {
7008 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007009 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007010 mApp, phone.getSubId(), "getRadioAccessFamily");
7011 } catch (SecurityException e) {
7012 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7013 throw e;
7014 }
chen xub97461a2018-10-26 14:17:57 -07007015 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007016 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007017 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 final long identity = Binder.clearCallingIdentity();
7020 try {
chen xub97461a2018-10-26 14:17:57 -07007021 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007022 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007023 mApp, phone.getSubId(), "getRadioAccessFamily");
7024 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 } finally {
7026 Binder.restoreCallingIdentity(identity);
7027 }
chen xub97461a2018-10-26 14:17:57 -07007028 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007029 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007030
7031 @Override
7032 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007033 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007034 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035
7036 final long identity = Binder.clearCallingIdentity();
7037 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007038 ImsManager.getInstance(defaultPhone.getContext(),
7039 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 } finally {
7041 Binder.restoreCallingIdentity(identity);
7042 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007043 }
7044
7045 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007046 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007047 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7049 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007050 return false;
7051 }
Svet Ganovb320e182015-04-16 12:30:10 -07007052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053 final long identity = Binder.clearCallingIdentity();
7054 try {
7055 // Check the user preference and the system-level IMS setting. Even if the user has
7056 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7057 // In the long run, we may instead need to check if there exists a connection service
7058 // which can support video calling.
7059 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007060 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 return imsManager.isVtEnabledByPlatform()
7062 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7063 && imsManager.isVtEnabledByUser();
7064 } finally {
7065 Binder.restoreCallingIdentity(identity);
7066 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007067 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007068
Andrew Leea1239f22015-03-02 17:44:07 -08007069 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007070 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7071 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007073 mApp, subId, callingPackage, callingFeatureId,
7074 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 return false;
7076 }
7077
7078 final long identity = Binder.clearCallingIdentity();
7079 try {
7080 CarrierConfigManager configManager =
7081 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007082 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7084 } finally {
7085 Binder.restoreCallingIdentity(identity);
7086 }
Andrew Leea1239f22015-03-02 17:44:07 -08007087 }
7088
7089 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007090 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007092 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093 return false;
7094 }
7095
7096 final long identity = Binder.clearCallingIdentity();
7097 try {
7098 CarrierConfigManager configManager =
7099 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007100 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
Andrew Leea1239f22015-03-02 17:44:07 -08007105 }
7106
Andrew Lee9431b832015-03-09 18:46:45 -07007107 @Override
7108 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007109 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007110 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007111 }
7112
7113 @Override
7114 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115 final long identity = Binder.clearCallingIdentity();
7116 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007117 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 } finally {
7119 Binder.restoreCallingIdentity(identity);
7120 }
Andrew Lee9431b832015-03-09 18:46:45 -07007121 }
7122
Hall Liuf6668912018-10-31 17:05:23 -07007123 /**
7124 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7125 * support for the feature and device firmware support.
7126 *
7127 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7128 */
7129 @Override
7130 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007132 final Phone phone = getPhone(subscriptionId);
7133 if (phone == null) {
7134 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7135 return false;
7136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007138 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7140 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007141 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142 return isCarrierSupported && isDeviceSupported;
7143 } finally {
7144 Binder.restoreCallingIdentity(identity);
7145 }
Hall Liu98187582018-01-22 19:15:32 -08007146 }
7147
Hall Liuf6668912018-10-31 17:05:23 -07007148 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007149 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7150 * RTT setting, will return true if the device and carrier both support RTT.
7151 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007152 */
7153 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154 final long identity = Binder.clearCallingIdentity();
7155 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007156 boolean isRttSupported = isRttSupported(subscriptionId);
7157 boolean isUserRttSettingOn = Settings.Secure.getInt(
7158 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7159 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7160 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7161 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007165 }
7166
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007167 @Deprecated
7168 @Override
7169 public String getDeviceId(String callingPackage) {
7170 return getDeviceIdWithFeature(callingPackage, null);
7171 }
7172
Sanket Padawe7310cc72015-01-14 09:53:20 -08007173 /**
7174 * Returns the unique device ID of phone, for example, the IMEI for
7175 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7176 *
7177 * <p>Requires Permission:
7178 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7179 */
7180 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007181 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007182 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007183 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007184 return null;
7185 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007186 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007187 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007188 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007189 return null;
7190 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191
7192 final long identity = Binder.clearCallingIdentity();
7193 try {
7194 return phone.getDeviceId();
7195 } finally {
7196 Binder.restoreCallingIdentity(identity);
7197 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007198 }
7199
Ping Sunc67b7c22016-03-02 19:16:45 +08007200 /**
7201 * {@hide}
7202 * Returns the IMS Registration Status on a particular subid
7203 *
7204 * @param subId
7205 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007206 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007207 Phone phone = getPhone(subId);
7208 if (phone != null) {
7209 return phone.isImsRegistered();
7210 } else {
7211 return false;
7212 }
7213 }
7214
Santos Cordon7a1885b2015-02-03 11:15:19 -08007215 @Override
7216 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 final long identity = Binder.clearCallingIdentity();
7218 try {
7219 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7220 } finally {
7221 Binder.restoreCallingIdentity(identity);
7222 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007223 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007224
Tyler Gunnf70ed162019-04-03 15:28:53 -07007225 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007226 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007227 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007229 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007230 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7231 }
7232 final long identity = Binder.clearCallingIdentity();
7233 try {
7234 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7235 } finally {
7236 Binder.restoreCallingIdentity(identity);
7237 }
7238 }
7239
7240 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007241 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007242 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7243 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007244 final long identity = Binder.clearCallingIdentity();
7245 try {
7246 Phone phone = getPhone(subscriptionId);
7247 if (phone == null) {
7248 return null;
7249 }
7250 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7251 } finally {
7252 Binder.restoreCallingIdentity(identity);
7253 }
7254 }
7255
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007256 /**
7257 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007258 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007259 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 Phone phone = getPhone(subId);
7263 if (phone != null) {
7264 return phone.isWifiCallingEnabled();
7265 } else {
7266 return false;
7267 }
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007270 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007271 }
7272
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007273 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007274 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007275 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007276 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007277 final long identity = Binder.clearCallingIdentity();
7278 try {
7279 Phone phone = getPhone(subId);
7280 if (phone != null) {
7281 return phone.isVideoEnabled();
7282 } else {
7283 return false;
7284 }
7285 } finally {
7286 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007287 }
7288 }
7289
7290 /**
7291 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7292 * defined in {@link ImsRegistrationImplBase}.
7293 */
7294 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 Phone phone = getPhone(subId);
7298 if (phone != null) {
7299 return phone.getImsRegistrationTech();
7300 } else {
7301 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7302 }
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007305 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007306 }
7307
Stuart Scott8eef64f2015-04-08 15:13:54 -07007308 @Override
7309 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007310 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007311 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7312 return;
7313 }
7314
Svet Ganovcc087f82015-05-12 20:35:54 -07007315 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007316
Svet Ganovcc087f82015-05-12 20:35:54 -07007317 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007318 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7319 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007320 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007321 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007322 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007323 Phone phone = getPhone(subId);
SongFerngWang51ee2b12021-05-27 22:44:54 +08007324 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007325 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7326 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007327 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007328 // There has been issues when Sms raw table somehow stores orphan
7329 // fragments. They lead to garbled message when new fragments come
7330 // in and combined with those stale ones. In case this happens again,
7331 // user can reset all network settings which will clean up this table.
7332 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007333 // Clean up IMS settings as well here.
7334 int slotId = getSlotIndex(subId);
7335 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7336 ImsManager.getInstance(mApp, slotId).factoryReset();
7337 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007338
7339 // Erase modem config if erase modem on network setting is enabled.
7340 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7341 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7342 if (configValue != null && Boolean.parseBoolean(configValue)) {
7343 sendEraseModemConfig(getDefaultPhone());
7344 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007345 } finally {
7346 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007347 }
7348 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007349
SongFerngWang51ee2b12021-05-27 22:44:54 +08007350 @VisibleForTesting
7351 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7352 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7353 return;
7354 }
7355 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7356 RILConstants.PREFERRED_NETWORK_MODE);
7357 SubscriptionManager.setSubscriptionProperty(subId,
7358 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7359 "user=" + defaultNetworkType);
7360 phone.loadAllowedNetworksFromSubscriptionDatabase();
7361 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7362 defaultNetworkType, null);
7363 }
7364
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007365 private void cleanUpSmsRawTable(Context context) {
7366 ContentResolver resolver = context.getContentResolver();
7367 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7368 resolver.delete(uri, null, null);
7369 }
7370
Narayan Kamath1c496c22015-04-16 14:40:19 +01007371 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007372 public String getSimLocaleForSubscriber(int subId) {
7373 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7374 final Phone phone = getPhone(subId);
7375 if (phone == null) {
7376 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007377 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 final long identity = Binder.clearCallingIdentity();
7380 try {
chen xu5d3637b2019-01-21 23:31:38 -08007381 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007382 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007383 if (info == null) {
7384 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7385 return null;
7386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 // Try and fetch the locale from the carrier properties or from the SIM language
7388 // preferences (EF-PL and EF-LI)...
7389 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007391 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7392 if (localeFromDefaultSim != null) {
7393 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7394 if (DBG) log("Using locale from subId: " + subId + " locale: "
7395 + localeFromDefaultSim);
7396 return localeFromDefaultSim.toLanguageTag();
7397 } else {
7398 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007399 }
7400 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007402 // The SIM language preferences only store a language (e.g. fr = French), not an
7403 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7404 // the SIM and carrier preferences does not include a country we add the country
7405 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007406 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007408 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007409 return mccLocale.toLanguageTag();
7410 }
7411
7412 if (DBG) log("No locale found - returning null");
7413 return null;
7414 } finally {
7415 Binder.restoreCallingIdentity(identity);
7416 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007417 }
7418
7419 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007420 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007421 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007422 }
7423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 /**
7425 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7426 */
7427 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007428 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007429 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007430 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007431
Chenjie Yu1ba97252018-01-11 18:16:20 -08007432 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liue8315982020-10-09 19:00:11 -07007433 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007434
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007435 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007436 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7437 * representing the state of the modem.
7438 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007439 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7440 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007441 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007442 */
7443 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007444 public void requestModemActivityInfo(ResultReceiver result) {
7445 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007446 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447
7448 final long identity = Binder.clearCallingIdentity();
7449 try {
sqian1a1be542020-03-05 11:37:28 -08007450 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 } finally {
7452 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007453 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007454 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007455
Siddharth Rayb8114062018-06-17 15:02:38 -07007456 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7457 // less than total activity duration.
7458 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7459 if (info == null) {
7460 return false;
7461 }
7462 int activityDurationMs =
Hall Liue8315982020-10-09 19:00:11 -07007463 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7464 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7465
Siddharth Rayb8114062018-06-17 15:02:38 -07007466 return (info.isValid()
7467 && (info.getSleepTimeMillis() <= activityDurationMs)
7468 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007469 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007470 && (totalTxTimeMs <= activityDurationMs));
7471 }
7472
Jack Yu85bd38a2015-11-09 11:34:32 -08007473 /**
7474 * {@hide}
7475 * Returns the service state information on specified subscription.
7476 */
7477 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007478 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7479 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007481 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007482 return null;
7483 }
7484
Hall Liuf19c44f2018-11-27 14:38:17 -08007485 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7486 LocationAccessPolicy.checkLocationPermission(mApp,
7487 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7488 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007489 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007490 .setCallingPid(Binder.getCallingPid())
7491 .setCallingUid(Binder.getCallingUid())
7492 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007493 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007494 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007495 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7496 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007497 .build());
7498
7499 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7500 LocationAccessPolicy.checkLocationPermission(mApp,
7501 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7502 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007503 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007504 .setCallingPid(Binder.getCallingPid())
7505 .setCallingUid(Binder.getCallingUid())
7506 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007507 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007508 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007509 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7510 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007511 .build());
7512 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7513 boolean hasFinePermission =
7514 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7515 boolean hasCoarsePermission =
7516 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 final long identity = Binder.clearCallingIdentity();
7519 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007520 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7521 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7522 Rlog.d(LOG_TAG,
7523 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7524 return null;
7525 }
7526
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 final Phone phone = getPhone(subId);
7528 if (phone == null) {
7529 return null;
7530 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007531
Hall Liuf19c44f2018-11-27 14:38:17 -08007532 ServiceState ss = phone.getServiceState();
7533
7534 // Scrub out the location info in ServiceState depending on what level of access
7535 // the caller has.
7536 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007537 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7538 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 } finally {
7540 Binder.restoreCallingIdentity(identity);
7541 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007542 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007543
7544 /**
7545 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7546 *
7547 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7548 * voicemail ringtone.
7549 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7550 * PhoneAccount.
7551 */
7552 @Override
7553 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 final long identity = Binder.clearCallingIdentity();
7555 try {
7556 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7557 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007558 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007559 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7562 } finally {
7563 Binder.restoreCallingIdentity(identity);
7564 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007565 }
7566
7567 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007568 * Sets the per-account voicemail ringtone.
7569 *
7570 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7571 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7572 *
7573 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7574 * voicemail ringtone.
7575 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7576 * PhoneAccount.
7577 */
7578 @Override
7579 public void setVoicemailRingtoneUri(String callingPackage,
7580 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007581 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007583 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7584 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7586 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7587 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589
7590 final long identity = Binder.clearCallingIdentity();
7591 try {
7592 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7593 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007594 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 }
7596 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7597 } finally {
7598 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007599 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007600 }
7601
7602 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007603 * Returns whether vibration is set for voicemail notification in Phone settings.
7604 *
7605 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7606 * voicemail vibration setting.
7607 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7608 */
7609 @Override
7610 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007611 final long identity = Binder.clearCallingIdentity();
7612 try {
7613 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7614 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007615 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007616 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007618 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7619 } finally {
7620 Binder.restoreCallingIdentity(identity);
7621 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007622 }
7623
Youhan Wange64578a2016-05-02 15:32:42 -07007624 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007625 * Sets the per-account voicemail vibration.
7626 *
7627 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7628 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7629 *
7630 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7631 * voicemail vibration setting.
7632 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7633 * specific PhoneAccount.
7634 */
7635 @Override
7636 public void setVoicemailVibrationEnabled(String callingPackage,
7637 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007638 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007639 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007640 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7641 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7643 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7644 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007645 }
7646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007647 final long identity = Binder.clearCallingIdentity();
7648 try {
7649 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7650 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007651 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 }
7653 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7654 } finally {
7655 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007656 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007657 }
7658
7659 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007660 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7661 *
7662 * @throws SecurityException if the caller does not have the required permission
7663 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007664 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007665 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007666 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007667 }
7668
7669 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007670 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7671 * permission.
7672 *
7673 * @throws SecurityException if the caller does not have the required permission
7674 */
7675 private void enforceSendSmsPermission() {
7676 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7677 }
7678
7679 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007680 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007681 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007682 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007683 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007684 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 final long identity = Binder.clearCallingIdentity();
7686 try {
7687 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007688 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007689 if (componentName == null) {
7690 throw new SecurityException(
7691 "Caller not current active visual voicemail package[null]");
7692 }
7693 String vvmPackage = componentName.getPackageName();
7694 if (!callingPackage.equals(vvmPackage)) {
7695 throw new SecurityException("Caller not current active visual voicemail package["
7696 + vvmPackage + "]");
7697 }
7698 } finally {
7699 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007700 }
7701 }
7702
7703 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007704 * Return the application ID for the app type.
7705 *
7706 * @param subId the subscription ID that this request applies to.
7707 * @param appType the uicc app type.
7708 * @return Application ID for specificied app type, or null if no uicc.
7709 */
7710 @Override
7711 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007712 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007713 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007714
7715 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007716 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 if (phone == null) {
7718 return null;
7719 }
7720 String aid = null;
7721 try {
7722 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7723 .getApplicationByType(appType).getAid();
7724 } catch (Exception e) {
7725 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7726 }
7727 return aid;
7728 } finally {
7729 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007730 }
Youhan Wange64578a2016-05-02 15:32:42 -07007731 }
7732
Youhan Wang4001d252016-05-11 10:29:41 -07007733 /**
7734 * Return the Electronic Serial Number.
7735 *
7736 * @param subId the subscription ID that this request applies to.
7737 * @return ESN or null if error.
7738 */
7739 @Override
7740 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007741 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007742 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007743
7744 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007745 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 if (phone == null) {
7747 return null;
7748 }
7749 String esn = null;
7750 try {
7751 esn = phone.getEsn();
7752 } catch (Exception e) {
7753 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7754 }
7755 return esn;
7756 } finally {
7757 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007758 }
Youhan Wang4001d252016-05-11 10:29:41 -07007759 }
7760
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007761 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007762 * Return the Preferred Roaming List Version.
7763 *
7764 * @param subId the subscription ID that this request applies to.
7765 * @return PRLVersion or null if error.
7766 */
7767 @Override
7768 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007769 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007770 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771
7772 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007773 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774 if (phone == null) {
7775 return null;
7776 }
7777 String cdmaPrlVersion = null;
7778 try {
7779 cdmaPrlVersion = phone.getCdmaPrlVersion();
7780 } catch (Exception e) {
7781 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7782 }
7783 return cdmaPrlVersion;
7784 } finally {
7785 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007786 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007787 }
7788
7789 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007790 * Get snapshot of Telephony histograms
7791 * @return List of Telephony histograms
7792 * @hide
7793 */
7794 @Override
7795 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7797 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798
7799 final long identity = Binder.clearCallingIdentity();
7800 try {
7801 return RIL.getTelephonyRILTimingHistograms();
7802 } finally {
7803 Binder.restoreCallingIdentity(identity);
7804 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007805 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007806
7807 /**
7808 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007809 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7810 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007811 * Require system privileges. In the future we may add this to carrier APIs.
7812 *
Michele Berionne482f8202018-11-27 18:57:59 -08007813 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007814 */
7815 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007816 @TelephonyManager.SetCarrierRestrictionResult
7817 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007818 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007819 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007820
Michele Berionne482f8202018-11-27 18:57:59 -08007821 if (carrierRestrictionRules == null) {
7822 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007823 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 final long identity = Binder.clearCallingIdentity();
7826 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007827 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007828 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829 } finally {
7830 Binder.restoreCallingIdentity(identity);
7831 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007832 }
7833
7834 /**
7835 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007836 * Get the allowed carrier list and the excluded carrier list, including the priority between
7837 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007838 * Require system privileges. In the future we may add this to carrier APIs.
7839 *
Michele Berionne482f8202018-11-27 18:57:59 -08007840 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007841 */
7842 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007843 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007844 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007845 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007846
7847 final long identity = Binder.clearCallingIdentity();
7848 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007849 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7850 if (response instanceof CarrierRestrictionRules) {
7851 return (CarrierRestrictionRules) response;
7852 }
7853 // Response is an Exception of some kind,
7854 // which is signalled to the user as a NULL retval
7855 return null;
7856 } catch (Exception e) {
7857 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7858 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007859 } finally {
7860 Binder.restoreCallingIdentity(identity);
7861 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007862 }
7863
fionaxu59545b42016-05-25 15:53:37 -07007864 /**
fionaxu59545b42016-05-25 15:53:37 -07007865 * Action set from carrier signalling broadcast receivers to enable/disable radio
7866 * @param subId the subscription ID that this action applies to.
7867 * @param enabled control enable or disable radio.
7868 * {@hide}
7869 */
7870 @Override
7871 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7872 enforceModifyPermission();
7873 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874
7875 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007876 if (phone == null) {
7877 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7878 return;
7879 }
7880 try {
7881 phone.carrierActionSetRadioEnabled(enabled);
7882 } catch (Exception e) {
7883 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007884 } finally {
7885 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007886 }
7887 }
7888
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007889 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007890 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7891 * network status based on which carrier apps could apply actions accordingly,
7892 * enable/disable default url handler for example.
7893 *
7894 * @param subId the subscription ID that this action applies to.
7895 * @param report control start/stop reporting the default network status.
7896 * {@hide}
7897 */
7898 @Override
7899 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7900 enforceModifyPermission();
7901 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007902
7903 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007904 if (phone == null) {
7905 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7906 return;
7907 }
7908 try {
7909 phone.carrierActionReportDefaultNetworkStatus(report);
7910 } catch (Exception e) {
7911 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 } finally {
7913 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007914 }
7915 }
7916
7917 /**
fionaxud9622282017-07-17 17:51:30 -07007918 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7919 * @param subId the subscription ID that this action applies to.
7920 * {@hide}
7921 */
7922 @Override
7923 public void carrierActionResetAll(int subId) {
7924 enforceModifyPermission();
7925 final Phone phone = getPhone(subId);
7926 if (phone == null) {
7927 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7928 return;
7929 }
7930 try {
7931 phone.carrierActionResetAll();
7932 } catch (Exception e) {
7933 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7934 }
7935 }
7936
7937 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007938 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7939 * bug report is being generated.
7940 */
7941 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007942 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007943 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7944 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007945 writer.println("Permission Denial: can't dump Phone from pid="
7946 + Binder.getCallingPid()
7947 + ", uid=" + Binder.getCallingUid()
7948 + "without permission "
7949 + android.Manifest.permission.DUMP);
7950 return;
7951 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007952 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007953 }
Jack Yueb89b242016-06-22 13:27:47 -07007954
Brad Ebingerdac2f002018-04-03 15:17:52 -07007955 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007956 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7957 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7958 @NonNull String[] args) {
7959 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7960 this, in.getFileDescriptor(), out.getFileDescriptor(),
7961 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007962 }
7963
Jack Yueb89b242016-06-22 13:27:47 -07007964 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007965 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007966 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007967 * @param reason the reason the data enable change is taking place
7968 * @param enabled True if enabling the data, otherwise disabling.
7969 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007970 */
7971 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007972 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007973 boolean enabled) {
7974 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7975 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7976 try {
7977 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007978 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007979 } catch (SecurityException se) {
7980 enforceModifyPermission();
7981 }
7982 } else {
7983 enforceModifyPermission();
7984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985
7986 final long identity = Binder.clearCallingIdentity();
7987 try {
7988 Phone phone = getPhone(subId);
7989 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007990 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7991 phone.carrierActionSetMeteredApnsEnabled(enabled);
7992 } else {
7993 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995 }
7996 } finally {
7997 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007998 }
7999 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008000
8001 /**
8002 * Get Client request stats
8003 * @return List of Client Request Stats
8004 * @hide
8005 */
8006 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008007 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8008 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008009 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008010 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008011 return null;
8012 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008013 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015 final long identity = Binder.clearCallingIdentity();
8016 try {
8017 if (phone != null) {
8018 return phone.getClientRequestStats();
8019 }
8020
8021 return null;
8022 } finally {
8023 Binder.restoreCallingIdentity(identity);
8024 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008025 }
8026
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008027 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008028 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008029 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008030 }
Jack Yueb4124c2017-02-16 15:32:43 -08008031
8032 /**
Grace Chen70990072017-03-24 17:21:30 -07008033 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008034 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008035 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008036 * @param state State of SIM (power down, power up, pass through)
8037 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8038 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8039 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008040 *
8041 **/
8042 @Override
Grace Chen70990072017-03-24 17:21:30 -07008043 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008044 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008045 Phone phone = PhoneFactory.getPhone(slotIndex);
8046
vagdeviaf9a5b92018-08-15 16:01:53 -07008047 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008049 final long identity = Binder.clearCallingIdentity();
8050 try {
8051 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008052 phone.setSimPowerState(state, null, workSource);
8053 }
8054 } finally {
8055 Binder.restoreCallingIdentity(identity);
8056 }
8057 }
8058
8059 /**
8060 * Set SIM card power state.
8061 *
8062 * @param slotIndex SIM slot id.
8063 * @param state State of SIM (power down, power up, pass through)
8064 * @param callback callback to trigger after success or failure
8065 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8066 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8067 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8068 *
8069 **/
8070 @Override
8071 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8072 IIntegerConsumer callback) {
8073 enforceModifyPermission();
8074 Phone phone = PhoneFactory.getPhone(slotIndex);
8075
8076 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8077
8078 final long identity = Binder.clearCallingIdentity();
8079 try {
8080 if (phone != null) {
8081 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8082 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 }
8084 } finally {
8085 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008086 }
8087 }
Shuo Qiandd210312017-04-12 22:11:33 +00008088
Tyler Gunn65d45c22017-06-05 11:22:26 -07008089 private boolean isUssdApiAllowed(int subId) {
8090 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008091 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008092 if (configManager == null) {
8093 return false;
8094 }
8095 PersistableBundle pb = configManager.getConfigForSubId(subId);
8096 if (pb == null) {
8097 return false;
8098 }
8099 return pb.getBoolean(
8100 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8101 }
8102
Shuo Qiandd210312017-04-12 22:11:33 +00008103 /**
8104 * Check if phone is in emergency callback mode
8105 * @return true if phone is in emergency callback mode
8106 * @param subId sub id
8107 */
goneil9c5f4872017-12-05 14:07:56 -08008108 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008109 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008110 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008111 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008112
8113 final long identity = Binder.clearCallingIdentity();
8114 try {
8115 if (phone != null) {
8116 return phone.isInEcm();
8117 } else {
8118 return false;
8119 }
8120 } finally {
8121 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008122 }
8123 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008124
8125 /**
8126 * Get the current signal strength information for the given subscription.
8127 * Because this information is not updated when the device is in a low power state
8128 * it should not be relied-upon to be current.
8129 * @param subId Subscription index
8130 * @return the most recent cached signal strength info from the modem
8131 */
8132 @Override
8133 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008134 final long identity = Binder.clearCallingIdentity();
8135 try {
8136 Phone p = getPhone(subId);
8137 if (p == null) {
8138 return null;
8139 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141 return p.getSignalStrength();
8142 } finally {
8143 Binder.restoreCallingIdentity(identity);
8144 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008145 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008146
Pengquan Meng77b7f132018-08-22 14:49:57 -07008147 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008148 * Get the current modem radio state for the given slot.
8149 * @param slotIndex slot index.
8150 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008151 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008152 * @return the current radio power state from the modem
8153 */
8154 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008155 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008156 Phone phone = PhoneFactory.getPhone(slotIndex);
8157 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8159 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008160 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8161 }
8162
8163 final long identity = Binder.clearCallingIdentity();
8164 try {
8165 return phone.getRadioPowerState();
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
8168 }
8169 }
8170 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8171 }
8172
8173 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008174 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8175 *
8176 * <p>Requires one of the following permissions:
8177 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8178 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8179 * privileges.
8180 *
8181 * @param subId subscription id
8182 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8183 * {@code false}.
8184 */
8185 @Override
8186 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008187 try {
8188 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8189 null);
8190 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008191 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008192 mApp, subId, "isDataRoamingEnabled");
8193 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008194
Pengquan Menga1bb6272018-09-06 09:59:22 -07008195 boolean isEnabled = false;
8196 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008197 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008198 Phone phone = getPhone(subId);
8199 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008200 } finally {
8201 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008202 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008203 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008204 }
8205
8206
8207 /**
8208 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8209 *
8210 * <p> Requires permission:
8211 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8212 * privileges.
8213 *
8214 * @param subId subscription id
8215 * @param isEnabled {@code true} means enable, {@code false} means disable.
8216 */
8217 @Override
8218 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8220 mApp, subId, "setDataRoamingEnabled");
8221
Pengquan Menga1bb6272018-09-06 09:59:22 -07008222 final long identity = Binder.clearCallingIdentity();
8223 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008224 Phone phone = getPhone(subId);
8225 if (phone != null) {
8226 phone.setDataRoamingEnabled(isEnabled);
8227 }
8228 } finally {
8229 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008230 }
8231 }
8232
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008233 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008234 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008235 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008236 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008237 mApp, subId, "isManualNetworkSelectionAllowed");
8238
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008239 boolean isAllowed = true;
8240 final long identity = Binder.clearCallingIdentity();
8241 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008242 Phone phone = getPhone(subId);
8243 if (phone != null) {
8244 isAllowed = phone.isCspPlmnEnabled();
8245 }
8246 } finally {
8247 Binder.restoreCallingIdentity(identity);
8248 }
8249 return isAllowed;
8250 }
8251
8252 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008253 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008254 // Verify that tha callingPackage belongs to the calling UID
8255 mApp.getSystemService(AppOpsManager.class)
8256 .checkPackage(Binder.getCallingUid(), callingPackage);
8257
Jordan Liu1e142fc2019-04-22 15:10:43 -07008258 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008259 try {
8260 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008261 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008262 } catch (SecurityException e) {
8263 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8264 // has carrier privileges on an active UICC
8265 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8266 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008267 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008268 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008269 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008270
8271 final long identity = Binder.clearCallingIdentity();
8272 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008273 UiccController uiccController = UiccController.getInstance();
8274 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008275 if (hasReadPermission) {
8276 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008277 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008278
8279 // Remove private info if the caller doesn't have access
8280 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8281 for (UiccCardInfo cardInfo : cardInfos) {
8282 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8283 // is available
8284 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8285 if (card == null || card.getUiccProfile() == null) {
8286 // assume no access if the card or profile is unavailable
8287 filteredInfos.add(cardInfo.getUnprivileged());
8288 continue;
8289 }
8290 UiccProfile profile = card.getUiccProfile();
8291 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8292 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8293 filteredInfos.add(cardInfo);
8294 } else {
8295 filteredInfos.add(cardInfo.getUnprivileged());
8296 }
8297 }
8298 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008299 } finally {
8300 Binder.restoreCallingIdentity(identity);
8301 }
8302 }
8303
8304 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008305 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008306 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308 final long identity = Binder.clearCallingIdentity();
8309 try {
8310 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8311 if (slots == null) {
8312 Rlog.i(LOG_TAG, "slots is null.");
8313 return null;
8314 }
8315
8316 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8317 for (int i = 0; i < slots.length; i++) {
8318 UiccSlot slot = slots[i];
8319 if (slot == null) {
8320 continue;
8321 }
8322
Jordan Liu7be7e652019-05-06 18:55:02 +00008323 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008324 UiccCard card = slot.getUiccCard();
8325 if (card != null) {
8326 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008327 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008328 cardId = slot.getEid();
8329 if (TextUtils.isEmpty(cardId)) {
8330 cardId = slot.getIccId();
8331 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008332 }
8333
Jordan Liu857451f2019-05-09 16:35:35 -07008334 if (cardId != null) {
8335 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8336 // if cardId is an EID, it's all digits so this is fine
8337 cardId = IccUtils.stripTrailingFs(cardId);
8338 }
8339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008340 int cardState = 0;
8341 switch (slot.getCardState()) {
8342 case CARDSTATE_ABSENT:
8343 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8344 break;
8345 case CARDSTATE_PRESENT:
8346 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8347 break;
8348 case CARDSTATE_ERROR:
8349 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8350 break;
8351 case CARDSTATE_RESTRICTED:
8352 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8353 break;
8354 default:
8355 break;
8356
8357 }
8358
8359 infos[i] = new UiccSlotInfo(
8360 slot.isActive(),
8361 slot.isEuicc(),
8362 cardId,
8363 cardState,
8364 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008365 slot.isExtendedApduSupported(),
8366 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367 }
8368 return infos;
8369 } finally {
8370 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008371 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008372 }
8373
8374 @Override
8375 public boolean switchSlots(int[] physicalSlots) {
8376 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008377
8378 final long identity = Binder.clearCallingIdentity();
8379 try {
8380 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8381 } finally {
8382 Binder.restoreCallingIdentity(identity);
8383 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008384 }
Jack Yu4c988042018-02-27 15:30:01 -08008385
8386 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008387 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008388 final long identity = Binder.clearCallingIdentity();
8389 try {
8390 return UiccController.getInstance().getCardIdForDefaultEuicc();
8391 } finally {
8392 Binder.restoreCallingIdentity(identity);
8393 }
8394 }
8395
Pengquan Meng85728fb2018-03-12 16:31:21 -07008396 /**
goneil47ffb6e2018-04-06 15:40:58 -07008397 * A test API to reload the UICC profile.
8398 *
8399 * <p>Requires that the calling app has permission
8400 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8401 * @hide
8402 */
8403 @Override
8404 public void refreshUiccProfile(int subId) {
8405 enforceModifyPermission();
8406
8407 final long identity = Binder.clearCallingIdentity();
8408 try {
8409 Phone phone = getPhone(subId);
8410 if (phone == null) {
8411 return;
8412 }
8413 UiccCard uiccCard = phone.getUiccCard();
8414 if (uiccCard == null) {
8415 return;
8416 }
8417 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8418 if (uiccProfile == null) {
8419 return;
8420 }
8421 uiccProfile.refresh();
8422 } finally {
8423 Binder.restoreCallingIdentity(identity);
8424 }
8425 }
8426
8427 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008428 * Returns false if the mobile data is disabled by default, otherwise return true.
8429 */
8430 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008431 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008432 }
8433
8434 /**
8435 * Returns true if the data roaming is enabled by default, i.e the system property
8436 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8437 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8438 */
8439 private boolean getDefaultDataRoamingEnabled(int subId) {
8440 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008441 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008442 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008443 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8444 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8445 return isDataRoamingEnabled;
8446 }
8447
8448 /**
8449 * Returns the default network type for the given {@code subId}, if the default network type is
8450 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8451 */
8452 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008453 List<Integer> list = TelephonyProperties.default_network();
8454 int phoneId = mSubscriptionController.getPhoneId(subId);
8455 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8456 return list.get(phoneId);
8457 }
8458 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008459 }
fionaxua13278b2018-03-21 00:08:13 -07008460
8461 @Override
8462 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008463 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008464 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008465
8466 final long identity = Binder.clearCallingIdentity();
8467 try {
8468 final Phone phone = getPhone(subId);
8469 if (phone == null) {
8470 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8471 return;
8472 }
chen xueaba88a2019-03-15 13:15:10 -07008473 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8474 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008475 if (carrierPrivilegeRules == null) {
8476 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8477 } else {
8478 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008480 } finally {
8481 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008482 }
fionaxua13278b2018-03-21 00:08:13 -07008483 }
8484
8485 @Override
8486 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008487 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008488
8489 final long identity = Binder.clearCallingIdentity();
8490 try {
8491 final Phone phone = getPhone(subId);
8492 if (phone == null) {
8493 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8494 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8495 }
8496 return phone.getCarrierIdListVersion();
8497 } finally {
8498 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008499 }
fionaxua13278b2018-03-21 00:08:13 -07008500 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008501
8502 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008503 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8504 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008506 mApp, subId, callingPackage, callingFeatureId,
8507 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008508 return -1;
8509 }
8510
8511 final long identity = Binder.clearCallingIdentity();
8512 try {
8513 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8514 } finally {
8515 Binder.restoreCallingIdentity(identity);
8516 }
8517 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008518
8519 @Override
8520 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008521 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008522 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008523 mApp, subId, "getCdmaRoamingMode");
8524
8525 final long identity = Binder.clearCallingIdentity();
8526 try {
8527 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8528 } finally {
8529 Binder.restoreCallingIdentity(identity);
8530 }
8531 }
8532
8533 @Override
8534 public boolean setCdmaRoamingMode(int subId, int mode) {
8535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8536 mApp, subId, "setCdmaRoamingMode");
8537
8538 final long identity = Binder.clearCallingIdentity();
8539 try {
8540 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8541 } finally {
8542 Binder.restoreCallingIdentity(identity);
8543 }
8544 }
8545
8546 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008547 public int getCdmaSubscriptionMode(int subId) {
8548 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008549 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008550 mApp, subId, "getCdmaSubscriptionMode");
8551
8552 final long identity = Binder.clearCallingIdentity();
8553 try {
8554 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8555 } finally {
8556 Binder.restoreCallingIdentity(identity);
8557 }
8558 }
8559
8560 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008561 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8563 mApp, subId, "setCdmaSubscriptionMode");
8564
8565 final long identity = Binder.clearCallingIdentity();
8566 try {
8567 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8568 } finally {
8569 Binder.restoreCallingIdentity(identity);
8570 }
8571 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008572
sqianc5eccab2018-10-19 18:46:41 -07008573 @Override
sqian8c685422019-02-22 15:55:18 -08008574 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008575 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008577 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8578 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008579 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8580 }
8581 final long identity = Binder.clearCallingIdentity();
8582 try {
sqian854d44b2018-12-12 16:48:18 -08008583 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8584 for (Phone phone: PhoneFactory.getPhones()) {
8585 if (phone.getEmergencyNumberTracker() != null
8586 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8587 emergencyNumberListInternal.put(
8588 phone.getSubId(),
8589 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8590 }
sqian11b7a0e2018-12-05 18:48:28 -08008591 }
sqian854d44b2018-12-12 16:48:18 -08008592 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008593 } finally {
8594 Binder.restoreCallingIdentity(identity);
8595 }
sqianc5eccab2018-10-19 18:46:41 -07008596 }
8597
8598 @Override
sqian8c685422019-02-22 15:55:18 -08008599 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008600 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008601 if (!exactMatch) {
8602 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008603 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008604 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008605 }
8606 final long identity = Binder.clearCallingIdentity();
8607 try {
sqian854d44b2018-12-12 16:48:18 -08008608 for (Phone phone: PhoneFactory.getPhones()) {
8609 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008610 && phone.getEmergencyNumberTracker()
8611 .isEmergencyNumber(number, exactMatch)) {
8612 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008613 }
sqian11b7a0e2018-12-05 18:48:28 -08008614 }
8615 return false;
8616 } finally {
8617 Binder.restoreCallingIdentity(identity);
8618 }
8619 }
8620
sqianf4ca7ed2019-01-15 18:32:07 -08008621 /**
Shuo Qian479dd9e2021-02-22 18:32:21 -08008622 * Start emergency callback mode for GsmCdmaPhone for testing.
8623 */
8624 @Override
8625 public void startEmergencyCallbackMode() {
8626 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8627 "startEmergencyCallbackMode");
8628 enforceModifyPermission();
8629 final long identity = Binder.clearCallingIdentity();
8630 try {
8631 for (Phone phone : PhoneFactory.getPhones()) {
8632 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8633 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8634 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8635 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8636 gsmCdmaPhone.obtainMessage(
8637 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8638 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8639 }
8640 }
8641 } finally {
8642 Binder.restoreCallingIdentity(identity);
8643 }
8644 }
8645
8646 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008647 * Update emergency number list for test mode.
8648 */
8649 @Override
8650 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8651 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8652 "updateEmergencyNumberListTestMode");
8653
8654 final long identity = Binder.clearCallingIdentity();
8655 try {
8656 for (Phone phone: PhoneFactory.getPhones()) {
8657 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8658 if (tracker != null) {
8659 tracker.executeEmergencyNumberTestModeCommand(action, num);
8660 }
8661 }
8662 } finally {
8663 Binder.restoreCallingIdentity(identity);
8664 }
8665 }
8666
8667 /**
8668 * Get the full emergency number list for test mode.
8669 */
8670 @Override
8671 public List<String> getEmergencyNumberListTestMode() {
8672 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8673 "getEmergencyNumberListTestMode");
8674
8675 final long identity = Binder.clearCallingIdentity();
8676 try {
8677 Set<String> emergencyNumbers = new HashSet<>();
8678 for (Phone phone: PhoneFactory.getPhones()) {
8679 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8680 if (tracker != null) {
8681 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8682 emergencyNumbers.add(num.getNumber());
8683 }
8684 }
8685 }
8686 return new ArrayList<>(emergencyNumbers);
8687 } finally {
8688 Binder.restoreCallingIdentity(identity);
8689 }
8690 }
8691
chen xud6b45bd2018-10-30 22:27:10 -07008692 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008693 public int getEmergencyNumberDbVersion(int subId) {
8694 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8695
8696 final long identity = Binder.clearCallingIdentity();
8697 try {
8698 final Phone phone = getPhone(subId);
8699 if (phone == null) {
8700 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8701 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8702 }
8703 return phone.getEmergencyNumberDbVersion();
8704 } finally {
8705 Binder.restoreCallingIdentity(identity);
8706 }
8707 }
8708
8709 @Override
8710 public void notifyOtaEmergencyNumberDbInstalled() {
8711 enforceModifyPermission();
8712
8713 final long identity = Binder.clearCallingIdentity();
8714 try {
8715 for (Phone phone: PhoneFactory.getPhones()) {
8716 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8717 if (tracker != null) {
8718 tracker.updateOtaEmergencyNumberDatabase();
8719 }
8720 }
8721 } finally {
8722 Binder.restoreCallingIdentity(identity);
8723 }
8724 }
8725
8726 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008727 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008728 enforceActiveEmergencySessionPermission();
8729
8730 final long identity = Binder.clearCallingIdentity();
8731 try {
8732 for (Phone phone: PhoneFactory.getPhones()) {
8733 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8734 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008735 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8736 }
8737 }
8738 } finally {
8739 Binder.restoreCallingIdentity(identity);
8740 }
8741 }
8742
8743 @Override
8744 public void resetOtaEmergencyNumberDbFilePath() {
8745 enforceActiveEmergencySessionPermission();
8746
8747 final long identity = Binder.clearCallingIdentity();
8748 try {
8749 for (Phone phone: PhoneFactory.getPhones()) {
8750 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8751 if (tracker != null) {
8752 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008753 }
8754 }
8755 } finally {
8756 Binder.restoreCallingIdentity(identity);
8757 }
8758 }
8759
8760 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008761 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8762 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8763 Phone phone = getPhone(subId);
8764 if (phone == null) {
8765 return null;
8766 }
8767 final long identity = Binder.clearCallingIdentity();
8768 try {
8769 UiccProfile profile = UiccController.getInstance()
8770 .getUiccProfileForPhone(phone.getPhoneId());
8771 if (profile != null) {
8772 return profile.getCertsFromCarrierPrivilegeAccessRules();
8773 }
8774 } finally {
8775 Binder.restoreCallingIdentity(identity);
8776 }
8777 return null;
8778 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008779
8780 /**
8781 * Enable or disable a modem stack.
8782 */
8783 @Override
8784 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8785 enforceModifyPermission();
8786
8787 final long identity = Binder.clearCallingIdentity();
8788 try {
8789 Phone phone = PhoneFactory.getPhone(slotIndex);
8790 if (phone == null) {
8791 return false;
8792 } else {
8793 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8794 }
8795 } finally {
8796 Binder.restoreCallingIdentity(identity);
8797 }
8798 }
Michelecea4cf22018-12-21 15:00:11 -08008799
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008800 /**
8801 * Whether a modem stack is enabled or not.
8802 */
8803 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008804 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8805 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008806 Phone phone = PhoneFactory.getPhone(slotIndex);
8807 if (phone == null) return false;
8808
8809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008810 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8811 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008812 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8813 }
8814
8815 final long identity = Binder.clearCallingIdentity();
8816 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008817 try {
8818 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8819 } catch (NoSuchElementException ex) {
8820 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8821 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008822 } finally {
8823 Binder.restoreCallingIdentity(identity);
8824 }
8825 }
8826
Michelecea4cf22018-12-21 15:00:11 -08008827 @Override
Michele0ea7d782019-03-19 14:58:42 -07008828 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008829 enforceModifyPermission();
8830
8831 final long identity = Binder.clearCallingIdentity();
8832 try {
8833 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008834 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008835 .commit();
8836 } finally {
8837 Binder.restoreCallingIdentity(identity);
8838 }
8839 }
8840
8841 @Override
Michele0ea7d782019-03-19 14:58:42 -07008842 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008843 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008845 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8846 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008847 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008848 }
Michelecea4cf22018-12-21 15:00:11 -08008849
8850 final long identity = Binder.clearCallingIdentity();
8851 try {
Michele0ea7d782019-03-19 14:58:42 -07008852 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008853 } finally {
8854 Binder.restoreCallingIdentity(identity);
8855 }
8856 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008857
Michele0ea7d782019-03-19 14:58:42 -07008858 @TelephonyManager.IsMultiSimSupportedResult
8859 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008860 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8861 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8862 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008863 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8864 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008865 }
8866 // Check if the hardware supports multisim functionality. If usage of multisim is not
8867 // supported by the modem, indicate that it is restricted.
8868 PhoneCapability staticCapability =
8869 mPhoneConfigurationManager.getStaticPhoneCapability();
8870 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008871 loge("isMultiSimSupportedInternal: no static configuration available");
8872 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008873 }
SongFerngWang2c4309d2021-01-17 21:51:44 +08008874 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008875 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8876 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008877 }
8878 // Check if support of multiple SIMs is restricted by carrier
8879 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008880 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008881 }
8882
Michele0ea7d782019-03-19 14:58:42 -07008883 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008884 }
8885
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008886 /**
8887 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008888 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8889 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8890 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008891 * @param numOfSims number of active sims we want to switch to
8892 */
8893 @Override
8894 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008895 if (numOfSims == 1) {
8896 enforceModifyPermission();
8897 } else {
8898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8899 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8900 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008901 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008902
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008903 try {
Michele30b57b22019-03-01 12:01:14 -08008904 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008905 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008906 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8907 return;
8908 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008909 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8910 } finally {
8911 Binder.restoreCallingIdentity(identity);
8912 }
8913 }
8914
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008915 @Override
8916 public boolean isApplicationOnUicc(int subId, int appType) {
8917 enforceReadPrivilegedPermission("isApplicationOnUicc");
8918 Phone phone = getPhone(subId);
8919 if (phone == null) {
8920 return false;
8921 }
8922 final long identity = Binder.clearCallingIdentity();
8923 try {
8924 UiccCard uiccCard = phone.getUiccCard();
8925 if (uiccCard == null) {
8926 return false;
8927 }
8928 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8929 if (uiccProfile == null) {
8930 return false;
8931 }
8932 if (TelephonyManager.APPTYPE_SIM <= appType
8933 && appType <= TelephonyManager.APPTYPE_ISIM) {
8934 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8935 }
8936 return false;
8937 } finally {
8938 Binder.restoreCallingIdentity(identity);
8939 }
8940 }
8941
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008942 /**
chen xub4baa772019-04-03 10:23:41 -07008943 * Get whether making changes to modem configurations will trigger reboot.
8944 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008945 */
8946 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008947 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8948 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008949 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008950 mApp, subId, callingPackage, callingFeatureId,
8951 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008952 return false;
8953 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008954 final long identity = Binder.clearCallingIdentity();
8955 try {
8956 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8957 } finally {
8958 Binder.restoreCallingIdentity(identity);
8959 }
8960 }
8961
Nathan Harold29f5f052019-02-15 13:41:57 -08008962 private void updateModemStateMetrics() {
8963 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8964 // TODO: check the state for each modem if the api is ready.
8965 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8966 }
8967
Pengquan Meng3889a572019-01-23 11:16:29 -08008968 @Override
8969 public int[] getSlotsMapping() {
8970 enforceReadPrivilegedPermission("getSlotsMapping");
8971
8972 final long identity = Binder.clearCallingIdentity();
8973 try {
8974 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8975 // All logical slots should have a mapping to a physical slot.
8976 int[] logicalSlotsMapping = new int[phoneCount];
8977 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8978 for (int i = 0; i < slotInfos.length; i++) {
8979 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8980 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8981 }
8982 }
8983 return logicalSlotsMapping;
8984 } finally {
8985 Binder.restoreCallingIdentity(identity);
8986 }
8987 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008988
8989 /**
8990 * Get the IRadio HAL Version
8991 */
8992 @Override
8993 public int getRadioHalVersion() {
8994 Phone phone = getDefaultPhone();
8995 if (phone == null) return -1;
8996 HalVersion hv = phone.getHalVersion();
8997 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8998 return hv.major * 100 + hv.minor;
8999 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009000
9001 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08009002 * Get the current calling package name.
9003 * @return the current calling package name
9004 */
9005 @Override
9006 public String getCurrentPackageName() {
9007 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9008 }
9009
9010 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009011 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9012 * corresponding network requests on a subId.
9013 *
9014 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009015 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009016 * 2) APN is un-metered for this subscription, or
9017 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07009018 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009019 *
9020 * @return whether data is allowed for a apn type.
9021 *
9022 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009023 */
9024 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009025 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009026 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9027 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009028
9029 // Now that all security checks passes, perform the operation as ourselves.
9030 final long identity = Binder.clearCallingIdentity();
9031 try {
9032 Phone phone = getPhone(subId);
9033 if (phone == null) return false;
9034
Jack Yu41407ee2019-05-13 16:54:09 -07009035 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009036 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9037 } finally {
9038 Binder.restoreCallingIdentity(identity);
9039 }
9040 }
9041
9042 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009043 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009044 enforceReadPrivilegedPermission("isApnMetered");
9045
9046 // Now that all security checks passes, perform the operation as ourselves.
9047 final long identity = Binder.clearCallingIdentity();
9048 try {
9049 Phone phone = getPhone(subId);
9050 if (phone == null) return true; // By default return true.
9051
Jack Yu41407ee2019-05-13 16:54:09 -07009052 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009053 } finally {
9054 Binder.restoreCallingIdentity(identity);
9055 }
9056 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009057
9058 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009059 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9060 int subscriptionId, IBooleanConsumer resultCallback) {
9061 enforceModifyPermission();
9062 long token = Binder.clearCallingIdentity();
9063 try {
9064 Phone phone = getPhone(subscriptionId);
9065 if (phone == null) {
9066 try {
9067 if (resultCallback != null) {
9068 resultCallback.accept(false);
9069 }
9070 } catch (RemoteException e) {
9071 // ignore
9072 }
9073 return;
9074 }
9075 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9076 Pair.create(specifiers, (x) -> {
9077 try {
9078 if (resultCallback != null) {
9079 resultCallback.accept(x);
9080 }
9081 } catch (RemoteException e) {
9082 // ignore
9083 }
9084 });
9085 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9086 } finally {
9087 Binder.restoreCallingIdentity(token);
9088 }
9089 }
9090
9091 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009092 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9093 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07009094 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08009095 mApp, subId, "getSystemSelectionChannels");
9096 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9097 final long identity = Binder.clearCallingIdentity();
9098 try {
Sarah Chin58691872021-03-13 03:17:40 -08009099 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9100 if (result instanceof IllegalStateException) {
9101 throw (IllegalStateException) result;
9102 }
9103 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chincc055732020-11-18 13:39:35 -08009104 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9105 return specifiers;
9106 } finally {
9107 Binder.restoreCallingIdentity(identity);
9108 }
9109 }
9110
9111 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009112 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009113 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009114 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9115 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9116 if (iccRecords == null) {
9117 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9118 return false;
9119 }
9120 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9121 }
9122
9123 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009124 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9125 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009126 if (callingPackage == null) {
9127 callingPackage = getCurrentPackageName();
9128 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009129 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9130 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009131 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9132 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009133 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9134 }
9135 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9136 Intent intent = new Intent();
9137 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9138 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9139 // Bring up choose default SMS subscription dialog right now
9140 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9141 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9142 mApp.startActivity(intent);
9143 }
chen xud5ca2d52019-05-28 15:20:57 -07009144
9145 @Override
9146 public String getMmsUAProfUrl(int subId) {
9147 //TODO investigate if this API should require proper permission check in R b/133791609
9148 final long identity = Binder.clearCallingIdentity();
9149 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009150 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9151 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9152 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9153 return carrierUAProfUrl;
9154 }
chen xud5ca2d52019-05-28 15:20:57 -07009155 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9156 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9157 } finally {
9158 Binder.restoreCallingIdentity(identity);
9159 }
9160 }
9161
9162 @Override
9163 public String getMmsUserAgent(int subId) {
9164 //TODO investigate if this API should require proper permission check in R b/133791609
9165 final long identity = Binder.clearCallingIdentity();
9166 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009167 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9168 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9169 if (!TextUtils.isEmpty(carrierUserAgent)) {
9170 return carrierUserAgent;
9171 }
chen xud5ca2d52019-05-28 15:20:57 -07009172 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9173 .getString(com.android.internal.R.string.config_mms_user_agent);
9174 } finally {
9175 Binder.restoreCallingIdentity(identity);
9176 }
9177 }
Jack Yub07d4972019-05-28 16:12:25 -07009178
9179 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009180 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9181 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9182
9183 final long identity = Binder.clearCallingIdentity();
9184 try {
9185 Phone phone = getPhone(subscriptionId);
9186 if (phone == null) return false;
9187
9188 switch (policy) {
9189 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9190 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9191 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9192 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9193 default:
9194 throw new IllegalArgumentException(policy + " is not a valid policy");
9195 }
9196 } finally {
9197 Binder.restoreCallingIdentity(identity);
9198 }
9199 }
9200
9201 @Override
9202 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9203 boolean enabled) {
9204 enforceModifyPermission();
9205
9206 final long identity = Binder.clearCallingIdentity();
9207 try {
9208 Phone phone = getPhone(subscriptionId);
9209 if (phone == null) return;
9210
9211 switch (policy) {
9212 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9213 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9214 break;
9215 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9216 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9217 break;
9218 default:
9219 throw new IllegalArgumentException(policy + " is not a valid policy");
9220 }
9221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
9224 }
9225
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009226 /**
Hall Liub48cf452020-09-25 11:13:49 -07009227 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009228 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9229 * otherwise.
9230 */
9231 @Override
9232 public void setCepEnabled(boolean isCepEnabled) {
9233 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9234
9235 final long identity = Binder.clearCallingIdentity();
9236 try {
9237 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9238 for (Phone phone : PhoneFactory.getPhones()) {
9239 Phone defaultPhone = phone.getImsPhone();
9240 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9241 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9242 ImsPhoneCallTracker imsPhoneCallTracker =
9243 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9244 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9245 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9246 + imsPhone.getMsisdn());
9247 }
9248 }
9249 } finally {
9250 Binder.restoreCallingIdentity(identity);
9251 }
9252 }
allenwtsu46dcc572020-01-08 18:24:03 +08009253
9254 /**
9255 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9256 *
9257 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9258 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9259 * before being read.
9260 */
9261 @Override
9262 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9263 isCompressed) {
9264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9265 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009266 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9267 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9268 }
9269 if (!isImsAvailableOnDevice()) {
9270 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9271 "IMS not available on device.");
9272 }
9273
9274 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009275 try {
Hui Wang068ab862020-10-31 05:12:53 +00009276 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9277 } finally {
9278 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009279 }
9280 }
zoey chenf95ca592019-12-30 16:11:23 +08009281
9282 @Override
9283 public boolean isIccLockEnabled(int subId) {
9284 enforceReadPrivilegedPermission("isIccLockEnabled");
9285
9286 // Now that all security checks passes, perform the operation as ourselves.
9287 final long identity = Binder.clearCallingIdentity();
9288 try {
9289 Phone phone = getPhone(subId);
9290 if (phone != null && phone.getIccCard() != null) {
9291 return phone.getIccCard().getIccLockEnabled();
9292 } else {
9293 return false;
9294 }
9295 } finally {
9296 Binder.restoreCallingIdentity(identity);
9297 }
9298 }
9299
9300 /**
zoey chene02881a2019-12-30 16:11:23 +08009301 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009302 *
zoey chene02881a2019-12-30 16:11:23 +08009303 * @return an integer representing the status of IccLock enabled or disabled in the following
9304 * three cases:
9305 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9306 * successfully.
9307 * - Positive number and zero for remaining password attempts.
9308 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009309 *
9310 */
9311 @Override
9312 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9313 enforceModifyPermission();
9314
9315 Phone phone = getPhone(subId);
9316 if (phone == null) {
9317 return 0;
9318 }
9319 // Now that all security checks passes, perform the operation as ourselves.
9320 final long identity = Binder.clearCallingIdentity();
9321 try {
9322 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9323 new Pair<Boolean, String>(enabled, password), phone, null);
9324 return attemptsRemaining;
9325
9326 } catch (Exception e) {
9327 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9328 } finally {
9329 Binder.restoreCallingIdentity(identity);
9330 }
9331 return 0;
9332 }
9333
9334 /**
9335 * Change the ICC password used in ICC pin lock.
9336 *
zoey chene02881a2019-12-30 16:11:23 +08009337 * @return an integer representing the status of IccLock changed in the following three cases:
9338 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9339 * - Positive number and zero for remaining password attempts.
9340 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009341 *
9342 */
9343 @Override
9344 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9345 enforceModifyPermission();
9346
9347 Phone phone = getPhone(subId);
9348 if (phone == null) {
9349 return 0;
9350 }
9351 // Now that all security checks passes, perform the operation as ourselves.
9352 final long identity = Binder.clearCallingIdentity();
9353 try {
9354 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9355 new Pair<String, String>(oldPassword, newPassword), phone, null);
9356 return attemptsRemaining;
9357
9358 } catch (Exception e) {
9359 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9360 } finally {
9361 Binder.restoreCallingIdentity(identity);
9362 }
9363 return 0;
9364 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009365
Peter Wangdafb9ac2020-01-15 14:13:38 -08009366 /**
9367 * Request for receiving user activity notification
9368 */
9369 @Override
9370 public void requestUserActivityNotification() {
9371 if (!mNotifyUserActivity.get()
9372 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9373 mNotifyUserActivity.set(true);
9374 }
9375 }
9376
9377 /**
9378 * Called when userActivity is signalled in the power manager.
9379 * This is safe to call from any thread, with any window manager locks held or not.
9380 */
9381 @Override
9382 public void userActivity() {
9383 // ***************************************
9384 // * Inherited from PhoneWindowManager *
9385 // ***************************************
9386 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9387 // WITH ITS LOCKS HELD.
9388 //
9389 // This code must be VERY careful about the locks
9390 // it acquires.
9391 // In fact, the current code acquires way too many,
9392 // and probably has lurking deadlocks.
9393
9394 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9395 throw new SecurityException("Only the OS may call notifyUserActivity()");
9396 }
9397
9398 if (mNotifyUserActivity.getAndSet(false)) {
9399 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9400 USER_ACTIVITY_NOTIFICATION_DELAY);
9401 }
9402 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009403
Malcolm Chen884180b2020-04-13 11:59:40 -07009404 @Override
9405 public boolean canConnectTo5GInDsdsMode() {
9406 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9407 }
Jack Yud10cdd42020-09-28 20:28:01 -07009408
9409 @Override
9410 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9411 String callingFeatureId) {
9412 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9413 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9414 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9415 }
9416
9417 Phone phone = getPhone(subId);
9418 if (phone == null) {
9419 throw new RuntimeException("phone is not available");
9420 }
9421 // Now that all security checks passes, perform the operation as ourselves.
9422 final long identity = Binder.clearCallingIdentity();
9423 try {
9424 return phone.getEquivalentHomePlmns();
9425 } finally {
9426 Binder.restoreCallingIdentity(identity);
9427 }
9428 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009429
Hui Wang0866fcc2020-10-12 12:14:23 -07009430 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009431 public boolean isRadioInterfaceCapabilitySupported(
9432 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009433 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009434 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009435 if (radioInterfaceCapabilities == null) {
9436 throw new RuntimeException("radio interface capabilities are not available");
9437 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009438 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009439 }
9440 }
9441
9442 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009443 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9444 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009445 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9446 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9447 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9448 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9449 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009450 if (DBG) {
9451 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9452 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9453 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9454 }
9455
9456 if (!SubscriptionManager.isValidSubscriptionId(subId)
9457 || appType < TelephonyManager.APPTYPE_UNKNOWN
9458 || appType > TelephonyManager.APPTYPE_ISIM
9459 || nafUrl == null || securityProtocol == null || callback == null) {
9460 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9461 if (callback != null) {
9462 try {
9463 callback.onAuthenticationFailure(
9464 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9465 } catch (RemoteException exception) {
9466 log("Fail to notify onAuthenticationFailure due to " + exception);
9467 }
9468 return;
9469 }
9470 }
9471
9472 final long token = Binder.clearCallingIdentity();
9473 try {
9474 getGbaManager(subId).bootstrapAuthenticationRequest(
9475 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9476 forceBootStrapping, callback));
9477 } finally {
9478 Binder.restoreCallingIdentity(token);
9479 }
9480 }
9481
Jack Nudelman24d51a52020-11-24 12:08:04 -08009482 /**
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009483 * Attempts to set the radio power state for all phones for thermal reason.
9484 * This does not guarantee that the
Jack Nudelman24d51a52020-11-24 12:08:04 -08009485 * requested radio power state will actually be set. See {@link
9486 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9487 *
Jack Nudelman24d51a52020-11-24 12:08:04 -08009488 * @param enable {@code true} if trying to turn radio on.
9489 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9490 * false}.
9491 */
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009492 private boolean setRadioPowerForThermal(boolean enable) {
9493 boolean isPhoneAvailable = false;
9494 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9495 Phone phone = PhoneFactory.getPhone(i);
9496 if (phone != null) {
9497 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9498 isPhoneAvailable = true;
9499 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009500 }
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009501
9502 // return true if successfully informed the phone object about the thermal radio power
9503 // request.
9504 return isPhoneAvailable;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009505 }
9506
9507 private int handleDataThrottlingRequest(int subId,
9508 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009509 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9510 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9511 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9512 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9513 throw new IllegalArgumentException("modem does not support data throttling");
9514 }
9515
Jack Nudelman24d51a52020-11-24 12:08:04 -08009516 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9517 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009518 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009519 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9520 }
9521
9522 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9523
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009524 if (isDataThrottlingSupported) {
9525 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009526 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009527 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9528 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9529 } else if (thermalMitigationResult
9530 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman20352592021-05-20 13:57:30 -07009531 log("Modem likely does not support data throttling on secondary carrier. Data " +
9532 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9533 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009534 }
9535 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009536 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009537
9538 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009539 }
9540
Jack Nudelman644b91a2021-03-12 14:09:48 -08009541 private static List<String> getThermalMitigationAllowlist(Context context) {
9542 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9543 for (String pckg : context.getResources()
9544 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9545 sThermalMitigationAllowlistedPackages.add(pckg);
9546 }
9547 }
9548
9549 return sThermalMitigationAllowlistedPackages;
9550 }
9551
Jack Nudelmane634f962021-05-13 10:00:15 -07009552 private boolean isAnyPhoneInEmergencyState() {
9553 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9554 if (tm.isInEmergencyCall()) {
9555 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9556 return true;
9557 }
9558 for (Phone phone : PhoneFactory.getPhones()) {
9559 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9560 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9561 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9562 + phone.isInEcm());
9563 return true;
9564 }
9565 }
9566
9567 return false;
9568 }
9569
Jack Nudelman644b91a2021-03-12 14:09:48 -08009570 /**
9571 * Used by shell commands to add an authorized package name for thermal mitigation.
9572 * @param packageName name of package to be allowlisted
9573 * @param context
9574 */
9575 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9576 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9577 sThermalMitigationAllowlistedPackages.add(packageName);
9578 }
9579
9580 /**
9581 * Used by shell commands to remove an authorized package name for thermal mitigation.
9582 * @param packageName name of package to remove from allowlist
9583 * @param context
9584 */
9585 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9586 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9587 sThermalMitigationAllowlistedPackages.remove(packageName);
9588 }
9589
Jack Nudelman24d51a52020-11-24 12:08:04 -08009590 /**
9591 * Thermal mitigation request to control functionalities at modem.
9592 *
9593 * @param subId the id of the subscription.
9594 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009595 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009596 *
9597 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9598 */
9599 @Override
9600 @ThermalMitigationResult
9601 public int sendThermalMitigationRequest(
9602 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009603 ThermalMitigationRequest thermalMitigationRequest,
9604 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009605 enforceModifyPermission();
9606
Jack Nudelman644b91a2021-03-12 14:09:48 -08009607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9608 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9609 .contains(callingPackage)) {
9610 throw new SecurityException("Calling package must be configured in the device config. "
9611 + "calling package: " + callingPackage);
9612 }
9613
Jack Nudelman24d51a52020-11-24 12:08:04 -08009614 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9615 final long identity = Binder.clearCallingIdentity();
9616
9617 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9618 try {
9619 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9620 switch (thermalMitigationAction) {
9621 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9622 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009623 handleDataThrottlingRequest(subId,
9624 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009625 break;
9626 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9627 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9628 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9629 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9630 }
9631
9632 // Ensure that radio is on. If not able to power on due to phone being
9633 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009634 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009635 thermalMitigationResult =
9636 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9637 break;
9638 }
9639
9640 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9641 false);
9642 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9643 break;
9644 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9645 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9646 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9647 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9648 }
9649
9650 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9651 if (registry != null) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009652 Phone phone = getPhone(subId);
9653 if (phone == null) {
9654 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009655 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009656 break;
9657 }
9658
Jack Nudelmane634f962021-05-13 10:00:15 -07009659 TelephonyConnectionService service =
9660 registry.getTelephonyConnectionService();
Jack Nudelmana80c0012021-06-17 15:39:58 -07009661 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane634f962021-05-13 10:00:15 -07009662 Log.e(LOG_TAG, "An emergency call is pending");
9663 thermalMitigationResult =
9664 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9665 break;
9666 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009667 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009668 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009669 break;
9670 }
9671 } else {
9672 thermalMitigationResult =
9673 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9674 break;
9675 }
9676
9677 // Turn radio off. If not able to power off due to phone being unavailable,
9678 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009679 if (!setRadioPowerForThermal(false)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009680 thermalMitigationResult =
9681 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9682 break;
9683 }
9684 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009685 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009686 break;
9687 default:
9688 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9689 + "not exist. Requested action: " + thermalMitigationAction);
9690 }
9691 } catch (IllegalArgumentException e) {
9692 throw e;
9693 } catch (Exception e) {
9694 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9695 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9696 } finally {
9697 Binder.restoreCallingIdentity(identity);
9698 }
9699
9700 if (DBG) {
9701 log("thermalMitigationRequest returning with thermalMitigationResult: "
9702 + thermalMitigationResult);
9703 }
9704
9705 return thermalMitigationResult;
9706 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009707
9708 /**
9709 * Set the GbaService Package Name that Telephony will bind to.
9710 *
9711 * @param subId The sim that the GbaService is associated with.
9712 * @param packageName The name of the package to be replaced with.
9713 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9714 */
9715 @Override
9716 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9717 enforceModifyPermission();
9718
9719 final long identity = Binder.clearCallingIdentity();
9720 try {
9721 return getGbaManager(subId).overrideServicePackage(packageName);
9722 } finally {
9723 Binder.restoreCallingIdentity(identity);
9724 }
9725 }
9726
9727 /**
9728 * Return the package name of the currently bound GbaService.
9729 *
9730 * @param subId The sim that the GbaService is associated with.
9731 * @return the package name of the GbaService configuration, null if GBA is not supported.
9732 */
9733 @Override
9734 public String getBoundGbaService(int subId) {
9735 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9736
9737 final long identity = Binder.clearCallingIdentity();
9738 try {
9739 return getGbaManager(subId).getServicePackage();
9740 } finally {
9741 Binder.restoreCallingIdentity(identity);
9742 }
9743 }
9744
9745 /**
9746 * Set the release time for telephony to unbind GbaService.
9747 *
9748 * @param subId The sim that the GbaService is associated with.
9749 * @param interval The release time to unbind GbaService by millisecond.
9750 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9751 */
9752 @Override
9753 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9754 enforceModifyPermission();
9755
9756 final long identity = Binder.clearCallingIdentity();
9757 try {
9758 return getGbaManager(subId).overrideReleaseTime(interval);
9759 } finally {
9760 Binder.restoreCallingIdentity(identity);
9761 }
9762 }
9763
9764 /**
9765 * Return the release time for telephony to unbind GbaService.
9766 *
9767 * @param subId The sim that the GbaService is associated with.
9768 * @return The release time to unbind GbaService by millisecond.
9769 */
9770 @Override
9771 public int getGbaReleaseTime(int subId) {
9772 enforceReadPrivilegedPermission("getGbaReleaseTime");
9773
9774 final long identity = Binder.clearCallingIdentity();
9775 try {
9776 return getGbaManager(subId).getReleaseTime();
9777 } finally {
9778 Binder.restoreCallingIdentity(identity);
9779 }
9780 }
9781
9782 private GbaManager getGbaManager(int subId) {
9783 GbaManager instance = GbaManager.getInstance(subId);
9784 if (instance == null) {
9785 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9786 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9787 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9788 }
9789 return instance;
9790 }
Hui Wang068ab862020-10-31 05:12:53 +00009791
9792 /**
9793 * indicate whether the device and the carrier can support
9794 * RCS VoLTE single registration.
9795 */
9796 @Override
9797 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009798 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9799 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9800 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9801 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009802
9803 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9804 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9805 }
9806
9807 final long identity = Binder.clearCallingIdentity();
9808 try {
9809 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9810 if (rpm != null) {
Hui Wang048c10a2021-06-21 18:05:57 +00009811 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
9812 if (isCapable != null) {
9813 return isCapable;
9814 }
Hui Wang068ab862020-10-31 05:12:53 +00009815 }
Hui Wang048c10a2021-06-21 18:05:57 +00009816 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
9817 "service is temporarily unavailable.");
Hui Wang068ab862020-10-31 05:12:53 +00009818 } finally {
9819 Binder.restoreCallingIdentity(identity);
9820 }
9821 }
9822
9823 /**
9824 * Register RCS provisioning callback.
9825 */
9826 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009827 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009828 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009829 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009830 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009831 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9832 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009833
9834 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9835 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9836 }
9837 if (!isImsAvailableOnDevice()) {
9838 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9839 "IMS not available on device.");
9840 }
9841
9842 final long identity = Binder.clearCallingIdentity();
9843 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009844 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009845 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009846 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9847 "Service not available for the subscription.");
9848 }
Hui Wang068ab862020-10-31 05:12:53 +00009849 } finally {
9850 Binder.restoreCallingIdentity(identity);
9851 }
9852 }
9853
9854 /**
9855 * Unregister RCS provisioning callback.
9856 */
9857 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009858 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009859 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009860 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009861 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009862 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9863 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009864
9865 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9866 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9867 }
9868 if (!isImsAvailableOnDevice()) {
9869 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9870 "IMS not available on device.");
9871 }
9872
9873 final long identity = Binder.clearCallingIdentity();
9874 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009875 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009876 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009877 } finally {
9878 Binder.restoreCallingIdentity(identity);
9879 }
9880 }
9881
9882 /**
9883 * trigger RCS reconfiguration.
9884 */
9885 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009886 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9887 "triggerRcsReconfiguration",
9888 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009889
9890 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9891 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9892 }
9893 if (!isImsAvailableOnDevice()) {
9894 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9895 "IMS not available on device.");
9896 }
9897
9898 final long identity = Binder.clearCallingIdentity();
9899 try {
9900 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9901 } finally {
9902 Binder.restoreCallingIdentity(identity);
9903 }
9904 }
9905
9906 /**
9907 * Provide the client configuration parameters of the RCS application.
9908 */
9909 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009910 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9911 "setRcsClientConfiguration",
9912 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009913
9914 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9915 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9916 }
9917 if (!isImsAvailableOnDevice()) {
9918 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9919 "IMS not available on device.");
9920 }
9921
9922 final long identity = Binder.clearCallingIdentity();
9923
9924 try {
9925 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9926 if (configBinder == null) {
9927 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9928 } else {
9929 configBinder.setRcsClientConfiguration(rcc);
9930 }
9931 } catch (RemoteException e) {
9932 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9933 } finally {
9934 Binder.restoreCallingIdentity(identity);
9935 }
9936 }
9937
9938 /**
Hui Wang19a21872021-02-19 20:45:36 -08009939 * Enables or disables the test mode for RCS VoLTE single registration.
9940 */
9941 @Override
9942 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9944 "setRcsSingleRegistrationTestModeEnabled");
9945
9946 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9947 }
9948
9949 /**
9950 * Gets the test mode for RCS VoLTE single registration.
9951 */
9952 @Override
9953 public boolean getRcsSingleRegistrationTestModeEnabled() {
9954 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9955 "getRcsSingleRegistrationTestModeEnabled");
9956
9957 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9958 }
9959
9960 /**
Hui Wang068ab862020-10-31 05:12:53 +00009961 * Overrides the config of RCS VoLTE single registration enabled for the device.
9962 */
9963 @Override
9964 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9965 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9966 "setDeviceSingleRegistrationEnabledOverride");
9967 enforceModifyPermission();
9968
9969 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9970 : Boolean.parseBoolean(enabledStr);
9971 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009972 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009973 }
9974
9975 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009976 * Sends a device to device communication message. Only usable via shell.
9977 * @param message message to send.
9978 * @param value message value.
9979 */
9980 @Override
9981 public void sendDeviceToDeviceMessage(int message, int value) {
9982 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9983 "setCarrierSingleRegistrationEnabledOverride");
9984 enforceModifyPermission();
9985
9986 final long identity = Binder.clearCallingIdentity();
9987 try {
9988 TelephonyConnectionService service =
9989 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9990 if (service == null) {
9991 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9992 return;
9993 }
9994 service.sendTestDeviceToDeviceMessage(message, value);
9995 } finally {
9996 Binder.restoreCallingIdentity(identity);
9997 }
9998 }
9999
10000
10001 /**
Hui Wang068ab862020-10-31 05:12:53 +000010002 * Gets the config of RCS VoLTE single registration enabled for the device.
10003 */
10004 @Override
10005 public boolean getDeviceSingleRegistrationEnabled() {
10006 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10007 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10008 }
10009
10010 /**
10011 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10012 */
10013 @Override
10014 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10015 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10016 "setCarrierSingleRegistrationEnabledOverride");
10017 enforceModifyPermission();
10018
10019 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10020 : Boolean.parseBoolean(enabledStr);
10021 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10022 subId, enabled);
10023 }
10024
10025 /**
10026 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10027 */
10028 @Override
10029 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10030 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10031 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10032 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010033
10034 /**
Hui Wangeadb2562021-02-26 09:33:38 -080010035 * Overrides the ims feature validation result
10036 */
10037 @Override
10038 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10039 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10040 "setImsFeatureValidationOverride");
10041
10042 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10043 : Boolean.parseBoolean(enabledStr);
10044 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10045 subId, enabled);
10046 }
10047
10048 /**
10049 * Gets the ims feature validation override value
10050 */
10051 @Override
10052 public boolean getImsFeatureValidationOverride(int subId) {
10053 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10054 "getImsFeatureValidationOverride");
10055 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10056 }
10057
10058 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010059 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10060 * their mobile plan.
10061 */
10062 @Override
10063 public String getMobileProvisioningUrl() {
10064 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10065 final long identity = Binder.clearCallingIdentity();
10066 try {
10067 return getDefaultPhone().getMobileProvisioningUrl();
10068 } finally {
10069 Binder.restoreCallingIdentity(identity);
10070 }
10071 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010072
James.cf Linbcdf8b32021-01-14 16:44:13 +080010073 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010074 * Get the EAB contact from the EAB database.
10075 */
10076 @Override
10077 public String getContactFromEab(String contact) {
10078 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10079 enforceModifyPermission();
10080 final long identity = Binder.clearCallingIdentity();
10081 try {
10082 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10083 } finally {
10084 Binder.restoreCallingIdentity(identity);
10085 }
10086 }
10087
10088 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010089 * Remove the EAB contacts from the EAB database.
10090 */
10091 @Override
10092 public int removeContactFromEab(int subId, String contacts) {
10093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10094 enforceModifyPermission();
10095 final long identity = Binder.clearCallingIdentity();
10096 try {
10097 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10098 } finally {
10099 Binder.restoreCallingIdentity(identity);
10100 }
10101 }
10102
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010103 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010104 public boolean getDeviceUceEnabled() {
10105 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10106 final long identity = Binder.clearCallingIdentity();
10107 try {
10108 return mApp.getDeviceUceEnabled();
10109 } finally {
10110 Binder.restoreCallingIdentity(identity);
10111 }
10112 }
10113
10114 @Override
10115 public void setDeviceUceEnabled(boolean isEnabled) {
10116 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10117 final long identity = Binder.clearCallingIdentity();
10118 try {
10119 mApp.setDeviceUceEnabled(isEnabled);
10120 } finally {
10121 Binder.restoreCallingIdentity(identity);
10122 }
10123 }
10124
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010125 /**
10126 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10127 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10128 */
10129 // Used for SHELL command only right now.
10130 @Override
10131 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10132 List<String> featureTags) {
10133 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10134 "addUceRegistrationOverrideShell");
10135 final long identity = Binder.clearCallingIdentity();
10136 try {
10137 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10138 new ArraySet<>(featureTags));
10139 } catch (ImsException e) {
10140 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10141 } finally {
10142 Binder.restoreCallingIdentity(identity);
10143 }
10144 }
10145
10146 /**
10147 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10148 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10149 */
10150 // Used for SHELL command only right now.
10151 @Override
10152 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10153 List<String> featureTags) {
10154 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10155 "removeUceRegistrationOverrideShell");
10156 final long identity = Binder.clearCallingIdentity();
10157 try {
10158 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10159 new ArraySet<>(featureTags));
10160 } catch (ImsException e) {
10161 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10162 } finally {
10163 Binder.restoreCallingIdentity(identity);
10164 }
10165 }
10166
10167 /**
10168 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10169 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10170 */
10171 // Used for SHELL command only right now.
10172 @Override
10173 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10174 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10175 "clearUceRegistrationOverrideShell");
10176 final long identity = Binder.clearCallingIdentity();
10177 try {
10178 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10179 } catch (ImsException e) {
10180 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10181 } finally {
10182 Binder.restoreCallingIdentity(identity);
10183 }
10184 }
10185
10186 /**
10187 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10188 */
10189 // Used for SHELL command only right now.
10190 @Override
10191 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10192 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10193 "getLatestRcsContactUceCapabilityShell");
10194 final long identity = Binder.clearCallingIdentity();
10195 try {
10196 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10197 } catch (ImsException e) {
10198 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10199 } finally {
10200 Binder.restoreCallingIdentity(identity);
10201 }
10202 }
10203
10204 /**
10205 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10206 * device does not have an active PUBLISH.
10207 */
10208 // Used for SHELL command only right now.
10209 @Override
10210 public String getLastUcePidfXmlShell(int subId) {
10211 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10212 final long identity = Binder.clearCallingIdentity();
10213 try {
10214 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10215 } catch (ImsException e) {
10216 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10217 } finally {
10218 Binder.restoreCallingIdentity(identity);
10219 }
10220 }
10221
James.cf Line8713a42021-04-29 16:04:26 +080010222 /**
10223 * Remove UCE requests cannot be sent to the network status.
10224 */
10225 // Used for SHELL command only right now.
10226 @Override
10227 public boolean removeUceRequestDisallowedStatus(int subId) {
10228 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10229 final long identity = Binder.clearCallingIdentity();
10230 try {
10231 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10232 } catch (ImsException e) {
10233 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10234 } finally {
10235 Binder.restoreCallingIdentity(identity);
10236 }
10237 }
10238
James.cf Lin18bb9002021-05-25 01:37:38 +080010239 /**
10240 * Remove UCE requests cannot be sent to the network status.
10241 */
10242 // Used for SHELL command only.
10243 @Override
10244 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10245 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10246 final long identity = Binder.clearCallingIdentity();
10247 try {
10248 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10249 } catch (ImsException e) {
10250 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10251 } finally {
10252 Binder.restoreCallingIdentity(identity);
10253 }
10254 }
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010255
James.cf Lin4b784aa2021-01-31 03:25:15 +080010256 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010257 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10258 String callingPackage) {
10259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10260 mApp, subId, "setSignalStrengthUpdateRequest");
10261
10262 final int callingUid = Binder.getCallingUid();
10263 // Verify that tha callingPackage belongs to the calling UID
10264 mApp.getSystemService(AppOpsManager.class)
10265 .checkPackage(callingUid, callingPackage);
10266
10267 validateSignalStrengthUpdateRequest(request, callingUid);
10268
10269 final long identity = Binder.clearCallingIdentity();
10270 try {
10271 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10272 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10273
10274 if (result instanceof IllegalStateException) {
10275 throw (IllegalStateException) result;
10276 }
10277 } finally {
10278 Binder.restoreCallingIdentity(identity);
10279 }
10280 }
10281
10282 @Override
10283 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10284 String callingPackage) {
10285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10286 mApp, subId, "clearSignalStrengthUpdateRequest");
10287
10288 final int callingUid = Binder.getCallingUid();
10289 // Verify that tha callingPackage belongs to the calling UID
10290 mApp.getSystemService(AppOpsManager.class)
10291 .checkPackage(callingUid, callingPackage);
10292
10293 final long identity = Binder.clearCallingIdentity();
10294 try {
10295 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10296 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10297
10298 if (result instanceof IllegalStateException) {
10299 throw (IllegalStateException) result;
10300 }
10301 } finally {
10302 Binder.restoreCallingIdentity(identity);
10303 }
10304 }
10305
10306 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10307 int callingUid) {
10308 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10309 // phone/system process do not have further restriction on request
10310 return;
10311 }
10312
10313 // Applications has restrictions on how to use the request:
10314 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10315 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10316 // This is not system caller which has been checked above
10317 throw new IllegalArgumentException(
10318 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10319 }
10320
10321 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10322 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10323 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10324 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10325 || info.isEnabled()) {
10326 throw new IllegalArgumentException(
10327 "Only system can set hide fields in SignalThresholdInfo");
10328 }
10329
10330 // Thresholds length for each RAN need in range. This has been validated in
10331 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10332 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10333 final int[] thresholds = info.getThresholds();
10334 Objects.requireNonNull(thresholds);
10335 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10336 || thresholds.length
10337 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10338 throw new IllegalArgumentException(
10339 "thresholds length is out of range: " + thresholds.length);
10340 }
10341 }
10342 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010343
10344 /**
10345 * Prepare TelephonyManager for an unattended reboot. The reboot is
10346 * required to be done shortly after the API is invoked.
10347 */
10348 @Override
10349 @TelephonyManager.PrepareUnattendedRebootResult
10350 public int prepareForUnattendedReboot() {
10351 enforceRebootPermission();
10352
10353 final long identity = Binder.clearCallingIdentity();
10354 try {
10355 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10356 } finally {
10357 Binder.restoreCallingIdentity(identity);
10358 }
10359 }
SongFerngWang2c4309d2021-01-17 21:51:44 +080010360
10361 /**
10362 * Gets the current phone capability.
10363 *
10364 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10365 * @return the PhoneCapability which describes the data connection capability of modem.
10366 * It's used to evaluate possible phone config change, for example from single
10367 * SIM device to multi-SIM device.
10368 */
10369 @Override
10370 public PhoneCapability getPhoneCapability() {
10371 enforceReadPrivilegedPermission("getPhoneCapability");
10372 final long identity = Binder.clearCallingIdentity();
10373 try {
10374 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10375 } finally {
10376 Binder.restoreCallingIdentity(identity);
10377 }
10378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010379}