blob: 5cd6297647d632265653d3692d0585b2296b154f [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
1229 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1230 ar = (AsyncResult) msg.obj;
1231 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001232 ResultReceiver result = (ResultReceiver) request.argument;
1233
Hall Liue8315982020-10-09 19:00:11 -07001234 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0,
1235 new int[ModemActivityInfo.getNumTxPowerLevels()], 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");
1265 } else if (ar.exception instanceof CommandException) {
1266 loge("queryModemActivityInfo: CommandException: " +
1267 ar.exception);
1268 } else {
1269 loge("queryModemActivityInfo: Unknown exception");
1270 }
1271 }
sqian1a1be542020-03-05 11:37:28 -08001272 Bundle bundle = new Bundle();
1273 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1274 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001275 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001276 break;
1277
Meng Wang1a7c35a2016-05-05 20:56:15 -07001278 case CMD_SET_ALLOWED_CARRIERS:
1279 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001280 CarrierRestrictionRules argument =
1281 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001282 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001283 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001284 break;
1285
1286 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1287 ar = (AsyncResult) msg.obj;
1288 request = (MainThreadRequest) ar.userObj;
1289 if (ar.exception == null && ar.result != null) {
1290 request.result = ar.result;
1291 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001292 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1293 if (ar.exception instanceof CommandException) {
1294 loge("setAllowedCarriers: CommandException: " + ar.exception);
1295 CommandException.Error error =
1296 ((CommandException) (ar.exception)).getCommandError();
1297 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1298 request.result =
1299 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1300 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001301 } else {
1302 loge("setAllowedCarriers: Unknown exception");
1303 }
1304 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001305 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001306 break;
1307
1308 case CMD_GET_ALLOWED_CARRIERS:
1309 request = (MainThreadRequest) msg.obj;
1310 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001311 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001312 break;
1313
1314 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1315 ar = (AsyncResult) msg.obj;
1316 request = (MainThreadRequest) ar.userObj;
1317 if (ar.exception == null && ar.result != null) {
1318 request.result = ar.result;
1319 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001320 request.result = new IllegalStateException(
1321 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001322 if (ar.result == null) {
1323 loge("getAllowedCarriers: Empty response");
1324 } else if (ar.exception instanceof CommandException) {
1325 loge("getAllowedCarriers: CommandException: " +
1326 ar.exception);
1327 } else {
1328 loge("getAllowedCarriers: Unknown exception");
1329 }
1330 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001331 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001332 break;
1333
Nathan Haroldb3014052017-01-25 15:57:32 -08001334 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1335 ar = (AsyncResult) msg.obj;
1336 request = (MainThreadRequest) ar.userObj;
1337 if (ar.exception == null && ar.result != null) {
1338 request.result = ar.result;
1339 } else {
1340 request.result = new IllegalArgumentException(
1341 "Failed to retrieve Forbidden Plmns");
1342 if (ar.result == null) {
1343 loge("getForbiddenPlmns: Empty response");
1344 } else {
1345 loge("getForbiddenPlmns: Unknown exception");
1346 }
1347 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001348 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001349 break;
1350
1351 case CMD_GET_FORBIDDEN_PLMNS:
1352 request = (MainThreadRequest) msg.obj;
1353 uiccCard = getUiccCardFromRequest(request);
1354 if (uiccCard == null) {
1355 loge("getForbiddenPlmns() UiccCard is null");
1356 request.result = new IllegalArgumentException(
1357 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001358 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001359 break;
1360 }
1361 Integer appType = (Integer) request.argument;
1362 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1363 if (uiccApp == null) {
1364 loge("getForbiddenPlmns() no app with specified type -- "
1365 + appType);
1366 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001367 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001368 break;
1369 } else {
1370 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1371 + " specified type -- " + appType);
1372 }
1373 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1374 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1375 onCompleted);
1376 break;
1377
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001378 case CMD_SWITCH_SLOTS:
1379 request = (MainThreadRequest) msg.obj;
1380 int[] physicalSlots = (int[]) request.argument;
1381 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1382 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1383 break;
1384
1385 case EVENT_SWITCH_SLOTS_DONE:
1386 ar = (AsyncResult) msg.obj;
1387 request = (MainThreadRequest) ar.userObj;
1388 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001389 notifyRequester(request);
1390 break;
1391 case CMD_GET_NETWORK_SELECTION_MODE:
1392 request = (MainThreadRequest) msg.obj;
1393 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1394 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1395 break;
1396
1397 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1398 ar = (AsyncResult) msg.obj;
1399 request = (MainThreadRequest) ar.userObj;
1400 if (ar.exception != null) {
1401 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1402 } else {
1403 int mode = ((int[]) ar.result)[0];
1404 if (mode == 0) {
1405 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1406 } else {
1407 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1408 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001409 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001410 notifyRequester(request);
1411 break;
1412 case CMD_GET_CDMA_ROAMING_MODE:
1413 request = (MainThreadRequest) msg.obj;
1414 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1415 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1416 break;
1417 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1418 ar = (AsyncResult) msg.obj;
1419 request = (MainThreadRequest) ar.userObj;
1420 if (ar.exception != null) {
1421 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1422 } else {
1423 request.result = ((int[]) ar.result)[0];
1424 }
1425 notifyRequester(request);
1426 break;
1427 case CMD_SET_CDMA_ROAMING_MODE:
1428 request = (MainThreadRequest) msg.obj;
1429 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1430 int mode = (int) request.argument;
1431 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1432 break;
1433 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1434 ar = (AsyncResult) msg.obj;
1435 request = (MainThreadRequest) ar.userObj;
1436 request.result = ar.exception == null;
1437 notifyRequester(request);
1438 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001439 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1440 request = (MainThreadRequest) msg.obj;
1441 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1442 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1443 break;
1444 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1445 ar = (AsyncResult) msg.obj;
1446 request = (MainThreadRequest) ar.userObj;
1447 if (ar.exception != null) {
1448 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1449 } else {
1450 request.result = ((int[]) ar.result)[0];
1451 }
1452 notifyRequester(request);
1453 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001454 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1455 request = (MainThreadRequest) msg.obj;
1456 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1457 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001458 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1459 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001460 break;
1461 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1462 ar = (AsyncResult) msg.obj;
1463 request = (MainThreadRequest) ar.userObj;
1464 request.result = ar.exception == null;
1465 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001466 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001467 case CMD_GET_ALL_CELL_INFO:
1468 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001469 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001470 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001471 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001472 case EVENT_GET_ALL_CELL_INFO_DONE:
1473 ar = (AsyncResult) msg.obj;
1474 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001475 // If a timeout occurs, the response will be null
1476 request.result = (ar.exception == null && ar.result != null)
1477 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001478 synchronized (request) {
1479 request.notifyAll();
1480 }
1481 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001482 case CMD_REQUEST_CELL_INFO_UPDATE:
1483 request = (MainThreadRequest) msg.obj;
1484 request.phone.requestCellInfoUpdate(request.workSource,
1485 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1486 break;
1487 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1488 ar = (AsyncResult) msg.obj;
1489 request = (MainThreadRequest) ar.userObj;
1490 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1491 try {
1492 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001493 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001494 cb.onError(
1495 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1496 ar.exception.getClass().getName(),
1497 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001498 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001499 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001500 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001501 } else {
1502 // use the result as returned
1503 cb.onCellInfo((List<CellInfo>) ar.result);
1504 }
1505 } catch (RemoteException re) {
1506 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1507 }
1508 break;
Sarah Chincc055732020-11-18 13:39:35 -08001509 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001510 request = (MainThreadRequest) msg.obj;
1511 WorkSource ws = (WorkSource) request.argument;
1512 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001513 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001514 break;
Sarah Chincc055732020-11-18 13:39:35 -08001515 }
1516 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001517 ar = (AsyncResult) msg.obj;
1518 request = (MainThreadRequest) ar.userObj;
1519 if (ar.exception == null) {
1520 request.result = ar.result;
1521 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001522 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001523 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001524 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001525 }
1526
1527 synchronized (request) {
1528 request.notifyAll();
1529 }
1530 break;
Sarah Chincc055732020-11-18 13:39:35 -08001531 }
chen xu6dac5ab2018-10-26 17:39:23 -07001532 case CMD_MODEM_REBOOT:
1533 request = (MainThreadRequest) msg.obj;
1534 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001535 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001536 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001537 case EVENT_CMD_MODEM_REBOOT_DONE:
1538 handleNullReturnEvent(msg, "rebootModem");
1539 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001540 case CMD_REQUEST_ENABLE_MODEM:
1541 request = (MainThreadRequest) msg.obj;
1542 boolean enable = (boolean) request.argument;
1543 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001544 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001545 PhoneConfigurationManager.getInstance()
1546 .enablePhone(request.phone, enable, onCompleted);
1547 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001548 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001552 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001553 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001554 if ((boolean) request.result) {
1555 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1556 updateModemStateMetrics();
1557 } else {
1558 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1559 + ar.exception);
1560 }
1561 notifyRequester(request);
1562 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001563 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001564 case CMD_GET_MODEM_STATUS:
1565 request = (MainThreadRequest) msg.obj;
1566 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1567 PhoneConfigurationManager.getInstance()
1568 .getPhoneStatusFromModem(request.phone, onCompleted);
1569 break;
1570 case EVENT_GET_MODEM_STATUS_DONE:
1571 ar = (AsyncResult) msg.obj;
1572 request = (MainThreadRequest) ar.userObj;
1573 int id = request.phone.getPhoneId();
1574 if (ar.exception == null && ar.result != null) {
1575 request.result = ar.result;
1576 //update the cache as modem status has changed
1577 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1578 (boolean) request.result);
1579 } else {
1580 // Return true if modem status cannot be retrieved. For most cases,
1581 // modem status is on. And for older version modems, GET_MODEM_STATUS
1582 // and disable modem are not supported. Modem is always on.
1583 // TODO: this should be fixed in R to support a third
1584 // status UNKNOWN b/131631629
1585 request.result = true;
1586 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1587 + ar.exception);
1588 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001589 notifyRequester(request);
1590 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001591 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1592 request = (MainThreadRequest) msg.obj;
1593 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1594 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1595 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1596 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1597 break;
1598 }
1599 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1600 ar = (AsyncResult) msg.obj;
1601 request = (MainThreadRequest) ar.userObj;
1602 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1603 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1604 args.second.accept(ar.exception == null);
1605 notifyRequester(request);
1606 break;
1607 }
Sarah Chincc055732020-11-18 13:39:35 -08001608 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1609 request = (MainThreadRequest) msg.obj;
1610 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1611 Phone phone = getPhoneFromRequest(request);
1612 if (phone != null) {
1613 phone.getSystemSelectionChannels(onCompleted);
1614 } else {
1615 loge("getSystemSelectionChannels: No phone object");
1616 request.result = new ArrayList<RadioAccessSpecifier>();
1617 notifyRequester(request);
1618 }
1619 break;
1620 }
1621 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1622 ar = (AsyncResult) msg.obj;
1623 request = (MainThreadRequest) ar.userObj;
1624 if (ar.exception == null && ar.result != null) {
1625 request.result = ar.result;
1626 } else {
Sarah Chin58691872021-03-13 03:17:40 -08001627 request.result = new IllegalStateException(
1628 "Failed to retrieve system selecton channels");
Sarah Chincc055732020-11-18 13:39:35 -08001629 if (ar.result == null) {
1630 loge("getSystemSelectionChannels: Empty response");
1631 } else {
1632 loge("getSystemSelectionChannels: Unknown exception");
1633 }
1634 }
1635 notifyRequester(request);
1636 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001637 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1638 ar = (AsyncResult) msg.obj;
1639 request = (MainThreadRequest) ar.userObj;
1640 if (ar.exception == null && ar.result != null) {
1641 request.result = ar.result;
1642 } else {
1643 request.result = -1;
1644 loge("Failed to set Forbidden Plmns");
1645 if (ar.result == null) {
1646 loge("setForbidenPlmns: Empty response");
1647 } else if (ar.exception != null) {
1648 loge("setForbiddenPlmns: Exception: " + ar.exception);
1649 request.result = -1;
1650 } else {
1651 loge("setForbiddenPlmns: Unknown exception");
1652 }
1653 }
1654 notifyRequester(request);
1655 break;
1656 case CMD_SET_FORBIDDEN_PLMNS:
1657 request = (MainThreadRequest) msg.obj;
1658 uiccCard = getUiccCardFromRequest(request);
1659 if (uiccCard == null) {
1660 loge("setForbiddenPlmns: UiccCard is null");
1661 request.result = -1;
1662 notifyRequester(request);
1663 break;
1664 }
1665 Pair<Integer, List<String>> setFplmnsArgs =
1666 (Pair<Integer, List<String>>) request.argument;
1667 appType = setFplmnsArgs.first;
1668 List<String> fplmns = setFplmnsArgs.second;
1669 uiccApp = uiccCard.getApplicationByType(appType);
1670 if (uiccApp == null) {
1671 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1672 request.result = -1;
1673 loge("Failed to get UICC App");
1674 notifyRequester(request);
1675 } else {
1676 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1677 ((SIMRecords) uiccApp.getIccRecords())
1678 .setForbiddenPlmns(onCompleted, fplmns);
1679 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001680 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001681 case CMD_ERASE_MODEM_CONFIG:
1682 request = (MainThreadRequest) msg.obj;
1683 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1684 defaultPhone.eraseModemConfig(onCompleted);
1685 break;
1686 case EVENT_ERASE_MODEM_CONFIG_DONE:
1687 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001688 break;
zoey chenf95ca592019-12-30 16:11:23 +08001689
1690 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1691 request = (MainThreadRequest) msg.obj;
1692 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1693 Pair<String, String> changed = (Pair<String, String>) request.argument;
1694 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1695 changed.first, changed.second, onCompleted);
1696 break;
1697 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1698 ar = (AsyncResult) msg.obj;
1699 request = (MainThreadRequest) ar.userObj;
1700 if (ar.exception == null) {
1701 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001702 // If the operation is successful, update the PIN storage
1703 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1704 int phoneId = getPhoneFromRequest(request).getPhoneId();
1705 UiccController.getInstance().getPinStorage()
1706 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001707 } else {
1708 request.result = msg.arg1;
1709 }
1710 notifyRequester(request);
1711 break;
1712
Michele Berionned9fbae52020-11-13 02:36:59 +00001713 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001714 request = (MainThreadRequest) msg.obj;
1715 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1716 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1717 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1718 enabled.first, enabled.second, onCompleted);
1719 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001720 }
zoey chenf95ca592019-12-30 16:11:23 +08001721 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1722 ar = (AsyncResult) msg.obj;
1723 request = (MainThreadRequest) ar.userObj;
1724 if (ar.exception == null) {
1725 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001726 // If the operation is successful, update the PIN storage
1727 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1728 int phoneId = getPhoneFromRequest(request).getPhoneId();
1729 if (enabled.first) {
1730 UiccController.getInstance().getPinStorage()
1731 .storePin(enabled.second, phoneId);
1732 } else {
1733 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1734 }
zoey chenf95ca592019-12-30 16:11:23 +08001735 } else {
1736 request.result = msg.arg1;
1737 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001738
1739
zoey chenf95ca592019-12-30 16:11:23 +08001740 notifyRequester(request);
1741 break;
1742
Peter Wangdafb9ac2020-01-15 14:13:38 -08001743 case MSG_NOTIFY_USER_ACTIVITY:
1744 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001745 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001746 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1747 getDefaultPhone().getContext().sendBroadcastAsUser(
1748 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1749 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001750
1751 case CMD_SET_DATA_THROTTLING: {
1752 request = (MainThreadRequest) msg.obj;
1753 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1754 DataThrottlingRequest dataThrottlingRequest =
1755 (DataThrottlingRequest) request.argument;
1756 Phone phone = getPhoneFromRequest(request);
1757 if (phone != null) {
1758 phone.setDataThrottling(onCompleted,
1759 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1760 dataThrottlingRequest.getCompletionDurationMillis());
1761 } else {
1762 loge("setDataThrottling: No phone object");
1763 request.result =
1764 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1765 notifyRequester(request);
1766 }
1767
1768 break;
1769 }
1770 case EVENT_SET_DATA_THROTTLING_DONE:
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773
1774 if (ar.exception == null) {
1775 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1776 } else if (ar.exception instanceof CommandException) {
1777 loge("setDataThrottling: CommandException: " + ar.exception);
1778 CommandException.Error error =
1779 ((CommandException) (ar.exception)).getCommandError();
1780
1781 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1782 request.result = TelephonyManager
1783 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1784 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1785 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001786 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1787 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001788 } else {
1789 request.result =
1790 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1791 }
1792 } else {
1793 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1794 }
1795 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1796 notifyRequester(request);
1797 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001798
1799 case CMD_SET_SIM_POWER: {
1800 request = (MainThreadRequest) msg.obj;
1801 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1802 request = (MainThreadRequest) msg.obj;
1803 int stateToSet =
1804 ((Pair<Integer, IIntegerConsumer>)
1805 request.argument).first;
1806 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1807 break;
1808 }
1809 case EVENT_SET_SIM_POWER_DONE: {
1810 ar = (AsyncResult) msg.obj;
1811 request = (MainThreadRequest) ar.userObj;
1812 IIntegerConsumer callback =
1813 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1814 if (ar.exception != null) {
1815 loge("setSimPower exception: " + ar.exception);
1816 int errorCode = TelephonyManager.CallForwardingInfoCallback
1817 .RESULT_ERROR_UNKNOWN;
1818 if (ar.exception instanceof CommandException) {
1819 CommandException.Error error =
1820 ((CommandException) (ar.exception)).getCommandError();
1821 if (error == CommandException.Error.SIM_ERR) {
1822 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1823 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1824 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1825 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1826 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1827 } else {
1828 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1829 }
1830 }
1831 try {
1832 callback.accept(errorCode);
1833 } catch (RemoteException e) {
1834 // Ignore if the remote process is no longer available to call back.
1835 Log.w(LOG_TAG, "setSimPower: callback not available.");
1836 }
1837 } else {
1838 try {
1839 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1840 } catch (RemoteException e) {
1841 // Ignore if the remote process is no longer available to call back.
1842 Log.w(LOG_TAG, "setSimPower: callback not available.");
1843 }
1844 }
1845 break;
1846 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001847 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1848 request = (MainThreadRequest) msg.obj;
1849
1850 final Phone phone = getPhoneFromRequest(request);
1851 if (phone == null || phone.getServiceStateTracker() == null) {
1852 request.result = new IllegalStateException("Phone or SST is null");
1853 notifyRequester(request);
1854 break;
1855 }
1856
1857 Pair<Integer, SignalStrengthUpdateRequest> pair =
1858 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1859 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1860 request);
1861 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1862 request.subId, pair.first /*callingUid*/,
1863 pair.second /*request*/, onCompleted);
1864 break;
1865 }
1866 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1867 ar = (AsyncResult) msg.obj;
1868 request = (MainThreadRequest) ar.userObj;
1869 // request.result will be the exception of ar if present, true otherwise.
1870 // Be cautious not to leave result null which will wait() forever
1871 request.result = ar.exception != null ? ar.exception : true;
1872 notifyRequester(request);
1873 break;
1874 }
1875 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1876 request = (MainThreadRequest) msg.obj;
1877
1878 Phone phone = getPhoneFromRequest(request);
1879 if (phone == null || phone.getServiceStateTracker() == null) {
1880 request.result = new IllegalStateException("Phone or SST is null");
1881 notifyRequester(request);
1882 break;
1883 }
1884
1885 Pair<Integer, SignalStrengthUpdateRequest> pair =
1886 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1887 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1888 request);
1889 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1890 request.subId, pair.first /*callingUid*/,
1891 pair.second /*request*/, onCompleted);
1892 break;
1893 }
1894 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1895 ar = (AsyncResult) msg.obj;
1896 request = (MainThreadRequest) ar.userObj;
1897 request.result = ar.exception != null ? ar.exception : true;
1898 notifyRequester(request);
1899 break;
1900 }
Jordan Liud5366d92020-11-24 14:50:34 -08001901
Michele Berionned9fbae52020-11-13 02:36:59 +00001902 case CMD_PREPARE_UNATTENDED_REBOOT:
1903 request = (MainThreadRequest) msg.obj;
1904 request.result =
1905 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1906 notifyRequester(request);
1907 break;
1908
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 default:
1910 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1911 break;
1912 }
1913 }
Jake Hambye994d462014-02-03 13:10:13 -08001914
Pengquan Menga1bb6272018-09-06 09:59:22 -07001915 private void notifyRequester(MainThreadRequest request) {
1916 synchronized (request) {
1917 request.notifyAll();
1918 }
1919 }
1920
Jake Hambye994d462014-02-03 13:10:13 -08001921 private void handleNullReturnEvent(Message msg, String command) {
1922 AsyncResult ar = (AsyncResult) msg.obj;
1923 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1924 if (ar.exception == null) {
1925 request.result = true;
1926 } else {
1927 request.result = false;
1928 if (ar.exception instanceof CommandException) {
1929 loge(command + ": CommandException: " + ar.exception);
1930 } else {
1931 loge(command + ": Unknown exception");
1932 }
1933 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001934 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
1938 /**
1939 * Posts the specified command to be executed on the main thread,
1940 * waits for the request to complete, and returns the result.
1941 * @see #sendRequestAsync
1942 */
1943 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001944 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1945 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001946 }
1947
1948 /**
1949 * Posts the specified command to be executed on the main thread,
1950 * waits for the request to complete, and returns the result.
1951 * @see #sendRequestAsync
1952 */
1953 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1954 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001955 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001956 }
1957
1958 /**
1959 * Posts the specified command to be executed on the main thread,
1960 * waits for the request to complete, and returns the result.
1961 * @see #sendRequestAsync
1962 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001963 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001964 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1965 }
1966
1967 /**
1968 * Posts the specified command to be executed on the main thread,
1969 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1970 * if not timeout or null otherwise.
1971 * @see #sendRequestAsync
1972 */
1973 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1974 long timeoutInMs) {
1975 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001976 }
1977
1978 /**
1979 * Posts the specified command to be executed on the main thread,
1980 * waits for the request to complete, and returns the result.
1981 * @see #sendRequestAsync
1982 */
Nathan Harold92bed182018-10-12 18:16:49 -07001983 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001984 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001985 }
1986
1987 /**
1988 * Posts the specified command to be executed on the main thread,
1989 * waits for the request to complete, and returns the result.
1990 * @see #sendRequestAsync
1991 */
1992 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001993 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1994 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001995 }
1996
1997 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001998 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1999 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2000 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002001 * @see #sendRequestAsync
2002 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002003 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2004 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2006 throw new RuntimeException("This method will deadlock if called from the main thread.");
2007 }
2008
Nathan Harold92bed182018-10-12 18:16:49 -07002009 MainThreadRequest request = null;
2010 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2011 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2012 } else if (phone != null) {
2013 request = new MainThreadRequest(argument, phone, workSource);
2014 } else {
2015 request = new MainThreadRequest(argument, subId, workSource);
2016 }
2017
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 Message msg = mMainThreadHandler.obtainMessage(command, request);
2019 msg.sendToTarget();
2020
Rambo Wang0f050d82021-02-12 11:43:36 -08002021
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002022 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002023 if (timeoutInMs >= 0) {
2024 // Wait for at least timeoutInMs before returning null request result
2025 long now = SystemClock.elapsedRealtime();
2026 long deadline = now + timeoutInMs;
2027 while (request == null && now < deadline) {
2028 try {
2029 request.wait(deadline - now);
2030 } catch (InterruptedException e) {
2031 // Do nothing, go back and check if request is completed or timeout
2032 } finally {
2033 now = SystemClock.elapsedRealtime();
2034 }
2035 }
2036 } else {
2037 // Wait for the request to complete
2038 while (request.result == null) {
2039 try {
2040 request.wait();
2041 } catch (InterruptedException e) {
2042 // Do nothing, go back and wait until the request is complete
2043 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 }
2045 }
2046 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002047 if (request.result == null) {
2048 Log.wtf(LOG_TAG,
2049 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2050 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 return request.result;
2052 }
2053
2054 /**
2055 * Asynchronous ("fire and forget") version of sendRequest():
2056 * Posts the specified command to be executed on the main thread, and
2057 * returns immediately.
2058 * @see #sendRequest
2059 */
2060 private void sendRequestAsync(int command) {
2061 mMainThreadHandler.sendEmptyMessage(command);
2062 }
2063
2064 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002065 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002066 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002067 */
2068 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002069 sendRequestAsync(command, argument, null, null);
2070 }
2071
2072 /**
2073 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2074 * @see {@link #sendRequest(int,Object)}
2075 */
2076 private void sendRequestAsync(
2077 int command, Object argument, Phone phone, WorkSource workSource) {
2078 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002079 Message msg = mMainThreadHandler.obtainMessage(command, request);
2080 msg.sendToTarget();
2081 }
2082
2083 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084 * Initialize the singleton PhoneInterfaceManager instance.
2085 * This is only done once, at startup, from PhoneApp.onCreate().
2086 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002087 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 synchronized (PhoneInterfaceManager.class) {
2089 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002090 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 } else {
2092 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2093 }
2094 return sInstance;
2095 }
2096 }
2097
2098 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002099 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerc9c432e2021-05-17 20:54:49 +00002102 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002103 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2105 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002106 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002107 mTelephonySharedPreferences =
2108 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002109 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002110 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002111 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002112 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002113
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 publish();
2115 }
2116
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002117 private Phone getDefaultPhone() {
2118 Phone thePhone = getPhone(getDefaultSubscription());
2119 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2120 }
2121
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 private void publish() {
2123 if (DBG) log("publish: " + this);
2124
Peter Wangc035ce42020-01-08 21:00:22 -08002125 TelephonyFrameworkInitializer
2126 .getTelephonyServiceManager()
2127 .getTelephonyServiceRegisterer()
2128 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 }
2130
Stuart Scott584921c2015-01-15 17:10:34 -08002131 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002132 if (request.phone != null) {
2133 return request.phone;
2134 } else {
2135 return getPhoneFromSubId(request.subId);
2136 }
2137 }
2138
2139 private Phone getPhoneFromSubId(int subId) {
2140 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2141 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002142 }
2143
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002144 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2145 Phone phone = getPhoneFromRequest(request);
2146 return phone == null ? null :
2147 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2148 }
2149
Wink Saville36469e72014-06-11 15:17:00 -07002150 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002151 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002152 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002155 private void sendEraseModemConfig(Phone phone) {
2156 if (phone != null) {
2157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2158 mApp, phone.getSubId(), "eraseModemConfig");
2159 final long identity = Binder.clearCallingIdentity();
2160 try {
2161 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2162 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2163 } finally {
2164 Binder.restoreCallingIdentity(identity);
2165 }
2166 }
2167 }
2168
Peter Wang050bb052020-01-13 23:33:09 -08002169 private boolean isImsAvailableOnDevice() {
2170 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2171 if (pm == null) {
2172 // For some reason package manger is not available.. This will fail internally anyway,
2173 // so do not throw error and allow.
2174 return true;
2175 }
2176 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2177 }
2178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002180 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002181 }
2182
Wink Savilleb564aae2014-10-23 10:18:09 -07002183 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 if (DBG) log("dial: " + number);
2185 // No permission check needed here: This is just a wrapper around the
2186 // ACTION_DIAL intent, which is available to any app since it puts up
2187 // the UI before it does anything.
2188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189 final long identity = Binder.clearCallingIdentity();
2190 try {
2191 String url = createTelUrl(number);
2192 if (url == null) {
2193 return;
2194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002196 // PENDING: should we just silently fail if phone is offhook or ringing?
2197 PhoneConstants.State state = mCM.getState(subId);
2198 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2199 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2200 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2201 mApp.startActivity(intent);
2202 }
2203 } finally {
2204 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 }
2206 }
2207
2208 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002209 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002210 }
2211
Wink Savilleb564aae2014-10-23 10:18:09 -07002212 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 if (DBG) log("call: " + number);
2214
2215 // This is just a wrapper around the ACTION_CALL intent, but we still
2216 // need to do a permission check since we're calling startActivity()
2217 // from the context of the phone app.
2218 enforceCallPermission();
2219
Jordan Liu1617b712019-07-10 15:06:26 -07002220 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 != AppOpsManager.MODE_ALLOWED) {
2222 return;
2223 }
2224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002225 final long identity = Binder.clearCallingIdentity();
2226 try {
2227 String url = createTelUrl(number);
2228 if (url == null) {
2229 return;
2230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232 boolean isValid = false;
2233 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2234 if (slist != null) {
2235 for (SubscriptionInfo subInfoRecord : slist) {
2236 if (subInfoRecord.getSubscriptionId() == subId) {
2237 isValid = true;
2238 break;
2239 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002240 }
Wink Saville08874612014-08-31 19:19:58 -07002241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 if (!isValid) {
2243 return;
2244 }
Wink Saville08874612014-08-31 19:19:58 -07002245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002246 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2247 intent.putExtra(SUBSCRIPTION_KEY, subId);
2248 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2249 mApp.startActivity(intent);
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
2252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
Wink Savilleb564aae2014-10-23 10:18:09 -07002255 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002256 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002257 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2258 }
2259
Wink Savilleb564aae2014-10-23 10:18:09 -07002260 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002261 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002262 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2263 }
2264
Wink Savilleb564aae2014-10-23 10:18:09 -07002265 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002267
2268 final long identity = Binder.clearCallingIdentity();
2269 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002270 Phone phone = getPhone(subId);
2271 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002272 checkSimPin.start();
2273 return checkSimPin.unlockSim(null, pin);
2274 } finally {
2275 Binder.restoreCallingIdentity(identity);
2276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 }
2278
Wink Savilleb564aae2014-10-23 10:18:09 -07002279 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002281
2282 final long identity = Binder.clearCallingIdentity();
2283 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002284 Phone phone = getPhone(subId);
2285 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286 checkSimPuk.start();
2287 return checkSimPuk.unlockSim(puk, pin);
2288 } finally {
2289 Binder.restoreCallingIdentity(identity);
2290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 }
2292
2293 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002294 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 * a synchronous one.
2296 */
2297 private static class UnlockSim extends Thread {
2298
2299 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002300 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301
2302 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002303 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2304 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305
2306 // For replies from SimCard interface
2307 private Handler mHandler;
2308
2309 // For async handler to identify request type
2310 private static final int SUPPLY_PIN_COMPLETE = 100;
2311
Michele Berionned9fbae52020-11-13 02:36:59 +00002312 UnlockSim(int phoneId, IccCard simCard) {
2313 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 mSimCard = simCard;
2315 }
2316
2317 @Override
2318 public void run() {
2319 Looper.prepare();
2320 synchronized (UnlockSim.this) {
2321 mHandler = new Handler() {
2322 @Override
2323 public void handleMessage(Message msg) {
2324 AsyncResult ar = (AsyncResult) msg.obj;
2325 switch (msg.what) {
2326 case SUPPLY_PIN_COMPLETE:
2327 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2328 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002329 mRetryCount = msg.arg1;
2330 if (ar.exception != null) {
2331 if (ar.exception instanceof CommandException &&
2332 ((CommandException)(ar.exception)).getCommandError()
2333 == CommandException.Error.PASSWORD_INCORRECT) {
2334 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002335 } //When UiccCardApp dispose,handle message and return exception
2336 else if (ar.exception instanceof CommandException &&
2337 ((CommandException) (ar.exception)).getCommandError()
2338 == CommandException.Error.ABORTED) {
2339 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002340 } else {
2341 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2342 }
2343 } else {
2344 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 mDone = true;
2347 UnlockSim.this.notifyAll();
2348 }
2349 break;
2350 }
2351 }
2352 };
2353 UnlockSim.this.notifyAll();
2354 }
2355 Looper.loop();
2356 }
2357
2358 /*
2359 * Use PIN or PUK to unlock SIM card
2360 *
2361 * If PUK is null, unlock SIM card with PIN
2362 *
2363 * If PUK is not null, unlock SIM card with PUK and set PIN code
2364 */
Wink Saville9de0f752013-10-22 19:04:03 -07002365 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366
2367 while (mHandler == null) {
2368 try {
2369 wait();
2370 } catch (InterruptedException e) {
2371 Thread.currentThread().interrupt();
2372 }
2373 }
2374 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2375
2376 if (puk == null) {
2377 mSimCard.supplyPin(pin, callback);
2378 } else {
2379 mSimCard.supplyPuk(puk, pin, callback);
2380 }
2381
2382 while (!mDone) {
2383 try {
2384 Log.d(LOG_TAG, "wait for done");
2385 wait();
2386 } catch (InterruptedException e) {
2387 // Restore the interrupted status
2388 Thread.currentThread().interrupt();
2389 }
2390 }
2391 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002392 int[] resultArray = new int[2];
2393 resultArray[0] = mResult;
2394 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002395
2396 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2397 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2398 }
2399
Wink Saville9de0f752013-10-22 19:04:03 -07002400 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
2402 }
2403
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002404 /**
2405 * This method has been removed due to privacy and stability concerns.
2406 */
2407 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002409 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2410 return;
Wink Saville36469e72014-06-11 15:17:00 -07002411 }
2412
Nathan Harold1f889d82020-06-04 17:05:26 -07002413 @Override
2414 public void updateServiceLocationWithPackageName(String callingPackage) {
2415 mApp.getSystemService(AppOpsManager.class)
2416 .checkPackage(Binder.getCallingUid(), callingPackage);
2417
Nathan Haroldf096d982020-11-18 17:18:06 -08002418 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002419 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2420 // Callers targeting S have no business invoking this method.
2421 return;
2422 }
2423
2424 LocationAccessPolicy.LocationPermissionResult locationResult =
2425 LocationAccessPolicy.checkLocationPermission(mApp,
2426 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2427 .setCallingPackage(callingPackage)
2428 .setCallingFeatureId(null)
2429 .setCallingPid(Binder.getCallingPid())
2430 .setCallingUid(Binder.getCallingUid())
2431 .setMethod("updateServiceLocation")
2432 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2433 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2434 .build());
2435 // Apps that lack location permission have no business calling this method;
2436 // however, because no permission was declared in the public API, denials must
2437 // all be "soft".
2438 switch (locationResult) {
2439 case DENIED_HARD: /* fall through */
2440 case DENIED_SOFT:
2441 return;
2442 }
2443
2444 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 final long identity = Binder.clearCallingIdentity();
2446 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002447 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002449 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450 }
2451 } finally {
2452 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 }
2455
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002456 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002457 @Override
2458 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002459 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002460 }
2461
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002462
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002463 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002464 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2465 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2466 callingFeatureId);
2467 }
2468
2469 @Deprecated
2470 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002471 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002472 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2473 }
2474
2475 @Override
2476 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2477 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002478 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002479 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002480 return false;
2481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482
2483 final long identity = Binder.clearCallingIdentity();
2484 try {
2485 return isRadioOnForSubscriber(subId);
2486 } finally {
2487 Binder.restoreCallingIdentity(identity);
2488 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002489 }
2490
2491 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 final Phone phone = getPhone(subId);
2495 if (phone != null) {
2496 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2497 } else {
2498 return false;
2499 }
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002503 }
2504
2505 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002506 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 }
Wink Saville36469e72014-06-11 15:17:00 -07002508
Wink Savilleb564aae2014-10-23 10:18:09 -07002509 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511
2512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 final Phone phone = getPhone(subId);
2515 if (phone != null) {
2516 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2517 }
2518 } finally {
2519 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002520 }
Wink Saville36469e72014-06-11 15:17:00 -07002521 }
2522
2523 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002524 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002525 }
2526
Wink Savilleb564aae2014-10-23 10:18:09 -07002527 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002528 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529
2530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 final Phone phone = getPhone(subId);
2533 if (phone == null) {
2534 return false;
2535 }
2536 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2537 toggleRadioOnOffForSubscriber(subId);
2538 }
2539 return true;
2540 } finally {
2541 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002543 }
Wink Saville36469e72014-06-11 15:17:00 -07002544
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002545 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002546 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002547 /*
2548 * If any of the Radios are available, it will need to be
2549 * shutdown. So return true if any Radio is available.
2550 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002551 final long identity = Binder.clearCallingIdentity();
2552 try {
2553 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2554 Phone phone = PhoneFactory.getPhone(i);
2555 if (phone != null && phone.isRadioAvailable()) return true;
2556 }
2557 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2558 return false;
2559 } finally {
2560 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002561 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002562 }
2563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002565 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566 enforceModifyPermission();
2567
2568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2571 logv("Shutting down Phone " + i);
2572 shutdownRadioUsingPhoneId(i);
2573 }
2574 } finally {
2575 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002576 }
2577 }
2578
2579 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002580 Phone phone = PhoneFactory.getPhone(phoneId);
2581 if (phone != null && phone.isRadioAvailable()) {
2582 phone.shutdownRadio();
2583 }
2584 }
2585
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002587 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588
2589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2592 if (defaultPhone != null) {
2593 defaultPhone.setRadioPower(turnOn);
2594 return true;
2595 } else {
2596 loge("There's no default phone.");
2597 return false;
2598 }
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002601 }
Wink Saville36469e72014-06-11 15:17:00 -07002602 }
2603
Wink Savilleb564aae2014-10-23 10:18:09 -07002604 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606
2607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 final Phone phone = getPhone(subId);
2610 if (phone != null) {
2611 phone.setRadioPower(turnOn);
2612 return true;
2613 } else {
2614 return false;
2615 }
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 }
2620
Wink Saville36469e72014-06-11 15:17:00 -07002621 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002622 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623 public boolean enableDataConnectivity() {
2624 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625
2626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 int subId = mSubscriptionController.getDefaultDataSubId();
2629 final Phone phone = getPhone(subId);
2630 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002631 phone.getDataEnabledSettings().setDataEnabled(
2632 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633 return true;
2634 } else {
2635 return false;
2636 }
2637 } finally {
2638 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640 }
2641
Wink Saville36469e72014-06-11 15:17:00 -07002642 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002643 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002644 public boolean disableDataConnectivity() {
2645 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646
2647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 int subId = mSubscriptionController.getDefaultDataSubId();
2650 final Phone phone = getPhone(subId);
2651 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002652 phone.getDataEnabledSettings().setDataEnabled(
2653 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 return true;
2655 } else {
2656 return false;
2657 }
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 }
2662
Sanket Padawe356d7632015-06-22 14:03:32 -07002663 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002664 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
2668 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002669 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002670 } else {
2671 return false;
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
2678 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002679 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002680 }
2681
pkanwarae03a6b2016-11-06 20:37:09 -08002682 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 enforceCallPermission();
2684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2688 return;
2689 }
2690 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2691 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
2694 }
pkanwar32d516d2016-10-14 19:37:38 -07002695 };
2696
Wink Savilleb564aae2014-10-23 10:18:09 -07002697 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699
2700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2703 return false;
2704 }
2705 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002708 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 }
2710
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002711 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002712 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002713 }
2714
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002715 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 Phone phone = PhoneFactory.getPhone(slotIndex);
2719 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2720 PhoneConstantConversions.convertCallState(phone.getState());
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
2723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
2725
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002727 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002728 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2729 }
2730
2731 @Override
2732 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733 final long identity = Binder.clearCallingIdentity();
2734 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002735 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 if (phone != null) {
2737 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2738 } else {
2739 return PhoneConstantConversions.convertDataState(
2740 PhoneConstants.DataState.DISCONNECTED);
2741 }
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
2746
Sanket Padawe356d7632015-06-22 14:03:32 -07002747 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002748 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002749 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2750 }
2751
2752 @Override
2753 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754 final long identity = Binder.clearCallingIdentity();
2755 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002756 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757 if (phone != null) {
2758 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2759 } else {
2760 return TelephonyManager.DATA_ACTIVITY_NONE;
2761 }
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 }
2766
2767 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002768 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002769 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002770 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002771
2772 LocationAccessPolicy.LocationPermissionResult locationResult =
2773 LocationAccessPolicy.checkLocationPermission(mApp,
2774 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2775 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002776 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002777 .setCallingPid(Binder.getCallingPid())
2778 .setCallingUid(Binder.getCallingUid())
2779 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002780 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002781 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2782 .build());
2783 switch (locationResult) {
2784 case DENIED_HARD:
2785 throw new SecurityException("Not allowed to access cell location");
2786 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002787 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2788 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789 }
2790
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002791 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792 final long identity = Binder.clearCallingIdentity();
2793 try {
2794 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002795 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002796 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797 } finally {
2798 Binder.restoreCallingIdentity(identity);
2799 }
Svetoslav64fad262015-04-14 14:35:21 -07002800 }
2801
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802 @Override
Jack Yu01425032020-02-22 19:38:58 -08002803 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002804 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2805 // registered cell info, so return a NULL country instead.
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002808 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2809 // Get default phone in this case.
2810 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2811 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002812 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002814 if (phone == null) return "";
2815 ServiceStateTracker sst = phone.getServiceStateTracker();
2816 if (sst == null) return "";
2817 LocaleTracker lt = sst.getLocaleTracker();
2818 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002819 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002820 } finally {
2821 Binder.restoreCallingIdentity(identity);
2822 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002823 }
2824
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002825 /**
2826 * This method was removed due to potential issues caused by performing partial
2827 * updates of service state, and lack of a credible use case.
2828 *
2829 * This has the ability to break the telephony implementation by disabling notification of
2830 * changes in device connectivity. DO NOT USE THIS!
2831 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002832 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002833 public void enableLocationUpdates() {
2834 mApp.enforceCallingOrSelfPermission(
2835 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002836 }
2837
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002838 /**
2839 * This method was removed due to potential issues caused by performing partial
2840 * updates of service state, and lack of a credible use case.
2841 *
2842 * This has the ability to break the telephony implementation by disabling notification of
2843 * changes in device connectivity. DO NOT USE THIS!
2844 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 @Override
2846 public void disableLocationUpdates() {
2847 mApp.enforceCallingOrSelfPermission(
2848 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 }
2850
2851 @Override
2852 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002853 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2854 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002855 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002856 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2857 throw new SecurityException(
2858 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2859 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002860
Jordan Liu1617b712019-07-10 15:06:26 -07002861 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2863 return null;
2864 }
Svetoslav64fad262015-04-14 14:35:21 -07002865
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002866 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002868 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002869 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002870
Nathan Haroldf180aac2018-06-01 18:43:55 -07002871 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2872 for (CellInfo ci : info) {
2873 if (ci instanceof CellInfoGsm) {
2874 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2875 } else if (ci instanceof CellInfoWcdma) {
2876 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002879 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002880 }
2881
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002882 private List<CellInfo> getCachedCellInfo() {
2883 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2884 for (Phone phone : PhoneFactory.getPhones()) {
2885 List<CellInfo> info = phone.getAllCellInfo();
2886 if (info != null) cellInfos.addAll(info);
2887 }
2888 return cellInfos;
2889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890
2891 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002892 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002893 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002894 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002895
2896 LocationAccessPolicy.LocationPermissionResult locationResult =
2897 LocationAccessPolicy.checkLocationPermission(mApp,
2898 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2899 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002900 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002901 .setCallingPid(Binder.getCallingPid())
2902 .setCallingUid(Binder.getCallingUid())
2903 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002904 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002905 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2906 .build());
2907 switch (locationResult) {
2908 case DENIED_HARD:
2909 throw new SecurityException("Not allowed to access cell info");
2910 case DENIED_SOFT:
2911 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 }
2913
Nathan Haroldf096d982020-11-18 17:18:06 -08002914 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002915 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2916 return getCachedCellInfo();
2917 }
2918
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002919 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002920 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921 final long identity = Binder.clearCallingIdentity();
2922 try {
2923 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2924 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002925 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002926 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 if (info != null) cellInfos.addAll(info);
2928 }
2929 return cellInfos;
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 }
2933 }
2934
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002935 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002936 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2937 String callingFeatureId) {
2938 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2939 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002940 }
2941
2942 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002943 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2944 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002945 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002946 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002947 }
2948
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002949 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2950 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002951 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002952 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002953
2954 LocationAccessPolicy.LocationPermissionResult locationResult =
2955 LocationAccessPolicy.checkLocationPermission(mApp,
2956 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2957 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002958 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002959 .setCallingPid(Binder.getCallingPid())
2960 .setCallingUid(Binder.getCallingUid())
2961 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002962 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2963 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002964 .build());
2965 switch (locationResult) {
2966 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002967 if (TelephonyPermissions
2968 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002969 // Safetynet logging for b/154934934
2970 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2971 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002972 throw new SecurityException("Not allowed to access cell info");
2973 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002974 if (TelephonyPermissions
2975 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002976 // Safetynet logging for b/154934934
2977 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2978 }
Nathan Harold5320c422019-05-09 10:26:08 -07002979 try {
2980 cb.onCellInfo(new ArrayList<CellInfo>());
2981 } catch (RemoteException re) {
2982 // Drop without consequences
2983 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002984 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002985 }
2986
Nathan Harolda939a962019-05-09 10:13:47 -07002987
2988 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002989 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2990
2991 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2992 }
2993
2994 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002995 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002996 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002997 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002998
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003001 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 }
3006
Shishir Agrawala9f32182016-04-12 12:00:16 -07003007 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003008 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003009 Phone phone = PhoneFactory.getPhone(slotIndex);
3010 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003011 return null;
3012 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003013 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003014 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003015 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003016 return null;
3017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 return phone.getImei();
3022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003025 }
3026
3027 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003028 public String getTypeAllocationCodeForSlot(int slotIndex) {
3029 Phone phone = PhoneFactory.getPhone(slotIndex);
3030 String tac = null;
3031 if (phone != null) {
3032 String imei = phone.getImei();
3033 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3034 }
3035 return tac;
3036 }
3037
3038 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003039 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003040 Phone phone = PhoneFactory.getPhone(slotIndex);
3041 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003042 return null;
3043 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003044
Jeff Davidson913390f2018-02-23 17:11:49 -08003045 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003046 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003047 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003048 return null;
3049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050
3051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 return phone.getMeid();
3054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
Jack Yu2af8d712017-03-15 17:14:14 -07003057 }
3058
3059 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003060 public String getManufacturerCodeForSlot(int slotIndex) {
3061 Phone phone = PhoneFactory.getPhone(slotIndex);
3062 String manufacturerCode = null;
3063 if (phone != null) {
3064 String meid = phone.getMeid();
3065 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3066 }
3067 return manufacturerCode;
3068 }
3069
3070 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003071 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3072 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003073 Phone phone = PhoneFactory.getPhone(slotIndex);
3074 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003075 return null;
3076 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003077 int subId = phone.getSubId();
3078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003079 mApp, subId, callingPackage, callingFeatureId,
3080 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003081 return null;
3082 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083
3084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 return phone.getDeviceSvn();
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003090 }
3091
fionaxu43304da2017-11-27 22:51:16 -08003092 @Override
3093 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 final Phone phone = getPhone(subId);
3097 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
fionaxu43304da2017-11-27 22:51:16 -08003101 }
3102
3103 @Override
3104 public String getSubscriptionCarrierName(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 ? null : phone.getCarrierName();
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
fionaxu43304da2017-11-27 22:51:16 -08003112 }
3113
calvinpanffe225e2018-11-01 19:43:06 +08003114 @Override
chen xu0026ca62019-03-06 15:28:50 -08003115 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 final Phone phone = getPhone(subId);
3119 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003120 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003121 } finally {
3122 Binder.restoreCallingIdentity(identity);
3123 }
3124 }
3125
3126 @Override
chen xu0026ca62019-03-06 15:28:50 -08003127 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003131 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
chen xu651eec72018-11-11 19:03:44 -08003137 @Override
chen xu864e11c2018-12-06 22:10:03 -08003138 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3139 if (!isSubscriptionMccMnc) {
3140 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3141 }
chen xu651eec72018-11-11 19:03:44 -08003142 final Phone phone = PhoneFactory.getPhone(slotIndex);
3143 if (phone == null) {
3144 return TelephonyManager.UNKNOWN_CARRIER_ID;
3145 }
3146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3149 } finally {
3150 Binder.restoreCallingIdentity(identity);
3151 }
3152 }
3153
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003154 //
3155 // Internal helper methods.
3156 //
3157
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003158 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003159 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3160 *
3161 * @throws SecurityException if the caller does not have the required permission
3162 */
3163 private void enforceModifyPermission() {
3164 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3165 }
3166
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003167 /**
3168 * Make sure the caller is system.
3169 *
3170 * @throws SecurityException if the caller is not system.
3171 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003172 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003173 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3174 throw new SecurityException("Caller must be system");
3175 }
3176 }
3177
Shuo Qianf2b2df42019-11-13 17:43:31 -08003178 private void enforceActiveEmergencySessionPermission() {
3179 mApp.enforceCallingOrSelfPermission(
3180 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3181 }
3182
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003183 /**
3184 * Make sure the caller has the CALL_PHONE permission.
3185 *
3186 * @throws SecurityException if the caller does not have the required permission
3187 */
3188 private void enforceCallPermission() {
3189 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3190 }
3191
paulhu423b5f22019-08-23 19:17:33 +08003192 private void enforceSettingsPermission() {
3193 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003194 }
3195
Michele Berionned9fbae52020-11-13 02:36:59 +00003196 private void enforceRebootPermission() {
3197 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3198 }
3199
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 private String createTelUrl(String number) {
3201 if (TextUtils.isEmpty(number)) {
3202 return null;
3203 }
3204
Jake Hambye994d462014-02-03 13:10:13 -08003205 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 }
3207
Ihab Awadf9e92732013-12-05 18:02:52 -08003208 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3210 }
3211
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003212 private static void logv(String msg) {
3213 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3214 }
3215
Ihab Awadf9e92732013-12-05 18:02:52 -08003216 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003217 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3218 }
3219
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003220 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003222 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003223 }
3224
Sanket Padawe356d7632015-06-22 14:03:32 -07003225 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003226 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003227 final long identity = Binder.clearCallingIdentity();
3228 try {
3229 final Phone phone = PhoneFactory.getPhone(slotIndex);
3230 if (phone == null) {
3231 return PhoneConstants.PHONE_TYPE_NONE;
3232 } else {
3233 return phone.getPhoneType();
3234 }
3235 } finally {
3236 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003238 }
3239
3240 /**
3241 * Returns the CDMA ERI icon index to display
3242 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003243 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003244 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3245 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3246 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003247 }
3248
Sanket Padawe356d7632015-06-22 14:03:32 -07003249 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003250 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3251 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003252 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003253 mApp, subId, callingPackage, callingFeatureId,
3254 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003255 return -1;
3256 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003257
3258 final long identity = Binder.clearCallingIdentity();
3259 try {
3260 final Phone phone = getPhone(subId);
3261 if (phone != null) {
3262 return phone.getCdmaEriIconIndex();
3263 } else {
3264 return -1;
3265 }
3266 } finally {
3267 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003268 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003269 }
3270
3271 /**
3272 * Returns the CDMA ERI icon mode,
3273 * 0 - ON
3274 * 1 - FLASHING
3275 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003276 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003277 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3278 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3279 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003280 }
3281
Sanket Padawe356d7632015-06-22 14:03:32 -07003282 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003283 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3284 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003286 mApp, subId, callingPackage, callingFeatureId,
3287 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003288 return -1;
3289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003290
3291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 final Phone phone = getPhone(subId);
3294 if (phone != null) {
3295 return phone.getCdmaEriIconMode();
3296 } else {
3297 return -1;
3298 }
3299 } finally {
3300 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003302 }
3303
3304 /**
3305 * Returns the CDMA ERI text,
3306 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003307 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003308 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3309 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3310 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003311 }
3312
Sanket Padawe356d7632015-06-22 14:03:32 -07003313 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003314 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3315 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003317 mApp, subId, callingPackage, callingFeatureId,
3318 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003319 return null;
3320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003321
3322 final long identity = Binder.clearCallingIdentity();
3323 try {
3324 final Phone phone = getPhone(subId);
3325 if (phone != null) {
3326 return phone.getCdmaEriText();
3327 } else {
3328 return null;
3329 }
3330 } finally {
3331 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003333 }
3334
3335 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003336 * Returns the CDMA MDN.
3337 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003338 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003339 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3341 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342
3343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003346 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 return phone.getLine1Number();
3348 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003349 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003350 return null;
3351 }
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003354 }
3355 }
3356
3357 /**
3358 * Returns the CDMA MIN.
3359 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003360 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003361 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3363 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364
3365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 final Phone phone = getPhone(subId);
3368 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3369 return phone.getCdmaMin();
3370 } else {
3371 return null;
3372 }
3373 } finally {
3374 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003375 }
3376 }
3377
Hall Liud892bec2018-11-30 14:51:45 -08003378 @Override
3379 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3380 INumberVerificationCallback callback, String callingPackage) {
3381 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3382 != PERMISSION_GRANTED) {
3383 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3384 }
3385 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3386
3387 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3388 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003389 throw new SecurityException("Calling package must be configured in the device config: "
3390 + "calling package: " + callingPackage
3391 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003392 }
3393
3394 if (range == null) {
3395 throw new NullPointerException("Range must be non-null");
3396 }
3397
3398 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003399 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003400
3401 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3402 }
3403
Junda Liuca05d5d2014-08-14 22:36:34 -07003404 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003405 * Returns true if CDMA provisioning needs to run.
3406 */
3407 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408 final long identity = Binder.clearCallingIdentity();
3409 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003410 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003411 } finally {
3412 Binder.restoreCallingIdentity(identity);
3413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003414 }
3415
3416 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003417 * Sets the voice mail number of a given subId.
3418 */
3419 @Override
3420 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003421 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3422 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003423
3424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3427 new Pair<String, String>(alphaTag, number), new Integer(subId));
3428 return success;
3429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003432 }
3433
Ta-wei Yen87c49842016-05-13 21:19:52 -07003434 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003435 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3436 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003437 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3438 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003439 if (!TextUtils.equals(callingPackage, systemDialer)) {
3440 throw new SecurityException("caller must be system dialer");
3441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003442
3443 final long identity = Binder.clearCallingIdentity();
3444 try {
3445 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3446 if (phoneAccountHandle == null) {
3447 return null;
3448 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003449 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 } finally {
3451 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003452 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003453 }
3454
3455 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003456 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3457 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003460 mApp, subId, callingPackage, callingFeatureId,
3461 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003462 return null;
3463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003465 final long identity = Binder.clearCallingIdentity();
3466 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003467 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003468 } finally {
3469 Binder.restoreCallingIdentity(identity);
3470 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003471 }
3472
3473 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003474 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3475 VisualVoicemailSmsFilterSettings settings) {
3476 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003477
3478 final long identity = Binder.clearCallingIdentity();
3479 try {
3480 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003481 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003482 } finally {
3483 Binder.restoreCallingIdentity(identity);
3484 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003485 }
3486
3487 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003488 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3489 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003490
3491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003494 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003495 } finally {
3496 Binder.restoreCallingIdentity(identity);
3497 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003498 }
3499
3500 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003501 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3502 String callingPackage, int subId) {
3503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003504
3505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003508 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509 } finally {
3510 Binder.restoreCallingIdentity(identity);
3511 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003512 }
3513
3514 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003515 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003516 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003517
3518 final long identity = Binder.clearCallingIdentity();
3519 try {
3520 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003521 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003522 } finally {
3523 Binder.restoreCallingIdentity(identity);
3524 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003525 }
3526
3527 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003528 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3529 String callingAttributionTag, int subId, String number, int port, String text,
3530 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003531 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003532 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003533 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003534 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003535 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3536 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003537 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003538
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003539 /**
fionaxu0152e512016-11-14 13:36:14 -08003540 * Sets the voice activation state of a given subId.
3541 */
3542 @Override
3543 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3545 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546
3547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 final Phone phone = getPhone(subId);
3550 if (phone != null) {
3551 phone.setVoiceActivationState(activationState);
3552 } else {
3553 loge("setVoiceActivationState fails with invalid subId: " + subId);
3554 }
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003557 }
3558 }
3559
3560 /**
3561 * Sets the data activation state of a given subId.
3562 */
3563 @Override
3564 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3566 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003567
3568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 final Phone phone = getPhone(subId);
3571 if (phone != null) {
3572 phone.setDataActivationState(activationState);
3573 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003574 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575 }
3576 } finally {
3577 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003578 }
3579 }
3580
3581 /**
3582 * Returns the voice activation state of a given subId.
3583 */
3584 @Override
3585 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587
fionaxu0152e512016-11-14 13:36:14 -08003588 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589 final long identity = Binder.clearCallingIdentity();
3590 try {
3591 if (phone != null) {
3592 return phone.getVoiceActivationState();
3593 } else {
3594 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3595 }
3596 } finally {
3597 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003598 }
3599 }
3600
3601 /**
3602 * Returns the data activation state of a given subId.
3603 */
3604 @Override
3605 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003607
fionaxu0152e512016-11-14 13:36:14 -08003608 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 if (phone != null) {
3612 return phone.getDataActivationState();
3613 } else {
3614 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3615 }
3616 } finally {
3617 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003618 }
3619 }
3620
3621 /**
Wink Saville36469e72014-06-11 15:17:00 -07003622 * Returns the unread count of voicemails for a subId
3623 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003624 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003625 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3626 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003628 mApp, subId, callingPackage, callingFeatureId,
3629 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003630 return 0;
3631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632 final long identity = Binder.clearCallingIdentity();
3633 try {
3634 final Phone phone = getPhone(subId);
3635 if (phone != null) {
3636 return phone.getVoiceMessageCount();
3637 } else {
3638 return 0;
3639 }
3640 } finally {
3641 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003643 }
3644
3645 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003646 * returns true, if the device is in a state where both voice and data
3647 * are supported simultaneously. This can change based on location or network condition.
3648 */
3649 @Override
3650 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 final Phone phone = getPhone(subId);
3654 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
3657 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003658 }
3659
3660 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003661 * Send the dialer code if called from the current default dialer or the caller has
3662 * carrier privilege.
3663 * @param inputCode The dialer code to send
3664 */
3665 @Override
3666 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003667 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003668 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003669 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3670 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003671 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003672 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003673 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003674 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675
3676 final long identity = Binder.clearCallingIdentity();
3677 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003678 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003679 } finally {
3680 Binder.restoreCallingIdentity(identity);
3681 }
fionaxu235cc5e2017-03-06 22:25:57 -08003682 }
3683
Pengquan Menga1bb6272018-09-06 09:59:22 -07003684 @Override
3685 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003686 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07003687 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003688 mApp, subId, "getNetworkSelectionMode");
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 if (!isActiveSubscription(subId)) {
3692 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3693 }
3694 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3695 } finally {
3696 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003697 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003698 }
3699
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003701 public boolean isInEmergencySmsMode() {
3702 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 for (Phone phone : PhoneFactory.getPhones()) {
3706 if (phone.isInEmergencySmsMode()) {
3707 return true;
3708 }
3709 }
3710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
3713 return false;
3714 }
3715
shilu366312e2019-12-17 09:28:10 -08003716 /**
3717 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3718 * @param subId The subscription to use to check the configuration.
3719 * @param c The callback that will be used to send the result.
3720 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003721 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003722 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3723 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003724 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003725 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003726
Brad Ebinger77b832e2019-10-17 17:03:22 -07003727 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3728 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3729 "IMS not available on device.");
3730 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 final long token = Binder.clearCallingIdentity();
3732 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003733 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003734 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003735 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003736 } catch (ImsException e) {
3737 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 } finally {
3739 Binder.restoreCallingIdentity(token);
3740 }
3741 }
3742
shilu366312e2019-12-17 09:28:10 -08003743 /**
3744 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3745 * @param subId The subscription to use to check the configuration.
3746 * @param c The callback that will be used to send the result.
3747 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003748 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003749 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003750 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003751 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3753 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3754 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003755 final long token = Binder.clearCallingIdentity();
3756 try {
3757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3758 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3759 .removeRegistrationCallbackForSubscription(c, subId);
3760 } catch (ImsException e) {
3761 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3762 + "is inactive, ignoring unregister.");
3763 // If the subscription is no longer active, just return, since the callback
3764 // will already have been removed internally.
3765 } finally {
3766 Binder.restoreCallingIdentity(token);
3767 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003768 }
3769
Brad Ebinger774ba362019-10-22 17:36:18 -07003770 /**
3771 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3772 */
3773 @Override
3774 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3775 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3776 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3777 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3778 "IMS not available on device.");
3779 }
3780 final long token = Binder.clearCallingIdentity();
3781 try {
3782 Phone phone = getPhone(subId);
3783 if (phone == null) {
3784 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3785 + subId + "'");
3786 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3787 }
3788 phone.getImsRegistrationState(regState -> {
3789 try {
3790 consumer.accept((regState == null)
3791 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3792 } catch (RemoteException e) {
3793 // Ignore if the remote process is no longer available to call back.
3794 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3795 }
3796 });
3797 } finally {
3798 Binder.restoreCallingIdentity(token);
3799 }
3800 }
3801
3802 /**
3803 * Get the transport type for the IMS service registration state.
3804 */
3805 @Override
3806 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003807 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003808 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003809 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3810 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3811 "IMS not available on device.");
3812 }
3813 final long token = Binder.clearCallingIdentity();
3814 try {
3815 Phone phone = getPhone(subId);
3816 if (phone == null) {
3817 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3818 + subId + "'");
3819 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3820 }
3821 phone.getImsRegistrationTech(regTech -> {
3822 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3823 int regTechConverted = (regTech == null)
3824 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3825 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3826 regTechConverted);
3827 try {
3828 consumer.accept(regTechConverted);
3829 } catch (RemoteException e) {
3830 // Ignore if the remote process is no longer available to call back.
3831 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3832 }
3833 });
3834 } finally {
3835 Binder.restoreCallingIdentity(token);
3836 }
3837 }
3838
shilu366312e2019-12-17 09:28:10 -08003839 /**
3840 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3841 * @param subId The subscription to use to check the configuration.
3842 * @param c The callback that will be used to send the result.
3843 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003844 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003845 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3846 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003847 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003848 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003849 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3850 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3851 "IMS not available on device.");
3852 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3854 final long token = Binder.clearCallingIdentity();
3855 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003856 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003857 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003858 } catch (ImsException e) {
3859 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003860 } finally {
3861 Binder.restoreCallingIdentity(token);
3862 }
3863 }
3864
shilu366312e2019-12-17 09:28:10 -08003865 /**
3866 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3867 * @param subId The subscription to use to check the configuration.
3868 * @param c The callback that will be used to send the result.
3869 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003870 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003871 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003872 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003873 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003874 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3875 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3876 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003877
3878 final long token = Binder.clearCallingIdentity();
3879 try {
3880 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3881 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003882 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003883 } catch (ImsException e) {
3884 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3885 + "is inactive, ignoring unregister.");
3886 // If the subscription is no longer active, just return, since the callback
3887 // will already have been removed internally.
3888 } finally {
3889 Binder.restoreCallingIdentity(token);
3890 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003891 }
3892
3893 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003894 public boolean isCapable(int subId, int capability, int regTech) {
3895 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003896 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3897 final long token = Binder.clearCallingIdentity();
3898 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003899 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003900 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003901 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003902 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3903 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003904 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003905 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3906 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 } finally {
3908 Binder.restoreCallingIdentity(token);
3909 }
3910 }
3911
3912 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003913 public boolean isAvailable(int subId, int capability, int regTech) {
3914 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 final long token = Binder.clearCallingIdentity();
3916 try {
3917 Phone phone = getPhone(subId);
3918 if (phone == null) return false;
3919 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003920 } catch (com.android.ims.ImsException e) {
3921 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3922 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003923 } finally {
3924 Binder.restoreCallingIdentity(token);
3925 }
3926 }
3927
Brad Ebinger77b832e2019-10-17 17:03:22 -07003928 /**
3929 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3930 * subscription.
3931 * @param subId The subscription to use to check the configuration.
3932 * @param callback The callback that will be used to send the result.
3933 * @param capability The MmTelFeature capability that will be used to send the result.
3934 * @param transportType The transport type of the MmTelFeature capability.
3935 */
3936 @Override
3937 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3938 int transportType) {
3939 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3940 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3941 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3942 "IMS not available on device.");
3943 }
3944 final long token = Binder.clearCallingIdentity();
3945 try {
3946 int slotId = getSlotIndex(subId);
3947 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3948 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3949 + subId + "'");
3950 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3951 }
3952 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3953 transportType, aBoolean -> {
3954 try {
3955 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3956 } catch (RemoteException e) {
3957 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3958 + "running. Ignore");
3959 }
3960 });
3961 } finally {
3962 Binder.restoreCallingIdentity(token);
3963 }
3964 }
3965
shilu366312e2019-12-17 09:28:10 -08003966 /**
3967 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3968 * @param subId The subscription to use to check the configuration.
3969 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 @Override
3971 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003972 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003973 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003974
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3976 final long token = Binder.clearCallingIdentity();
3977 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003978 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003980 } catch (ImsException e) {
3981 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 } finally {
3983 Binder.restoreCallingIdentity(token);
3984 }
3985 }
3986
3987 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003988 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003990 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003991 final long identity = Binder.clearCallingIdentity();
3992 try {
3993 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003994 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003996 } catch (ImsException e) {
3997 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003998 } finally {
3999 Binder.restoreCallingIdentity(identity);
4000 }
4001 }
4002
shilu366312e2019-12-17 09:28:10 -08004003 /**
4004 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4005 * @param subId The subscription to use to check the configuration.
4006 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004008 public boolean isVtSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004009 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004010 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 final long identity = Binder.clearCallingIdentity();
4012 try {
4013 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004014 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4015 } catch (ImsException e) {
4016 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
4020 }
4021
4022 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004023 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004025 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004026 final long identity = Binder.clearCallingIdentity();
4027 try {
4028 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004029 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004030 } catch (ImsException e) {
4031 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 } finally {
4033 Binder.restoreCallingIdentity(identity);
4034 }
4035 }
4036
shilu366312e2019-12-17 09:28:10 -08004037 /**
4038 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4039 * @param subId The subscription to use to check the configuration.
4040 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 @Override
4042 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004043 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004044 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004048 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004050 } catch (ImsException e) {
4051 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
4055 }
4056
4057 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004058 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004060 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 final long identity = Binder.clearCallingIdentity();
4062 try {
4063 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004064 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004065 } catch (ImsException e) {
4066 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 } finally {
4068 Binder.restoreCallingIdentity(identity);
4069 }
4070 }
4071
shilu366312e2019-12-17 09:28:10 -08004072 /**
4073 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4074 * @param subId The subscription to use to check the configuration.
4075 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 @Override
4077 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004078 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004079 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004083 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004085 } catch (ImsException e) {
4086 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
4090 }
4091
4092 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004093 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004095 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004099 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004101 } catch (ImsException e) {
4102 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 } finally {
4104 Binder.restoreCallingIdentity(identity);
4105 }
4106 }
4107
4108 @Override
4109 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4111 "setVoWiFiNonPersistent");
4112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004115 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004116 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004117 } catch (ImsException e) {
4118 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 } finally {
4120 Binder.restoreCallingIdentity(identity);
4121 }
4122 }
4123
shilu366312e2019-12-17 09:28:10 -08004124 /**
4125 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4126 * @param subId The subscription to use to check the configuration.
4127 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 @Override
4129 public int getVoWiFiModeSetting(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004130 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004131 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004132 final long identity = Binder.clearCallingIdentity();
4133 try {
4134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004135 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004137 } catch (ImsException e) {
4138 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 } finally {
4140 Binder.restoreCallingIdentity(identity);
4141 }
4142 }
4143
4144 @Override
4145 public void setVoWiFiModeSetting(int subId, int mode) {
4146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4147 "setVoWiFiModeSetting");
4148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004151 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004153 } catch (ImsException e) {
4154 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 } finally {
4156 Binder.restoreCallingIdentity(identity);
4157 }
4158 }
4159
4160 @Override
4161 public int getVoWiFiRoamingModeSetting(int subId) {
4162 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4163 final long identity = Binder.clearCallingIdentity();
4164 try {
4165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004166 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004168 } catch (ImsException e) {
4169 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
4173 }
4174
4175 @Override
4176 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4178 "setVoWiFiRoamingModeSetting");
4179 final long identity = Binder.clearCallingIdentity();
4180 try {
4181 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004182 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004183 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004184 } catch (ImsException e) {
4185 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
4189 }
4190
4191 @Override
4192 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4194 "setRttCapabilityEnabled");
4195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004198 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4199 } catch (ImsException e) {
4200 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 } finally {
4202 Binder.restoreCallingIdentity(identity);
4203 }
4204 }
4205
shilu366312e2019-12-17 09:28:10 -08004206 /**
4207 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4208 * @param subId The subscription to use to check the configuration.
4209 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 @Override
4211 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004212 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004213 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 final long identity = Binder.clearCallingIdentity();
4215 try {
4216 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004217 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004219 } catch (ImsException e) {
4220 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 } finally {
4222 Binder.restoreCallingIdentity(identity);
4223 }
4224 }
4225
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004226 @Override
4227 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4228 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4229 final long identity = Binder.clearCallingIdentity();
4230 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004231 if (!isImsAvailableOnDevice()) {
4232 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4233 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004234 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004235 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004236 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004237 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004238 } catch (ImsException e) {
4239 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004240 } finally {
4241 Binder.restoreCallingIdentity(identity);
4242 }
4243 }
4244
4245 @Override
4246 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4247 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4248 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004249 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4250 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4251 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004252 try {
4253 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004254 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004255 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004256 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004257 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4258 + "is inactive, ignoring unregister.");
4259 // If the subscription is no longer active, just return, since the callback will already
4260 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004261 } finally {
4262 Binder.restoreCallingIdentity(identity);
4263 }
4264 }
4265
allenwtsu99c623b2020-01-03 18:24:23 +08004266
4267 private void checkModifyPhoneStatePermission(int subId, String message) {
4268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4269 message);
4270 }
4271
4272 private boolean isImsProvisioningRequired(int subId, int capability,
4273 boolean isMmtelCapability) {
4274 Phone phone = getPhone(subId);
4275 if (phone == null) {
4276 loge("phone instance null for subid " + subId);
4277 return false;
4278 }
4279 if (isMmtelCapability) {
4280 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4281 return false;
4282 }
4283 } else {
4284 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4285 return false;
4286 }
4287 }
4288 return true;
4289 }
4290
4291 @Override
4292 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4293 boolean isProvisioned) {
4294 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4295
4296 final long identity = Binder.clearCallingIdentity();
4297 try {
4298 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4299 if (!isImsProvisioningRequired(subId, capability, false)) {
4300 return;
4301 }
4302
4303 // this capability requires provisioning, route to the correct API.
4304 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4305 switch (capability) {
4306 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4307 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4308 ims.setEabProvisioned(isProvisioned);
4309 break;
4310 default: {
4311 throw new IllegalArgumentException("Tried to set provisioning for "
4312 + "rcs capability '" + capability + "', which does not require "
4313 + "provisioning.");
4314 }
4315 }
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
4319
4320 }
4321
4322
4323 @Override
4324 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4325 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4329 if (!isImsProvisioningRequired(subId, capability, false)) {
4330 return true;
4331 }
4332
4333 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4334 switch (capability) {
4335 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4336 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4337 return ims.isEabProvisionedOnDevice();
4338
4339 default: {
4340 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4341 + "capability '" + capability + "', which does not require "
4342 + "provisioning.");
4343 }
4344 }
4345
4346 } finally {
4347 Binder.restoreCallingIdentity(identity);
4348 }
4349 }
4350
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004351 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004352 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4353 boolean isProvisioned) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004354 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4355 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004356 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4357 }
allenwtsu99c623b2020-01-03 18:24:23 +08004358 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004359 final long identity = Binder.clearCallingIdentity();
4360 try {
4361 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004362 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004363 return;
4364 }
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004365 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4366 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4367 loge("setImsProvisioningStatusForCapability: called for technology that does "
4368 + "not support provisioning - " + tech);
4369 return;
4370 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004371
4372 // this capability requires provisioning, route to the correct API.
4373 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4374 switch (capability) {
4375 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4376 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4377 ims.setVolteProvisioned(isProvisioned);
4378 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4379 ims.setWfcProvisioned(isProvisioned);
4380 }
4381 break;
4382 }
4383 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4384 // There is currently no difference in VT provisioning type.
4385 ims.setVtProvisioned(isProvisioned);
4386 break;
4387 }
4388 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4389 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4390 // change the capability of the feature instead if needed.
4391 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4392 == isProvisioned) {
4393 // No change in provisioning.
4394 return;
4395 }
4396 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4397 try {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004398 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004399 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004400 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4401 + ", Exception" + e.getMessage());
4402 }
4403 break;
4404 }
4405 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004406 throw new IllegalArgumentException("Tried to set provisioning for "
4407 + "MmTel capability '" + capability + "', which does not require "
4408 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004409 }
4410 }
4411
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
4415 }
4416
4417 @Override
4418 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004419 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4420 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004421 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4422 }
4423 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4424 final long identity = Binder.clearCallingIdentity();
4425 try {
4426 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004427 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004428 return true;
4429 }
4430
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004431 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4432 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4433 loge("getImsProvisioningStatusForCapability: called for technology that does "
4434 + "not support provisioning - " + tech);
4435 return true;
4436 }
4437
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004438 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4439 switch (capability) {
4440 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4441 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4442 return ims.isVolteProvisionedOnDevice();
4443 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4444 return ims.isWfcProvisionedOnDevice();
4445 }
4446 // This should never happen, since we are checking tech above to make sure it
4447 // is either LTE or IWLAN.
4448 throw new IllegalArgumentException("Invalid radio technology for voice "
4449 + "capability.");
4450 }
4451 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4452 // There is currently no difference in VT provisioning type.
4453 return ims.isVtProvisionedOnDevice();
4454 }
4455 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4456 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4457 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4458 }
4459 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004460 throw new IllegalArgumentException(
4461 "Tried to get provisioning for MmTel capability '" + capability
4462 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004463 }
4464 }
4465
4466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
4471 @Override
4472 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4473 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4474 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4475 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4476 }
4477 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4478 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4479 return (provisionedBits & capability) > 0;
4480 }
4481
4482 @Override
4483 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4484 boolean isProvisioned) {
4485 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4486 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4487 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4488 }
4489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4490 "setProvisioningStatusForCapability");
4491 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4492 // If the current provisioning status for capability already matches isProvisioned,
4493 // do nothing.
4494 if (((provisionedBits & capability) > 0) == isProvisioned) {
4495 return;
4496 }
4497 if (isProvisioned) {
4498 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4499 } else {
4500 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4501 }
4502 }
4503
4504 /**
4505 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4506 * technology. The bitfield should mirror the bitfield defined by
4507 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4508 */
4509 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4510 String key = getMmTelProvisioningKey(subId, tech);
4511 // Default is no capabilities are provisioned.
4512 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4513 }
4514
4515 /**
4516 * Sets the MmTel capability provisioning bitfield (defined by
4517 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4518 * technology specified.
4519 *
4520 * Note: This is a synchronous command and should not be called on UI thread.
4521 */
4522 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4523 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4524 String key = getMmTelProvisioningKey(subId, tech);
4525 editor.putInt(key, newField);
4526 editor.commit();
4527 }
4528
4529 private static String getMmTelProvisioningKey(int subId, int tech) {
4530 // resulting key is provision_ims_mmtel_{subId}_{tech}
4531 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4532 }
4533
4534 /**
4535 * Query CarrierConfig to see if the specified capability requires provisioning for the
4536 * carrier associated with the subscription id.
4537 */
4538 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4539 int capability) {
4540 CarrierConfigManager configManager = new CarrierConfigManager(context);
4541 PersistableBundle c = configManager.getConfigForSubId(subId);
4542 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004543 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004544 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4545 false);
4546 boolean requireVoiceVtProvisioning = c.getBoolean(
4547 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4548
4549 // First check to make sure that the capability requires provisioning.
4550 switch (capability) {
4551 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4552 // intentional fallthrough
4553 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4554 if (requireVoiceVtProvisioning) {
4555 // Voice and Video requires provisioning
4556 return true;
4557 }
4558 break;
4559 }
4560 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4561 if (requireUtProvisioning) {
4562 // UT requires provisioning
4563 return true;
4564 }
4565 break;
4566 }
4567 }
4568 return false;
4569 }
4570
allenwtsu99c623b2020-01-03 18:24:23 +08004571 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4572 int capability) {
4573 CarrierConfigManager configManager = new CarrierConfigManager(context);
4574 PersistableBundle c = configManager.getConfigForSubId(subId);
4575
4576 boolean requireRcsProvisioning = c.getBoolean(
4577 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4578
4579 // First check to make sure that the capability requires provisioning.
4580 switch (capability) {
4581 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4582 // intentional fallthrough
4583 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4584 if (requireRcsProvisioning) {
4585 // OPTION or PRESENCE requires provisioning
4586 return true;
4587 }
4588 break;
4589 }
4590 }
4591 return false;
4592 }
4593
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004594 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004595 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004596 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4597 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4598 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004599 enforceReadPrivilegedPermission("getImsProvisioningInt");
4600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004603 int slotId = getSlotIndex(subId);
4604 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4605 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4606 + subId + "' for key:" + key);
4607 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4608 }
calvinpan9cfff472021-02-08 19:59:36 +08004609 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004610 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004611 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4612 + subId + "' for key:" + key);
4613 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004614 } finally {
4615 Binder.restoreCallingIdentity(identity);
4616 }
4617 }
4618
4619 @Override
4620 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004621 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4622 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4623 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004624 enforceReadPrivilegedPermission("getImsProvisioningString");
4625 final long identity = Binder.clearCallingIdentity();
4626 try {
4627 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004628 int slotId = getSlotIndex(subId);
4629 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4630 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4631 + subId + "' for key:" + key);
4632 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4633 }
calvinpan9cfff472021-02-08 19:59:36 +08004634 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004635 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004636 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4637 + subId + "' for key:" + key);
4638 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004639 } finally {
4640 Binder.restoreCallingIdentity(identity);
4641 }
4642 }
4643
4644 @Override
4645 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004646 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4647 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4648 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4650 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004651 final long identity = Binder.clearCallingIdentity();
4652 try {
4653 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654 int slotId = getSlotIndex(subId);
4655 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4656 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4657 + subId + "' for key:" + key);
4658 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4659 }
calvinpan9cfff472021-02-08 19:59:36 +08004660 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4661 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004663 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004664 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
4668 }
4669
4670 @Override
4671 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004672 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4673 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4674 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4676 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004677 final long identity = Binder.clearCallingIdentity();
4678 try {
4679 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004680 int slotId = getSlotIndex(subId);
4681 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4682 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4683 + subId + "' for key:" + key);
4684 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4685 }
calvinpan9cfff472021-02-08 19:59:36 +08004686 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4687 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004688 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004689 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004690 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
4694 }
4695
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004696 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004697 int slotId = SubscriptionManager.getSlotIndex(subId);
4698 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004699 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4700 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004701 }
4702 return slotId;
4703 }
4704
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004705 private int getSlotIndex(int subId) {
4706 int slotId = SubscriptionManager.getSlotIndex(subId);
4707 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4708 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4709 }
4710 return slotId;
4711 }
4712
Wink Saville36469e72014-06-11 15:17:00 -07004713 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004714 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004715 */
4716 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004717 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4718 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004719 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004720 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004721 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004722 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004723 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004724 mApp, subId, callingPackage, callingFeatureId,
4725 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004726 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4727 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729 final long identity = Binder.clearCallingIdentity();
4730 try {
4731 final Phone phone = getPhone(subId);
4732 if (phone != null) {
4733 return phone.getServiceState().getDataNetworkType();
4734 } else {
4735 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4736 }
4737 } finally {
4738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004740 }
4741
4742 /**
4743 * Returns the data network type
4744 */
4745 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004746 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004747 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4748 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004749 }
4750
4751 /**
4752 * Returns the data network type for a subId
4753 */
4754 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004755 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4756 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004758 mApp, subId, callingPackage, callingFeatureId,
4759 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004760 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4761 }
4762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 final long identity = Binder.clearCallingIdentity();
4764 try {
4765 final Phone phone = getPhone(subId);
4766 if (phone != null) {
4767 return phone.getServiceState().getDataNetworkType();
4768 } else {
4769 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4770 }
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004774 }
4775
4776 /**
Wink Saville36469e72014-06-11 15:17:00 -07004777 * Returns the Voice network type for a subId
4778 */
4779 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004780 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4781 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004783 mApp, subId, callingPackage, callingFeatureId,
4784 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004785 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4786 }
4787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004788 final long identity = Binder.clearCallingIdentity();
4789 try {
4790 final Phone phone = getPhone(subId);
4791 if (phone != null) {
4792 return phone.getServiceState().getVoiceNetworkType();
4793 } else {
4794 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4795 }
4796 } finally {
4797 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004799 }
4800
4801 /**
4802 * @return true if a ICC card is present
4803 */
4804 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004805 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004806 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4807 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004808 }
4809
4810 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004811 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004812 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004813 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004814 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 final long identity = Binder.clearCallingIdentity();
4816 try {
4817 final Phone phone = PhoneFactory.getPhone(slotIndex);
4818 if (phone != null) {
4819 return phone.getIccCard().hasIccCard();
4820 } else {
4821 return false;
4822 }
4823 } finally {
4824 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004826 }
4827
4828 /**
4829 * Return if the current radio is LTE on CDMA. This
4830 * is a tri-state return value as for a period of time
4831 * the mode may be unknown.
4832 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004833 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004834 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004835 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004836 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004837 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004838 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4839 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4840 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004841 }
4842
Sanket Padawe356d7632015-06-22 14:03:32 -07004843 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004844 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4845 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004846 try {
4847 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4848 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004849 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4850 }
4851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004852 final long identity = Binder.clearCallingIdentity();
4853 try {
4854 final Phone phone = getPhone(subId);
4855 if (phone == null) {
4856 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4857 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004858 return TelephonyProperties.lte_on_cdma_device()
4859 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 }
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004863 }
Wink Saville36469e72014-06-11 15:17:00 -07004864 }
4865
Wink Saville36469e72014-06-11 15:17:00 -07004866 /**
4867 * {@hide}
4868 * Returns Default subId, 0 in the case of single standby.
4869 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004870 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004871 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004872 }
4873
Shishir Agrawala9f32182016-04-12 12:00:16 -07004874 private int getSlotForDefaultSubscription() {
4875 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4876 }
4877
Wink Savilleb564aae2014-10-23 10:18:09 -07004878 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004879 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004880 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004881
Pengquan Menge92a50d2018-09-21 15:54:48 -07004882 private boolean isActiveSubscription(int subId) {
4883 return mSubscriptionController.isActiveSubId(subId);
4884 }
4885
Ihab Awadf2177b72013-11-25 13:33:23 -08004886 /**
4887 * @see android.telephony.TelephonyManager.WifiCallingChoices
4888 */
4889 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890 final long identity = Binder.clearCallingIdentity();
4891 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004892 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4894 getWhenToMakeWifiCallsDefaultPreference());
4895 } finally {
4896 Binder.restoreCallingIdentity(identity);
4897 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004898 }
4899
4900 /**
4901 * @see android.telephony.TelephonyManager.WifiCallingChoices
4902 */
4903 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 final long identity = Binder.clearCallingIdentity();
4905 try {
4906 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004907 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4909 } finally {
4910 Binder.restoreCallingIdentity(identity);
4911 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004912 }
4913
Sailesh Nepald1e68152013-12-12 19:08:02 -08004914 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004915 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004916 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004917 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004918
Jordan Liu4c733742019-02-28 12:03:40 -08004919 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4920 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4921 if (phoneId == -1) {
4922 throw new IllegalArgumentException("Given slot index: " + slotIndex
4923 + " does not correspond to an active phone");
4924 }
4925 return PhoneFactory.getPhone(phoneId);
4926 }
4927
Shishir Agrawal566b7612013-10-28 14:41:00 -07004928 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004929 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4930 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4932 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004934 if (DBG) {
4935 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4936 }
4937 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4938 p2);
4939 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004940
Jordan Liu4c733742019-02-28 12:03:40 -08004941
4942 @Override
4943 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4944 int slotIndex, String callingPackage, String aid, int p2) {
4945 enforceModifyPermission();
4946 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4947 if (DBG) {
4948 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4949 }
4950 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4951 callingPackage, aid, p2);
4952 }
4953
4954 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4955 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 if (TextUtils.equals(ISDR_AID, aid)) {
4959 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004960 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4961 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 if (bestComponent == null
4963 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4964 loge("The calling package is not allowed to access ISD-R.");
4965 throw new SecurityException(
4966 "The calling package is not allowed to access ISD-R.");
4967 }
Derek Tan740e1672017-06-27 14:56:27 -07004968 }
Derek Tan740e1672017-06-27 14:56:27 -07004969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004971 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4972 null /* workSource */);
4973 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 return response;
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
4977 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004978 }
4979
4980 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004981 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4983 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004984 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4985 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4986 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004987
Jordan Liu4c733742019-02-28 12:03:40 -08004988 @Override
4989 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4990 enforceModifyPermission();
4991 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4992 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4993 channel);
4994 }
4995
4996 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004997 final long identity = Binder.clearCallingIdentity();
4998 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 if (channel < 0) {
5000 return false;
5001 }
Jordan Liu4c733742019-02-28 12:03:40 -08005002 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5003 null /* workSource */);
5004 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005005 return success;
5006 } finally {
5007 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005008 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005009 }
5010
5011 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005012 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005013 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5015 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005016 if (DBG) {
5017 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5018 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5019 + p3 + " data=" + data);
5020 }
5021 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5022 command, p1, p2, p3, data);
5023 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005024
Jordan Liu4c733742019-02-28 12:03:40 -08005025 @Override
5026 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5027 int command, int p1, int p2, int p3, String data) {
5028 enforceModifyPermission();
5029 if (DBG) {
5030 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5031 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5032 + p3 + " data=" + data);
5033 }
5034 return iccTransmitApduLogicalChannelWithPermission(
5035 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5036 data);
5037 }
5038
5039 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5040 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 final long identity = Binder.clearCallingIdentity();
5042 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005043 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 return "";
5045 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005048 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5049 null /* workSource */);
5050 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 // Append the returned status code to the end of the response payload.
5053 String s = Integer.toHexString(
5054 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5055 if (response.payload != null) {
5056 s = IccUtils.bytesToHexString(response.payload) + s;
5057 }
5058 return s;
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005061 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005062 }
Jake Hambye994d462014-02-03 13:10:13 -08005063
Evan Charltonc66da362014-05-16 14:06:40 -07005064 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005065 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5066 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5068 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005070 if (DBG) {
5071 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5072 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5073 }
5074 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5075 cla, command, p1, p2, p3, data);
5076 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005077
Jordan Liu4c733742019-02-28 12:03:40 -08005078 @Override
5079 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5080 int command, int p1, int p2, int p3, String data) {
5081 enforceModifyPermission();
5082 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5083 if (DBG) {
5084 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5085 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5086 + " data=" + data);
5087 }
5088
5089 return iccTransmitApduBasicChannelWithPermission(
5090 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5091 p2, p3, data);
5092 }
5093
5094 // open APDU basic channel assuming the caller has sufficient permissions
5095 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5096 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 final long identity = Binder.clearCallingIdentity();
5098 try {
5099 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5100 && TextUtils.equals(ISDR_AID, data)) {
5101 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005102 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5103 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 if (bestComponent == null
5105 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5106 loge("The calling package is not allowed to select ISD-R.");
5107 throw new SecurityException(
5108 "The calling package is not allowed to select ISD-R.");
5109 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005110 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005111
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005113 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5114 null /* workSource */);
5115 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 // Append the returned status code to the end of the response payload.
5118 String s = Integer.toHexString(
5119 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5120 if (response.payload != null) {
5121 s = IccUtils.bytesToHexString(response.payload) + s;
5122 }
5123 return s;
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005126 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005127 }
5128
5129 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005130 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005131 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5133 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 final long identity = Binder.clearCallingIdentity();
5136 try {
5137 if (DBG) {
5138 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5139 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5140 }
5141
5142 IccIoResult response =
5143 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5144 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5145 subId);
5146
5147 if (DBG) {
5148 log("Exchange SIM_IO [R]" + response);
5149 }
5150
5151 byte[] result = null;
5152 int length = 2;
5153 if (response.payload != null) {
5154 length = 2 + response.payload.length;
5155 result = new byte[length];
5156 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5157 } else {
5158 result = new byte[length];
5159 }
5160
5161 result[length - 1] = (byte) response.sw2;
5162 result[length - 2] = (byte) response.sw1;
5163 return result;
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005166 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005167 }
5168
Nathan Haroldb3014052017-01-25 15:57:32 -08005169 /**
5170 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5171 * on a particular subscription
5172 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005173 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5174 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005175 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005176 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005177 return null;
5178 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179
5180 final long identity = Binder.clearCallingIdentity();
5181 try {
5182 if (appType != TelephonyManager.APPTYPE_USIM
5183 && appType != TelephonyManager.APPTYPE_SIM) {
5184 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5185 return null;
5186 }
5187 Object response = sendRequest(
5188 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5189 if (response instanceof String[]) {
5190 return (String[]) response;
5191 }
yincheng zhaod698b842019-09-06 17:06:54 -07005192 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005194 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 } finally {
5196 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005197 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005198 }
5199
yincheng zhaod698b842019-09-06 17:06:54 -07005200 /**
5201 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5202 * subscription.
5203 *
5204 * @param subId the id of the subscription.
5205 * @param appType the uicc app type, must be USIM or SIM.
5206 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5207 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005208 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005209 * @return number of fplmns that is successfully written to the SIM.
5210 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005211 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5212 String callingFeatureId) {
5213 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5214 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005215 if (DBG) logv("no permissions for setForbiddenplmns");
5216 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5217 }
5218 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5219 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5220 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5221 }
5222 if (fplmns == null) {
5223 throw new IllegalArgumentException("Fplmn List provided is null");
5224 }
5225 for (String fplmn : fplmns) {
5226 if (!CellIdentity.isValidPlmn(fplmn)) {
5227 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5228 }
5229 }
5230 final long identity = Binder.clearCallingIdentity();
5231 try {
5232 Object response = sendRequest(
5233 CMD_SET_FORBIDDEN_PLMNS,
5234 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5235 subId);
5236 return (int) response;
5237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
5240 }
5241
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005242 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005243 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5245 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 final long identity = Binder.clearCallingIdentity();
5248 try {
5249 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5250 if (response.payload == null) {
5251 return "";
5252 }
Evan Charltonc66da362014-05-16 14:06:40 -07005253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 // Append the returned status code to the end of the response payload.
5255 String s = Integer.toHexString(
5256 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5257 s = IccUtils.bytesToHexString(response.payload) + s;
5258 return s;
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
Evan Charltonc66da362014-05-16 14:06:40 -07005262 }
5263
Jake Hambye994d462014-02-03 13:10:13 -08005264 /**
5265 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5266 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5267 *
5268 * @param itemID the ID of the item to read
5269 * @return the NV item as a String, or null on error.
5270 */
5271 @Override
5272 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005273 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5275 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276
5277 final long identity = Binder.clearCallingIdentity();
5278 try {
5279 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005280 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5282 return value;
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
Jake Hambye994d462014-02-03 13:10:13 -08005286 }
5287
5288 /**
5289 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5290 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5291 *
5292 * @param itemID the ID of the item to read
5293 * @param itemValue the value to write, as a String
5294 * @return true on success; false on any failure
5295 */
5296 @Override
5297 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005298 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5300 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301
5302 final long identity = Binder.clearCallingIdentity();
5303 try {
5304 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5305 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005306 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5308 return success;
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
Jake Hambye994d462014-02-03 13:10:13 -08005312 }
5313
5314 /**
5315 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5316 * Used for device configuration by some CDMA operators.
5317 *
5318 * @param preferredRoamingList byte array containing the new PRL
5319 * @return true on success; false on any failure
5320 */
5321 @Override
5322 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5324 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325
5326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5329 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5330 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5331 return success;
5332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
Jake Hambye994d462014-02-03 13:10:13 -08005335 }
5336
5337 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005338 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005339 * Used for device configuration by some CDMA operators.
5340 *
chen xu6dac5ab2018-10-26 17:39:23 -07005341 * @param slotIndex - device slot.
5342 *
Jake Hambye994d462014-02-03 13:10:13 -08005343 * @return true on success; false on any failure
5344 */
5345 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005346 public boolean resetModemConfig(int slotIndex) {
5347 Phone phone = PhoneFactory.getPhone(slotIndex);
5348 if (phone != null) {
5349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5350 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351
chen xu6dac5ab2018-10-26 17:39:23 -07005352 final long identity = Binder.clearCallingIdentity();
5353 try {
5354 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5355 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5356 return success;
5357 } finally {
5358 Binder.restoreCallingIdentity(identity);
5359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 }
chen xu6dac5ab2018-10-26 17:39:23 -07005361 return false;
5362 }
5363
5364 /**
5365 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5366 *
5367 * @param slotIndex - device slot.
5368 *
5369 * @return true on success; false on any failure
5370 */
5371 @Override
5372 public boolean rebootModem(int slotIndex) {
5373 Phone phone = PhoneFactory.getPhone(slotIndex);
5374 if (phone != null) {
5375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5376 mApp, phone.getSubId(), "rebootModem");
5377
5378 final long identity = Binder.clearCallingIdentity();
5379 try {
5380 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5381 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5382 return success;
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
5385 }
5386 }
5387 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005388 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005389
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005390 public String[] getPcscfAddress(String apnType, String callingPackage,
5391 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005392 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5394 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005395 return new String[0];
5396 }
5397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 final long identity = Binder.clearCallingIdentity();
5399 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005400 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
Wink Saville36469e72014-06-11 15:17:00 -07005404 }
5405
Brad Ebinger51f743a2017-01-23 13:50:20 -08005406 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005407 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5408 * {@link #disableIms(int)}.
5409 * @param slotIndex device slot.
5410 */
5411 public void resetIms(int slotIndex) {
5412 enforceModifyPermission();
5413
5414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 if (mImsResolver == null) {
5417 // may happen if the does not support IMS.
5418 return;
5419 }
5420 mImsResolver.disableIms(slotIndex);
5421 mImsResolver.enableIms(slotIndex);
5422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
5425 }
5426
5427 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005428 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5429 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005430 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005431 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433
5434 final long identity = Binder.clearCallingIdentity();
5435 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005436 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005437 // may happen if the device does not support IMS.
5438 return;
5439 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005440 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005444 }
5445
5446 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005447 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5448 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005449 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005450 public void disableIms(int slotId) {
5451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452
5453 final long identity = Binder.clearCallingIdentity();
5454 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005455 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005456 // may happen if the device does not support IMS.
5457 return;
5458 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005459 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005463 }
5464
5465 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005466 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5467 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005468 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005469 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005470 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005471 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472
5473 final long identity = Binder.clearCallingIdentity();
5474 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005475 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005476 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5477 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005478 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005479 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 } finally {
5481 Binder.restoreCallingIdentity(identity);
5482 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005483 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005484 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005485 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5486 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005487 @Override
5488 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005489 enforceModifyPermission();
5490
5491 final long identity = Binder.clearCallingIdentity();
5492 try {
5493 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005494 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
5498 }
5499
5500 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005501 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005502 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005503 */
5504 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5505 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005509 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005510 // may happen if the device does not support IMS.
5511 return null;
5512 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005513 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005517 }
5518
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005519 /**
5520 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005521 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005522 */
5523 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525
5526 final long identity = Binder.clearCallingIdentity();
5527 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005528 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005529 // may happen if the device does not support IMS.
5530 return null;
5531 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005532 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 } finally {
5534 Binder.restoreCallingIdentity(identity);
5535 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005536 }
5537
Brad Ebinger884c07b2018-02-15 16:17:40 -08005538 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005539 * Sets the ImsService Package Name that Telephony will bind to.
5540 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005541 * @param slotIndex the slot ID that the ImsService should bind for.
5542 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005543 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005544 * @param featureTypes An integer array of feature types associated with a packageName.
5545 * @param packageName The name of the package that the current configuration will be replaced
5546 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005547 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005548 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005549 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5550 int[] featureTypes, String packageName) {
5551 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5552 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5554 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005555 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 final long identity = Binder.clearCallingIdentity();
5558 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005559 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005560 // may happen if the device does not support IMS.
5561 return false;
5562 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005563 Map<Integer, String> featureConfig = new HashMap<>();
5564 for (int featureType : featureTypes) {
5565 featureConfig.put(featureType, packageName);
5566 }
5567 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5568 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005572 }
5573
5574 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005575 * Clears any carrier ImsService overrides for the slot index specified that were previously
5576 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5577 *
5578 * This should only be used for testing.
5579 *
5580 * @param slotIndex the slot ID that the ImsService should bind for.
5581 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5582 */
5583 @Override
5584 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5585 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5586 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5587 "clearCarrierImsServiceOverride");
5588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5589 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5590 "clearCarrierImsServiceOverride");
5591
5592 final long identity = Binder.clearCallingIdentity();
5593 try {
5594 if (mImsResolver == null) {
5595 // may happen if the device does not support IMS.
5596 return false;
5597 }
5598 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
5602 }
5603
5604 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005605 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005606 *
5607 * @param slotId The slot that the ImsService is associated with.
5608 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5609 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005610 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005611 * @return the package name of the ImsService configuration.
5612 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005613 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5614 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005615 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005616 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005617 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005618 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5619 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 final long identity = Binder.clearCallingIdentity();
5622 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005623 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005624 // may happen if the device does not support IMS.
5625 return "";
5626 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005627 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005628 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5629 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005633 }
5634
Brad Ebinger77b832e2019-10-17 17:03:22 -07005635 /**
5636 * Get the MmTelFeature state associated with the requested subscription id.
5637 * @param subId The subscription that the MmTelFeature is associated with.
5638 * @param callback A callback with an integer containing the
5639 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5640 */
5641 @Override
5642 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5643 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5644 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5645 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5646 "IMS not available on device.");
5647 }
5648 final long token = Binder.clearCallingIdentity();
5649 try {
5650 int slotId = getSlotIndex(subId);
5651 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5652 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5653 + subId + "'");
5654 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5655 }
5656 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5657 try {
5658 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5659 } catch (RemoteException e) {
5660 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5661 + "Ignore");
5662 }
5663 });
5664 } finally {
5665 Binder.restoreCallingIdentity(token);
5666 }
5667 }
5668
Daniel Brightbb5840b2021-01-12 15:48:18 -08005669 /**
5670 * Sets the ims registration state on all valid {@link Phone}s.
5671 */
5672 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005673 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674
5675 final long identity = Binder.clearCallingIdentity();
5676 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005677 // NOTE: Before S, this method only set the default phone.
5678 for (final Phone phone : PhoneFactory.getPhones()) {
5679 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5680 phone.setImsRegistrationState(registered);
5681 }
5682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Wink Saville36469e72014-06-11 15:17:00 -07005686 }
5687
5688 /**
Stuart Scott54788802015-03-30 13:18:01 -07005689 * Set the network selection mode to automatic.
5690 *
5691 */
5692 @Override
5693 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5695 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696
5697 final long identity = Binder.clearCallingIdentity();
5698 try {
shilufc958392020-01-20 11:36:01 -08005699 if (!isActiveSubscription(subId)) {
5700 return;
5701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005703 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5704 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
Stuart Scott54788802015-03-30 13:18:01 -07005708 }
5709
Jack Yud10cdd42020-09-28 20:28:01 -07005710 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005711 * Ask the radio to connect to the input network and change selection mode to manual.
5712 *
5713 * @param subId the id of the subscription.
5714 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5715 * the operator to attach to.
5716 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5717 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5718 * normal network selection next time.
5719 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005720 */
5721 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005722 public boolean setNetworkSelectionModeManual(
5723 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5725 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005726
5727 if (!isActiveSubscription(subId)) {
5728 return false;
5729 }
5730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 final long identity = Binder.clearCallingIdentity();
5732 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005733 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005735 if (DBG) {
5736 log("setNetworkSelectionModeManual: subId: " + subId
5737 + " operator: " + operatorInfo);
5738 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005743 }
shilu84f6e8b2019-12-19 13:58:01 -08005744 /**
5745 * Get the manual network selection
5746 *
5747 * @param subId the id of the subscription.
5748 *
5749 * @return the previously saved user selected PLMN
5750 */
5751 @Override
5752 public String getManualNetworkSelectionPlmn(int subId) {
5753 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005754 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005755 mApp, subId, "getManualNetworkSelectionPlmn");
5756
5757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 if (!isActiveSubscription(subId)) {
5760 return "";
5761 }
5762
5763 final Phone phone = getPhone(subId);
5764 if (phone == null) {
5765 return "";
5766 }
5767 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5768 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5769 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
5773 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005774
5775 /**
5776 * Scans for available networks.
5777 */
5778 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005779 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5780 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5782 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005783 LocationAccessPolicy.LocationPermissionResult locationResult =
5784 LocationAccessPolicy.checkLocationPermission(mApp,
5785 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5786 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005787 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005788 .setCallingPid(Binder.getCallingPid())
5789 .setCallingUid(Binder.getCallingUid())
5790 .setMethod("getCellNetworkScanResults")
5791 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07005792 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5793 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005794 .build());
5795 switch (locationResult) {
5796 case DENIED_HARD:
5797 throw new SecurityException("Not allowed to access scan results -- location");
5798 case DENIED_SOFT:
5799 return null;
5800 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801
Pengquan Menga1bb6272018-09-06 09:59:22 -07005802 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803 try {
5804 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005805 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807 } finally {
5808 Binder.restoreCallingIdentity(identity);
5809 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005810 }
5811
5812 /**
sqian80370722020-01-29 15:02:51 -08005813 * Get the call forwarding info, given the call forwarding reason.
5814 */
5815 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005816 public void getCallForwarding(int subId, int callForwardingReason,
5817 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005818 enforceReadPrivilegedPermission("getCallForwarding");
5819 long identity = Binder.clearCallingIdentity();
5820 try {
5821 if (DBG) {
5822 log("getCallForwarding: subId " + subId
5823 + " callForwardingReason" + callForwardingReason);
5824 }
Hall Liua1acea22020-09-18 19:04:59 -07005825
5826 Phone phone = getPhone(subId);
5827 if (phone == null) {
5828 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005829 callback.onError(
5830 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005831 } catch (RemoteException e) {
5832 // ignore
5833 }
5834 return;
5835 }
5836
5837 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5838 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5839 @Override
5840 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5841 try {
5842 callback.onCallForwardingInfoAvailable(info);
5843 } catch (RemoteException e) {
5844 // ignore
5845 }
5846 }
5847
5848 @Override
5849 public void onError(int error) {
5850 try {
5851 callback.onError(error);
5852 } catch (RemoteException e) {
5853 // ignore
5854 }
5855 }
5856 });
5857 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005858 } finally {
5859 Binder.restoreCallingIdentity(identity);
5860 }
5861 }
5862
5863 /**
5864 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5865 * reason, the number to forward, and the timeout before the forwarding is attempted.
5866 */
5867 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005868 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5869 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005870 enforceModifyPermission();
5871 long identity = Binder.clearCallingIdentity();
5872 try {
5873 if (DBG) {
5874 log("setCallForwarding: subId " + subId
5875 + " callForwardingInfo" + callForwardingInfo);
5876 }
Hall Liua1acea22020-09-18 19:04:59 -07005877
5878 Phone phone = getPhone(subId);
5879 if (phone == null) {
5880 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005881 callback.accept(
5882 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005883 } catch (RemoteException e) {
5884 // ignore
5885 }
5886 return;
5887 }
5888
5889 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5890 FunctionalUtils.ignoreRemoteException(callback::accept));
5891
5892 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
5896 }
5897
5898 /**
Hall Liua1acea22020-09-18 19:04:59 -07005899 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005900 */
5901 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005902 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWangc63cf522021-03-31 22:08:45 +08005903 enforceReadPrivilegedPermission("getCallWaitingStatus");
sqian80370722020-01-29 15:02:51 -08005904 long identity = Binder.clearCallingIdentity();
5905 try {
Hall Liua1acea22020-09-18 19:04:59 -07005906 Phone phone = getPhone(subId);
5907 if (phone == null) {
5908 try {
5909 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5910 } catch (RemoteException e) {
5911 // ignore
5912 }
5913 return;
5914 }
SongFerngWangc63cf522021-03-31 22:08:45 +08005915 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5916 PersistableBundle c = configManager.getConfigForSubId(subId);
5917 boolean requireUssd = c.getBoolean(
5918 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005919
sqian80370722020-01-29 15:02:51 -08005920 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWangc63cf522021-03-31 22:08:45 +08005921 if (requireUssd) {
5922 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5923 getSubscriptionCarrierId(subId));
5924 String newUssdCommand = "";
5925 try {
5926 newUssdCommand = carrierXmlParser.getFeature(
5927 CarrierXmlParser.FEATURE_CALL_WAITING)
5928 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
5929 } catch (NullPointerException e) {
5930 loge("Failed to generate USSD number" + e);
5931 }
5932 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5933 mMainThreadHandler, callback, carrierXmlParser,
5934 CarrierXmlParser.SsEntry.SSAction.QUERY);
5935 final String ussdCommand = newUssdCommand;
5936 Executors.newSingleThreadExecutor().execute(() -> {
5937 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5938 });
5939 } else {
5940 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
5941 callback::accept);
5942 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
5943 }
sqian80370722020-01-29 15:02:51 -08005944 } finally {
5945 Binder.restoreCallingIdentity(identity);
5946 }
5947 }
5948
5949 /**
Hall Liua1acea22020-09-18 19:04:59 -07005950 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005951 */
5952 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005953 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005954 enforceModifyPermission();
5955 long identity = Binder.clearCallingIdentity();
5956 try {
Hall Liua1acea22020-09-18 19:04:59 -07005957 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5958
5959 Phone phone = getPhone(subId);
5960 if (phone == null) {
5961 try {
5962 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5963 } catch (RemoteException e) {
5964 // ignore
5965 }
5966 return;
5967 }
5968
SongFerngWangc63cf522021-03-31 22:08:45 +08005969 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5970 PersistableBundle c = configManager.getConfigForSubId(subId);
5971 boolean requireUssd = c.getBoolean(
5972 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005973
SongFerngWangc63cf522021-03-31 22:08:45 +08005974 if (DBG) log("getCallWaitingStatus: subId " + subId);
5975 if (requireUssd) {
5976 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5977 getSubscriptionCarrierId(subId));
5978 CarrierXmlParser.SsEntry.SSAction ssAction =
5979 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
5980 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
5981 String newUssdCommand = "";
5982 try {
5983 newUssdCommand = carrierXmlParser.getFeature(
5984 CarrierXmlParser.FEATURE_CALL_WAITING)
5985 .makeCommand(ssAction, null);
5986 } catch (NullPointerException e) {
5987 loge("Failed to generate USSD number" + e);
5988 }
5989 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5990 mMainThreadHandler, callback, carrierXmlParser, ssAction);
5991 final String ussdCommand = newUssdCommand;
5992 Executors.newSingleThreadExecutor().execute(() -> {
5993 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5994 });
5995 } else {
5996 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5997 FunctionalUtils.ignoreRemoteException(callback::accept));
5998
5999 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6000 }
sqian80370722020-01-29 15:02:51 -08006001 } finally {
6002 Binder.restoreCallingIdentity(identity);
6003 }
6004 }
6005
6006 /**
yinxub1bed742017-04-17 11:45:04 -07006007 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006008 *
yinxub1bed742017-04-17 11:45:04 -07006009 * @param subId id of the subscription
6010 * @param request contains the radio access networks with bands/channels to scan
6011 * @param messenger callback messenger for scan results or errors
6012 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006013 * @return the id of the requested scan which can be used to stop the scan.
6014 */
6015 @Override
6016 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006017 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6019 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006020 LocationAccessPolicy.LocationPermissionResult locationResult =
6021 LocationAccessPolicy.checkLocationPermission(mApp,
6022 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6023 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006024 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006025 .setCallingPid(Binder.getCallingPid())
6026 .setCallingUid(Binder.getCallingUid())
6027 .setMethod("requestNetworkScan")
6028 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6029 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006030 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07006031 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6032 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006033 if (e != null) {
6034 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6035 throw e;
6036 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006037 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006038 return TelephonyScanManager.INVALID_SCAN_ID;
6039 }
6040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 }
Hall Liu912dfd32019-04-25 14:02:26 -07006042 int callingUid = Binder.getCallingUid();
6043 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006044 final long identity = Binder.clearCallingIdentity();
6045 try {
6046 return mNetworkScanRequestTracker.startNetworkScan(
6047 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006048 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006049 } finally {
6050 Binder.restoreCallingIdentity(identity);
6051 }
yinxu504e1392017-04-12 16:03:22 -07006052 }
6053
Hall Liub2ac8ef2019-02-28 15:56:23 -08006054 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07006055 NetworkScanRequest request, int subId, String callingPackage) {
6056 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006057 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6058 boolean hasNetworkScanPermission =
6059 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6060 == PERMISSION_GRANTED;
6061
6062 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6063 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6064 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006065 }
6066
6067 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6068 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006069 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6070 return new SecurityException("Specific channels must not be"
6071 + " scanned without location access.");
6072 }
6073 }
6074 }
6075
Hall Liub2ac8ef2019-02-28 15:56:23 -08006076 return null;
6077 }
6078
yinxu504e1392017-04-12 16:03:22 -07006079 /**
6080 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006081 *
6082 * @param subId id of the subscription
6083 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006084 */
6085 @Override
6086 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6088 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089
Hall Liu912dfd32019-04-25 14:02:26 -07006090 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 final long identity = Binder.clearCallingIdentity();
6092 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006093 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 } finally {
6095 Binder.restoreCallingIdentity(identity);
6096 }
yinxu504e1392017-04-12 16:03:22 -07006097 }
6098
6099 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006100 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006101 *
SongFerngWang9e060372020-12-21 16:41:52 +08006102 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006103 */
6104 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006105 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006106 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006107 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006108 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109
6110 final long identity = Binder.clearCallingIdentity();
6111 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006112 if (DBG) log("getAllowedNetworkTypesBitmask");
6113 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6114 int networkTypesBitmask = (result != null ? result[0] : -1);
6115 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6116 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 } finally {
6118 Binder.restoreCallingIdentity(identity);
6119 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006120 }
6121
6122 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006123 * Get the allowed network types for certain reason.
6124 *
6125 * @param subId the id of the subscription.
6126 * @param reason the reason the allowed network type change is taking place
6127 * @return the allowed network types.
6128 */
6129 @Override
6130 public long getAllowedNetworkTypesForReason(int subId,
6131 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006132 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006133 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006134 final long identity = Binder.clearCallingIdentity();
6135 try {
6136 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6137 } finally {
6138 Binder.restoreCallingIdentity(identity);
6139 }
6140 }
6141
6142 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006143 * Enable/Disable E-UTRA-NR Dual Connectivity
6144 * @param subId subscription id of the sim card
6145 * @param nrDualConnectivityState expected NR dual connectivity state
6146 * This can be passed following states
6147 * <ol>
6148 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6149 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6150 * <li>Disable NR dual connectivity and force secondary cell to be released
6151 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6152 * </ol>
6153 * @return operation result.
6154 */
6155 @Override
6156 public int setNrDualConnectivityState(int subId,
6157 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6159 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006160 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006161 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6162 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6163 }
6164
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006165 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6166 final long identity = Binder.clearCallingIdentity();
6167 try {
6168 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6169 nrDualConnectivityState, subId,
6170 workSource);
6171 if (DBG) log("enableNRDualConnectivity result: " + result);
6172 return result;
6173 } finally {
6174 Binder.restoreCallingIdentity(identity);
6175 }
6176 }
6177
6178 /**
6179 * Is E-UTRA-NR Dual Connectivity enabled
6180 * @return true if dual connectivity is enabled else false
6181 */
6182 @Override
6183 public boolean isNrDualConnectivityEnabled(int subId) {
6184 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006185 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006186 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006187 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006188 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6189 return false;
6190 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006191 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6192 final long identity = Binder.clearCallingIdentity();
6193 try {
6194 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6195 null, subId, workSource);
6196 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6197 return isEnabled;
6198 } finally {
6199 Binder.restoreCallingIdentity(identity);
6200 }
6201 }
6202
6203 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006204 * Set the allowed network types of the device and
6205 * provide the reason triggering the allowed network change.
6206 *
6207 * @param subId the id of the subscription.
6208 * @param reason the reason the allowed network type change is taking place
6209 * @param allowedNetworkTypes the allowed network types.
6210 * @return true on success; false on any failure.
6211 */
6212 @Override
6213 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006214 @TelephonyManager.AllowedNetworkTypesReason int reason,
6215 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6217 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006218 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWangc2d3ccc2021-04-15 19:46:33 +08006219 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6220 return false;
6221 }
6222 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6223 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang9e060372020-12-21 16:41:52 +08006224 return false;
6225 }
6226
SongFerngWang522637d2021-03-02 22:09:29 +08006227 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6228 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6229
6230
6231 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6232 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6233 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006234 }
SongFerngWang522637d2021-03-02 22:09:29 +08006235
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006236 final long identity = Binder.clearCallingIdentity();
6237 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006238 Boolean success = (Boolean) sendRequest(
6239 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6240 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6241
6242 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6243 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006244 } finally {
6245 Binder.restoreCallingIdentity(identity);
6246 }
6247 }
6248
6249 /**
Miaoa84611c2019-03-15 09:21:10 +08006250 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006251 *
Miaoa84611c2019-03-15 09:21:10 +08006252 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006253 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006254 * @hide
6255 */
6256 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006257 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006258 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006260 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261 try {
Miaoa84611c2019-03-15 09:21:10 +08006262 if (phone != null) {
6263 return phone.hasMatchedTetherApnSetting();
6264 } else {
6265 return false;
6266 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 } finally {
6268 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006269 }
Junda Liu475951f2014-11-07 16:45:03 -08006270 }
6271
6272 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006273 * Enable or disable always reporting signal strength changes from radio.
6274 *
6275 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6276 */
6277 @Override
6278 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6279 enforceModifyPermission();
6280 enforceSystemCaller();
6281
6282 final long identity = Binder.clearCallingIdentity();
6283 final Phone phone = getPhone(subId);
6284 try {
6285 if (phone != null) {
6286 if (DBG) {
6287 log("setAlwaysReportSignalStrength: subId=" + subId
6288 + " isEnable=" + isEnable);
6289 }
6290 phone.setAlwaysReportSignalStrength(isEnable);
6291 } else {
6292 loge("setAlwaysReportSignalStrength: no phone found for subId="
6293 + subId);
6294 }
6295 } finally {
6296 Binder.restoreCallingIdentity(identity);
6297 }
6298 }
6299
6300 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006301 * Get the user enabled state of Mobile Data.
6302 *
6303 * TODO: remove and use isUserDataEnabled.
6304 * This can't be removed now because some vendor codes
6305 * calls through ITelephony directly while they should
6306 * use TelephonyManager.
6307 *
6308 * @return true on enabled
6309 */
6310 @Override
6311 public boolean getDataEnabled(int subId) {
6312 return isUserDataEnabled(subId);
6313 }
6314
6315 /**
6316 * Get whether mobile data is enabled per user setting.
6317 *
6318 * There are other factors deciding whether mobile data is actually enabled, but they are
6319 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006320 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006321 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006322 *
6323 * @return {@code true} if data is enabled else {@code false}
6324 */
6325 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006326 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006327 try {
6328 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6329 null);
6330 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6332 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006334
6335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 int phoneId = mSubscriptionController.getPhoneId(subId);
6338 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6339 Phone phone = PhoneFactory.getPhone(phoneId);
6340 if (phone != null) {
6341 boolean retVal = phone.isUserDataEnabled();
6342 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6343 return retVal;
6344 } else {
6345 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6346 return false;
6347 }
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006350 }
6351 }
6352
6353 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006354 * Checks if the device is capable of mobile data by considering whether whether the
6355 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6356 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006357 *
Shuo Qian985d1232020-01-08 14:30:06 -08006358 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006359 */
6360 @Override
6361 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006362 try {
6363 try {
6364 mApp.enforceCallingOrSelfPermission(
6365 android.Manifest.permission.ACCESS_NETWORK_STATE,
6366 null);
6367 } catch (Exception e) {
6368 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6369 "isDataEnabled");
6370 }
6371 } catch (Exception e) {
6372 enforceReadPrivilegedPermission("isDataEnabled");
6373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374
6375 final long identity = Binder.clearCallingIdentity();
6376 try {
6377 int phoneId = mSubscriptionController.getPhoneId(subId);
6378 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6379 Phone phone = PhoneFactory.getPhone(phoneId);
6380 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006381 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6383 return retVal;
6384 } else {
6385 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6386 return false;
6387 }
6388 } finally {
6389 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006390 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006391 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006392
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006393 /**
6394 * Check if data is enabled for a specific reason
6395 * @param subId Subscription index
6396 * @param reason the reason the data enable change is taking place
6397 * @return {@code true} if the overall data is enabled; {@code false} if not.
6398 */
6399 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006400 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006401 @TelephonyManager.DataEnabledReason int reason) {
6402 try {
6403 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6404 null);
6405 } catch (Exception e) {
6406 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006407 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006408 }
6409
6410
6411 final long identity = Binder.clearCallingIdentity();
6412 try {
6413 int phoneId = mSubscriptionController.getPhoneId(subId);
6414 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006415 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006416 + " reason=" + reason);
6417 }
6418 Phone phone = PhoneFactory.getPhone(phoneId);
6419 if (phone != null) {
6420 boolean retVal;
6421 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6422 retVal = phone.isUserDataEnabled();
6423 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006424 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006425 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006426 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006427 return retVal;
6428 } else {
6429 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006430 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006431 + subId + " retVal=false");
6432 }
6433 return false;
6434 }
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
6437 }
6438 }
6439
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006440 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006441 Phone phone) {
Sarah Chinca45c312021-04-09 10:37:15 -07006442 if (uid == Process.PHONE_UID) {
6443 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6444 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liuce478d22020-07-13 12:13:03 -07006445 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6446 }
6447
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006448 //load access rules from carrier configs, and check those as well: b/139133814
6449 SubscriptionController subController = SubscriptionController.getInstance();
6450 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6451 || subController == null) return privilegeFromSim;
6452
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006453 PackageManager pkgMgr = phone.getContext().getPackageManager();
6454 String[] packages = pkgMgr.getPackagesForUid(uid);
6455
6456 final long identity = Binder.clearCallingIdentity();
6457 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006458 int subId = phone.getSubId();
6459 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6460 // A test override is in place for the privileges for this subId, so don't try to
6461 // read the subscription privileges.
6462 return privilegeFromSim;
6463 }
6464 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006465 SubscriptionManager subManager = (SubscriptionManager)
6466 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6467 for (String pkg : packages) {
6468 if (subManager.canManageSubscription(subInfo, pkg)) {
6469 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6470 }
6471 }
6472 return privilegeFromSim;
6473 } finally {
6474 Binder.restoreCallingIdentity(identity);
6475 }
6476 }
6477
6478 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6479 String pkgName) {
6480 //load access rules from carrier configs, and check those as well: b/139133814
6481 SubscriptionController subController = SubscriptionController.getInstance();
6482 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6483 || subController == null) return privilegeFromSim;
6484
6485 final long identity = Binder.clearCallingIdentity();
6486 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006487 int subId = phone.getSubId();
6488 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6489 // A test override is in place for the privileges for this subId, so don't try to
6490 // read the subscription privileges.
6491 return privilegeFromSim;
6492 }
6493 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006494 SubscriptionManager subManager = (SubscriptionManager)
6495 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6496 return subManager.canManageSubscription(subInfo, pkgName)
6497 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6498 } finally {
6499 Binder.restoreCallingIdentity(identity);
6500 }
6501 }
6502
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006503 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006504 public int getCarrierPrivilegeStatus(int subId) {
6505 final Phone phone = getPhone(subId);
6506 if (phone == null) {
6507 loge("getCarrierPrivilegeStatus: Invalid subId");
6508 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6509 }
6510 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006511 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006512 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006513 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6514 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006515
6516 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6517 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006518 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006519 }
Junda Liu29340342014-07-10 15:23:27 -07006520
6521 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006522 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006523 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006524 final Phone phone = getPhone(subId);
6525 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006526 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006527 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6528 }
6529 UiccProfile profile =
6530 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6531 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006532 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006533 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6534 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006535 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006536 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006537 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006538 }
6539
6540 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006541 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6542 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006543 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006544 }
6545
6546 int phoneId = SubscriptionManager.getPhoneId(subId);
6547 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006548 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006549 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006550 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6551 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006552 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6553 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6554 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006555 }
6556
6557 @Override
6558 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006559 if (TextUtils.isEmpty(pkgName))
6560 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006561 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6562 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6563 UiccCard card = UiccController.getInstance().getUiccCard(i);
6564 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006565 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006566 continue;
6567 }
6568
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006569 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6570 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6571 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006572 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6573 break;
6574 }
6575 }
6576
6577 return result;
Junda Liu29340342014-07-10 15:23:27 -07006578 }
Derek Tan89e89d42014-07-08 17:00:10 -07006579
6580 @Override
Junda Liue64de782015-04-16 17:19:16 -07006581 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6582 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6583 loge("phoneId " + phoneId + " is not valid.");
6584 return null;
6585 }
6586 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006587 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006588 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006589 return null ;
6590 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006591 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006592 }
6593
Amith Yamasani6e118872016-02-19 12:53:51 -08006594 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006595 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006596 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006597 List<String> privilegedPackages = new ArrayList<>();
6598 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006599 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6600 // has UICC in that slot.
6601 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006602 if (card.hasCarrierPrivilegeRules()) {
6603 if (packages == null) {
6604 // Only check packages in user 0 for now
6605 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006606 PackageManager.MATCH_DISABLED_COMPONENTS
6607 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006608 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006609 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006610 }
6611 for (int p = packages.size() - 1; p >= 0; p--) {
6612 PackageInfo pkgInfo = packages.get(p);
6613 if (pkgInfo != null && pkgInfo.packageName != null
6614 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006615 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006616 privilegedPackages.add(pkgInfo.packageName);
6617 }
6618 }
6619 }
6620 }
6621 return privilegedPackages;
6622 }
6623
chen xuf7e9fe82019-05-09 19:31:02 -07006624 @Override
6625 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006626 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6627
6628 final long identity = Binder.clearCallingIdentity();
6629
chen xuf7e9fe82019-05-09 19:31:02 -07006630 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006631 try {
6632 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6633 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6634 }
6635 } finally {
6636 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006637 }
6638 return privilegedPackages;
6639 }
6640
Wink Savilleb564aae2014-10-23 10:18:09 -07006641 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006642 final Phone phone = getPhone(subId);
6643 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006644 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006645 return null;
6646 }
6647 String iccId = card.getIccId();
6648 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006649 return null;
6650 }
6651 return iccId;
6652 }
6653
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006654 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006655 public void setCallComposerStatus(int subId, int status) {
6656 enforceModifyPermission();
6657
6658 final long identity = Binder.clearCallingIdentity();
6659 try {
6660 Phone phone = getPhone(subId);
6661 if (phone != null) {
6662 Phone defaultPhone = phone.getImsPhone();
6663 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6664 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6665 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006666 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6667 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006668 }
6669 }
Shuo Qiand8782462020-12-22 19:10:14 -08006670 } catch (ImsException e) {
6671 throw new ServiceSpecificException(e.getCode());
6672 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006673 Binder.restoreCallingIdentity(identity);
6674 }
6675 }
6676
6677 @Override
6678 public int getCallComposerStatus(int subId) {
6679 enforceReadPrivilegedPermission("getCallComposerStatus");
6680
6681 final long identity = Binder.clearCallingIdentity();
6682 try {
6683 Phone phone = getPhone(subId);
6684 if (phone != null) {
6685 Phone defaultPhone = phone.getImsPhone();
6686 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6687 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6688 return imsPhone.getCallComposerStatus();
6689 }
6690 }
6691 } finally {
6692 Binder.restoreCallingIdentity(identity);
6693 }
6694 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6695 }
6696
6697 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006698 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6699 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006700 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006701 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703 final long identity = Binder.clearCallingIdentity();
6704 try {
6705 final String iccId = getIccId(subId);
6706 final Phone phone = getPhone(subId);
6707 if (phone == null) {
6708 return false;
6709 }
6710 final String subscriberId = phone.getSubscriberId();
6711
6712 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006713 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006714 + subscriberId + " to " + number);
6715 }
6716
6717 if (TextUtils.isEmpty(iccId)) {
6718 return false;
6719 }
6720
6721 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6722
6723 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6724 if (alphaTag == null) {
6725 editor.remove(alphaTagPrefKey);
6726 } else {
6727 editor.putString(alphaTagPrefKey, alphaTag);
6728 }
6729
6730 // Record both the line number and IMSI for this ICCID, since we need to
6731 // track all merged IMSIs based on line number
6732 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6733 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6734 if (number == null) {
6735 editor.remove(numberPrefKey);
6736 editor.remove(subscriberPrefKey);
6737 } else {
6738 editor.putString(numberPrefKey, number);
6739 editor.putString(subscriberPrefKey, subscriberId);
6740 }
6741
6742 editor.commit();
6743 return true;
6744 } finally {
6745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006746 }
Derek Tan7226c842014-07-02 17:42:23 -07006747 }
6748
6749 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006750 public String getLine1NumberForDisplay(int subId, String callingPackage,
6751 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006752 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006754 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006755 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006756 return null;
6757 }
Derek Tan97ebb422014-09-05 16:55:38 -07006758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006759 final long identity = Binder.clearCallingIdentity();
6760 try {
6761 String iccId = getIccId(subId);
6762 if (iccId != null) {
6763 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6764 if (DBG_MERGE) {
6765 log("getLine1NumberForDisplay returning "
6766 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6767 }
6768 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006770 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6771 return null;
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006774 }
Derek Tan7226c842014-07-02 17:42:23 -07006775 }
6776
6777 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006778 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6779 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006781 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006782 return null;
6783 }
Derek Tan97ebb422014-09-05 16:55:38 -07006784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 final long identity = Binder.clearCallingIdentity();
6786 try {
6787 String iccId = getIccId(subId);
6788 if (iccId != null) {
6789 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6790 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6791 }
6792 return null;
6793 } finally {
6794 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006795 }
Derek Tan7226c842014-07-02 17:42:23 -07006796 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006797
6798 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006799 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6800 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006801 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6802 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006804 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006805 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006806 return null;
6807 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006808
Jordan Liub49b04b2019-05-06 14:45:15 -07006809 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6810 // the process, where TelephonyManager was instantiated.
6811 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006812 final long identity = Binder.clearCallingIdentity();
6813 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006814 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815 final TelephonyManager tele = TelephonyManager.from(context);
6816 final SubscriptionManager sub = SubscriptionManager.from(context);
6817
6818 // Figure out what subscribers are currently active
6819 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820
Jordan Liub49b04b2019-05-06 14:45:15 -07006821 // Only consider subs which match the current subId
6822 // This logic can be simplified. See b/131189269 for progress.
6823 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006824 activeSubscriberIds.add(tele.getSubscriberId(subId));
6825 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826
6827 // First pass, find a number override for an active subscriber
6828 String mergeNumber = null;
6829 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6830 for (String key : prefs.keySet()) {
6831 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6832 final String subscriberId = (String) prefs.get(key);
6833 if (activeSubscriberIds.contains(subscriberId)) {
6834 final String iccId = key.substring(
6835 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6836 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6837 mergeNumber = (String) prefs.get(numberKey);
6838 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006839 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 + " for active subscriber " + subscriberId);
6841 }
6842 if (!TextUtils.isEmpty(mergeNumber)) {
6843 break;
6844 }
6845 }
6846 }
6847 }
6848
6849 // Shortcut when no active merged subscribers
6850 if (TextUtils.isEmpty(mergeNumber)) {
6851 return null;
6852 }
6853
6854 // Second pass, find all subscribers under that line override
6855 final ArraySet<String> result = new ArraySet<>();
6856 for (String key : prefs.keySet()) {
6857 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6858 final String number = (String) prefs.get(key);
6859 if (mergeNumber.equals(number)) {
6860 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6861 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6862 final String subscriberId = (String) prefs.get(subscriberKey);
6863 if (!TextUtils.isEmpty(subscriberId)) {
6864 result.add(subscriberId);
6865 }
6866 }
6867 }
6868 }
6869
6870 final String[] resultArray = result.toArray(new String[result.size()]);
6871 Arrays.sort(resultArray);
6872 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006873 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6875 }
6876 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006877 } finally {
6878 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006879 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006880 }
6881
6882 @Override
zoey chen38003472019-12-13 17:16:31 +08006883 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6884 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006885
6886 final long identity = Binder.clearCallingIdentity();
6887 try {
6888 final TelephonyManager telephonyManager = mApp.getSystemService(
6889 TelephonyManager.class);
6890 String subscriberId = telephonyManager.getSubscriberId(subId);
6891 if (subscriberId == null) {
6892 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006893 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006894 + subId);
6895 }
6896 return null;
6897 }
6898
6899 final SubscriptionInfo info = SubscriptionController.getInstance()
6900 .getSubscriptionInfo(subId);
6901 final ParcelUuid groupUuid = info.getGroupUuid();
6902 // If it doesn't belong to any group, return just subscriberId of itself.
6903 if (groupUuid == null) {
6904 return new String[]{subscriberId};
6905 }
6906
6907 // Get all subscriberIds from the group.
6908 final List<String> mergedSubscriberIds = new ArrayList<>();
6909 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006910 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006911 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006912 for (SubscriptionInfo subInfo : groupInfos) {
6913 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6914 if (subscriberId != null) {
6915 mergedSubscriberIds.add(subscriberId);
6916 }
6917 }
6918
6919 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6920 } finally {
6921 Binder.restoreCallingIdentity(identity);
6922
6923 }
6924 }
6925
6926 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006927 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006928 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006929 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930
6931 final long identity = Binder.clearCallingIdentity();
6932 try {
6933 final Phone phone = getPhone(subId);
6934 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6935 } finally {
6936 Binder.restoreCallingIdentity(identity);
6937 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006938 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006939
6940 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006941 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006942 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6943 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006944 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6945 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946
6947 final long identity = Binder.clearCallingIdentity();
6948 try {
6949 final Phone phone = getPhone(subId);
6950 if (phone == null) {
6951 return false;
6952 }
6953 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6954 cdmaNonRoamingList);
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006957 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006958 }
6959
6960 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006961 @Deprecated
6962 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6963 enforceModifyPermission();
6964
6965 int returnValue = 0;
6966 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006967 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006968 if(result.exception == null) {
6969 if (result.result != null) {
6970 byte[] responseData = (byte[])(result.result);
6971 if(responseData.length > oemResp.length) {
6972 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6973 responseData.length + "bytes. Buffer Size is " +
6974 oemResp.length + "bytes.");
6975 }
6976 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6977 returnValue = responseData.length;
6978 }
6979 } else {
6980 CommandException ex = (CommandException) result.exception;
6981 returnValue = ex.getCommandError().ordinal();
6982 if(returnValue > 0) returnValue *= -1;
6983 }
6984 } catch (RuntimeException e) {
6985 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6986 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6987 if(returnValue > 0) returnValue *= -1;
6988 }
6989
6990 return returnValue;
6991 }
6992
6993 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006994 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006995 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006996 try {
6997 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006998 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07006999 mApp, phone.getSubId(), "getRadioAccessFamily");
7000 } catch (SecurityException e) {
7001 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7002 throw e;
7003 }
chen xub97461a2018-10-26 14:17:57 -07007004 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007005 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007006 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 final long identity = Binder.clearCallingIdentity();
7009 try {
chen xub97461a2018-10-26 14:17:57 -07007010 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007011 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007012 mApp, phone.getSubId(), "getRadioAccessFamily");
7013 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014 } finally {
7015 Binder.restoreCallingIdentity(identity);
7016 }
chen xub97461a2018-10-26 14:17:57 -07007017 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007018 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007019
7020 @Override
7021 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007022 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007023 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024
7025 final long identity = Binder.clearCallingIdentity();
7026 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007027 ImsManager.getInstance(defaultPhone.getContext(),
7028 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007032 }
7033
7034 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007035 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007036 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7038 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007039 return false;
7040 }
Svet Ganovb320e182015-04-16 12:30:10 -07007041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 final long identity = Binder.clearCallingIdentity();
7043 try {
7044 // Check the user preference and the system-level IMS setting. Even if the user has
7045 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7046 // In the long run, we may instead need to check if there exists a connection service
7047 // which can support video calling.
7048 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007049 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 return imsManager.isVtEnabledByPlatform()
7051 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7052 && imsManager.isVtEnabledByUser();
7053 } finally {
7054 Binder.restoreCallingIdentity(identity);
7055 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007056 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007057
Andrew Leea1239f22015-03-02 17:44:07 -08007058 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007059 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7060 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007062 mApp, subId, callingPackage, callingFeatureId,
7063 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064 return false;
7065 }
7066
7067 final long identity = Binder.clearCallingIdentity();
7068 try {
7069 CarrierConfigManager configManager =
7070 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007071 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7073 } finally {
7074 Binder.restoreCallingIdentity(identity);
7075 }
Andrew Leea1239f22015-03-02 17:44:07 -08007076 }
7077
7078 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007079 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007081 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 return false;
7083 }
7084
7085 final long identity = Binder.clearCallingIdentity();
7086 try {
7087 CarrierConfigManager configManager =
7088 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007089 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7091 } finally {
7092 Binder.restoreCallingIdentity(identity);
7093 }
Andrew Leea1239f22015-03-02 17:44:07 -08007094 }
7095
Andrew Lee9431b832015-03-09 18:46:45 -07007096 @Override
7097 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007098 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007099 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007100 }
7101
7102 @Override
7103 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 final long identity = Binder.clearCallingIdentity();
7105 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007106 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 } finally {
7108 Binder.restoreCallingIdentity(identity);
7109 }
Andrew Lee9431b832015-03-09 18:46:45 -07007110 }
7111
Hall Liuf6668912018-10-31 17:05:23 -07007112 /**
7113 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7114 * support for the feature and device firmware support.
7115 *
7116 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7117 */
7118 @Override
7119 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007121 final Phone phone = getPhone(subscriptionId);
7122 if (phone == null) {
7123 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7124 return false;
7125 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007127 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7129 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007130 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 return isCarrierSupported && isDeviceSupported;
7132 } finally {
7133 Binder.restoreCallingIdentity(identity);
7134 }
Hall Liu98187582018-01-22 19:15:32 -08007135 }
7136
Hall Liuf6668912018-10-31 17:05:23 -07007137 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007138 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7139 * RTT setting, will return true if the device and carrier both support RTT.
7140 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007141 */
7142 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007143 final long identity = Binder.clearCallingIdentity();
7144 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007145 boolean isRttSupported = isRttSupported(subscriptionId);
7146 boolean isUserRttSettingOn = Settings.Secure.getInt(
7147 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7148 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7149 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7150 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 } finally {
7152 Binder.restoreCallingIdentity(identity);
7153 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007154 }
7155
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007156 @Deprecated
7157 @Override
7158 public String getDeviceId(String callingPackage) {
7159 return getDeviceIdWithFeature(callingPackage, null);
7160 }
7161
Sanket Padawe7310cc72015-01-14 09:53:20 -08007162 /**
7163 * Returns the unique device ID of phone, for example, the IMEI for
7164 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7165 *
7166 * <p>Requires Permission:
7167 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7168 */
7169 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007170 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007171 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007172 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007173 return null;
7174 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007175 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007176 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007177 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007178 return null;
7179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180
7181 final long identity = Binder.clearCallingIdentity();
7182 try {
7183 return phone.getDeviceId();
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007187 }
7188
Ping Sunc67b7c22016-03-02 19:16:45 +08007189 /**
7190 * {@hide}
7191 * Returns the IMS Registration Status on a particular subid
7192 *
7193 * @param subId
7194 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007195 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007196 Phone phone = getPhone(subId);
7197 if (phone != null) {
7198 return phone.isImsRegistered();
7199 } else {
7200 return false;
7201 }
7202 }
7203
Santos Cordon7a1885b2015-02-03 11:15:19 -08007204 @Override
7205 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 final long identity = Binder.clearCallingIdentity();
7207 try {
7208 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7209 } finally {
7210 Binder.restoreCallingIdentity(identity);
7211 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007212 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007213
Tyler Gunnf70ed162019-04-03 15:28:53 -07007214 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007215 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007216 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007218 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007219 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7220 }
7221 final long identity = Binder.clearCallingIdentity();
7222 try {
7223 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7224 } finally {
7225 Binder.restoreCallingIdentity(identity);
7226 }
7227 }
7228
7229 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007230 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007231 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7232 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007233 final long identity = Binder.clearCallingIdentity();
7234 try {
7235 Phone phone = getPhone(subscriptionId);
7236 if (phone == null) {
7237 return null;
7238 }
7239 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7240 } finally {
7241 Binder.restoreCallingIdentity(identity);
7242 }
7243 }
7244
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007245 /**
7246 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007247 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007248 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007249 final long identity = Binder.clearCallingIdentity();
7250 try {
7251 Phone phone = getPhone(subId);
7252 if (phone != null) {
7253 return phone.isWifiCallingEnabled();
7254 } else {
7255 return false;
7256 }
7257 } finally {
7258 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007259 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007260 }
7261
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007262 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007263 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007264 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007265 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 final long identity = Binder.clearCallingIdentity();
7267 try {
7268 Phone phone = getPhone(subId);
7269 if (phone != null) {
7270 return phone.isVideoEnabled();
7271 } else {
7272 return false;
7273 }
7274 } finally {
7275 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007276 }
7277 }
7278
7279 /**
7280 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7281 * defined in {@link ImsRegistrationImplBase}.
7282 */
7283 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007284 final long identity = Binder.clearCallingIdentity();
7285 try {
7286 Phone phone = getPhone(subId);
7287 if (phone != null) {
7288 return phone.getImsRegistrationTech();
7289 } else {
7290 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7291 }
7292 } finally {
7293 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007294 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007295 }
7296
Stuart Scott8eef64f2015-04-08 15:13:54 -07007297 @Override
7298 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007299 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007300 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7301 return;
7302 }
7303
Svet Ganovcc087f82015-05-12 20:35:54 -07007304 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007305
Svet Ganovcc087f82015-05-12 20:35:54 -07007306 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007307 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7308 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007309 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007310 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007311 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007312 Phone phone = getPhone(subId);
SongFerngWang51ee2b12021-05-27 22:44:54 +08007313 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007314 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7315 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007316 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007317 // There has been issues when Sms raw table somehow stores orphan
7318 // fragments. They lead to garbled message when new fragments come
7319 // in and combined with those stale ones. In case this happens again,
7320 // user can reset all network settings which will clean up this table.
7321 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007322 // Clean up IMS settings as well here.
7323 int slotId = getSlotIndex(subId);
7324 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7325 ImsManager.getInstance(mApp, slotId).factoryReset();
7326 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007327
7328 // Erase modem config if erase modem on network setting is enabled.
7329 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7330 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7331 if (configValue != null && Boolean.parseBoolean(configValue)) {
7332 sendEraseModemConfig(getDefaultPhone());
7333 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007334 } finally {
7335 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007336 }
7337 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007338
SongFerngWang51ee2b12021-05-27 22:44:54 +08007339 @VisibleForTesting
7340 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7341 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7342 return;
7343 }
7344 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7345 RILConstants.PREFERRED_NETWORK_MODE);
7346 SubscriptionManager.setSubscriptionProperty(subId,
7347 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7348 "user=" + defaultNetworkType);
7349 phone.loadAllowedNetworksFromSubscriptionDatabase();
7350 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7351 defaultNetworkType, null);
7352 }
7353
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007354 private void cleanUpSmsRawTable(Context context) {
7355 ContentResolver resolver = context.getContentResolver();
7356 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7357 resolver.delete(uri, null, null);
7358 }
7359
Narayan Kamath1c496c22015-04-16 14:40:19 +01007360 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007361 public String getSimLocaleForSubscriber(int subId) {
7362 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7363 final Phone phone = getPhone(subId);
7364 if (phone == null) {
7365 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007366 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007367 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368 final long identity = Binder.clearCallingIdentity();
7369 try {
chen xu5d3637b2019-01-21 23:31:38 -08007370 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007371 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007372 if (info == null) {
7373 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7374 return null;
7375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 // Try and fetch the locale from the carrier properties or from the SIM language
7377 // preferences (EF-PL and EF-LI)...
7378 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007380 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7381 if (localeFromDefaultSim != null) {
7382 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7383 if (DBG) log("Using locale from subId: " + subId + " locale: "
7384 + localeFromDefaultSim);
7385 return localeFromDefaultSim.toLanguageTag();
7386 } else {
7387 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 }
7389 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 // The SIM language preferences only store a language (e.g. fr = French), not an
7392 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7393 // the SIM and carrier preferences does not include a country we add the country
7394 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007395 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007397 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 return mccLocale.toLanguageTag();
7399 }
7400
7401 if (DBG) log("No locale found - returning null");
7402 return null;
7403 } finally {
7404 Binder.restoreCallingIdentity(identity);
7405 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007406 }
7407
7408 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007409 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007410 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007411 }
7412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413 /**
7414 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7415 */
7416 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007417 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007418 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007419 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007420
Chenjie Yu1ba97252018-01-11 18:16:20 -08007421 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liue8315982020-10-09 19:00:11 -07007422 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007423
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007424 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007425 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7426 * representing the state of the modem.
7427 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007428 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7429 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007430 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007431 */
7432 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007433 public void requestModemActivityInfo(ResultReceiver result) {
7434 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007435 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436
7437 final long identity = Binder.clearCallingIdentity();
7438 try {
sqian1a1be542020-03-05 11:37:28 -08007439 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 } finally {
7441 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007442 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007443 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007444
Siddharth Rayb8114062018-06-17 15:02:38 -07007445 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7446 // less than total activity duration.
7447 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7448 if (info == null) {
7449 return false;
7450 }
7451 int activityDurationMs =
Hall Liue8315982020-10-09 19:00:11 -07007452 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7453 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7454
Siddharth Rayb8114062018-06-17 15:02:38 -07007455 return (info.isValid()
7456 && (info.getSleepTimeMillis() <= activityDurationMs)
7457 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007458 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007459 && (totalTxTimeMs <= activityDurationMs));
7460 }
7461
Jack Yu85bd38a2015-11-09 11:34:32 -08007462 /**
7463 * {@hide}
7464 * Returns the service state information on specified subscription.
7465 */
7466 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007467 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7468 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007470 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007471 return null;
7472 }
7473
Hall Liuf19c44f2018-11-27 14:38:17 -08007474 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7475 LocationAccessPolicy.checkLocationPermission(mApp,
7476 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7477 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007478 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007479 .setCallingPid(Binder.getCallingPid())
7480 .setCallingUid(Binder.getCallingUid())
7481 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007482 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007483 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007484 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7485 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007486 .build());
7487
7488 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7489 LocationAccessPolicy.checkLocationPermission(mApp,
7490 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7491 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007492 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007493 .setCallingPid(Binder.getCallingPid())
7494 .setCallingUid(Binder.getCallingUid())
7495 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007496 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007497 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007498 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7499 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007500 .build());
7501 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7502 boolean hasFinePermission =
7503 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7504 boolean hasCoarsePermission =
7505 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 final long identity = Binder.clearCallingIdentity();
7508 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007509 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7510 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7511 Rlog.d(LOG_TAG,
7512 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7513 return null;
7514 }
7515
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 final Phone phone = getPhone(subId);
7517 if (phone == null) {
7518 return null;
7519 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007520
Hall Liuf19c44f2018-11-27 14:38:17 -08007521 ServiceState ss = phone.getServiceState();
7522
7523 // Scrub out the location info in ServiceState depending on what level of access
7524 // the caller has.
7525 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007526 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7527 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007531 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007532
7533 /**
7534 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7535 *
7536 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7537 * voicemail ringtone.
7538 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7539 * PhoneAccount.
7540 */
7541 @Override
7542 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543 final long identity = Binder.clearCallingIdentity();
7544 try {
7545 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7546 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007547 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007548 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007554 }
7555
7556 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007557 * Sets the per-account voicemail ringtone.
7558 *
7559 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7560 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7561 *
7562 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7563 * voicemail ringtone.
7564 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7565 * PhoneAccount.
7566 */
7567 @Override
7568 public void setVoicemailRingtoneUri(String callingPackage,
7569 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007570 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007571 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007572 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7573 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7575 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7576 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007578
7579 final long identity = Binder.clearCallingIdentity();
7580 try {
7581 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7582 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007583 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007584 }
7585 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7586 } finally {
7587 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007588 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007589 }
7590
7591 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007592 * Returns whether vibration is set for voicemail notification in Phone settings.
7593 *
7594 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7595 * voicemail vibration setting.
7596 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7597 */
7598 @Override
7599 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 final long identity = Binder.clearCallingIdentity();
7601 try {
7602 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7603 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007604 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007607 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7608 } finally {
7609 Binder.restoreCallingIdentity(identity);
7610 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007611 }
7612
Youhan Wange64578a2016-05-02 15:32:42 -07007613 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007614 * Sets the per-account voicemail vibration.
7615 *
7616 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7617 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7618 *
7619 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7620 * voicemail vibration setting.
7621 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7622 * specific PhoneAccount.
7623 */
7624 @Override
7625 public void setVoicemailVibrationEnabled(String callingPackage,
7626 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007627 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007628 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007629 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7630 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7632 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7633 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007634 }
7635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007636 final long identity = Binder.clearCallingIdentity();
7637 try {
7638 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7639 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007640 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007641 }
7642 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7643 } finally {
7644 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007645 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007646 }
7647
7648 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007649 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7650 *
7651 * @throws SecurityException if the caller does not have the required permission
7652 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007653 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007654 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007655 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007656 }
7657
7658 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007659 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7660 * permission.
7661 *
7662 * @throws SecurityException if the caller does not have the required permission
7663 */
7664 private void enforceSendSmsPermission() {
7665 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7666 }
7667
7668 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007669 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007670 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007671 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007672 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007673 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 final long identity = Binder.clearCallingIdentity();
7675 try {
7676 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007677 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 if (componentName == null) {
7679 throw new SecurityException(
7680 "Caller not current active visual voicemail package[null]");
7681 }
7682 String vvmPackage = componentName.getPackageName();
7683 if (!callingPackage.equals(vvmPackage)) {
7684 throw new SecurityException("Caller not current active visual voicemail package["
7685 + vvmPackage + "]");
7686 }
7687 } finally {
7688 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007689 }
7690 }
7691
7692 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007693 * Return the application ID for the app type.
7694 *
7695 * @param subId the subscription ID that this request applies to.
7696 * @param appType the uicc app type.
7697 * @return Application ID for specificied app type, or null if no uicc.
7698 */
7699 @Override
7700 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007701 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007702 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703
7704 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007705 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007706 if (phone == null) {
7707 return null;
7708 }
7709 String aid = null;
7710 try {
7711 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7712 .getApplicationByType(appType).getAid();
7713 } catch (Exception e) {
7714 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7715 }
7716 return aid;
7717 } finally {
7718 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007719 }
Youhan Wange64578a2016-05-02 15:32:42 -07007720 }
7721
Youhan Wang4001d252016-05-11 10:29:41 -07007722 /**
7723 * Return the Electronic Serial Number.
7724 *
7725 * @param subId the subscription ID that this request applies to.
7726 * @return ESN or null if error.
7727 */
7728 @Override
7729 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007730 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007731 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732
7733 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007734 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 if (phone == null) {
7736 return null;
7737 }
7738 String esn = null;
7739 try {
7740 esn = phone.getEsn();
7741 } catch (Exception e) {
7742 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7743 }
7744 return esn;
7745 } finally {
7746 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007747 }
Youhan Wang4001d252016-05-11 10:29:41 -07007748 }
7749
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007750 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007751 * Return the Preferred Roaming List Version.
7752 *
7753 * @param subId the subscription ID that this request applies to.
7754 * @return PRLVersion or null if error.
7755 */
7756 @Override
7757 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007758 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007759 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760
7761 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007762 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763 if (phone == null) {
7764 return null;
7765 }
7766 String cdmaPrlVersion = null;
7767 try {
7768 cdmaPrlVersion = phone.getCdmaPrlVersion();
7769 } catch (Exception e) {
7770 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7771 }
7772 return cdmaPrlVersion;
7773 } finally {
7774 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007775 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007776 }
7777
7778 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007779 * Get snapshot of Telephony histograms
7780 * @return List of Telephony histograms
7781 * @hide
7782 */
7783 @Override
7784 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7786 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007787
7788 final long identity = Binder.clearCallingIdentity();
7789 try {
7790 return RIL.getTelephonyRILTimingHistograms();
7791 } finally {
7792 Binder.restoreCallingIdentity(identity);
7793 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007794 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007795
7796 /**
7797 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007798 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7799 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007800 * Require system privileges. In the future we may add this to carrier APIs.
7801 *
Michele Berionne482f8202018-11-27 18:57:59 -08007802 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007803 */
7804 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007805 @TelephonyManager.SetCarrierRestrictionResult
7806 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007807 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007808 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007809
Michele Berionne482f8202018-11-27 18:57:59 -08007810 if (carrierRestrictionRules == null) {
7811 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007812 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 final long identity = Binder.clearCallingIdentity();
7815 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007816 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007817 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 } finally {
7819 Binder.restoreCallingIdentity(identity);
7820 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007821 }
7822
7823 /**
7824 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007825 * Get the allowed carrier list and the excluded carrier list, including the priority between
7826 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007827 * Require system privileges. In the future we may add this to carrier APIs.
7828 *
Michele Berionne482f8202018-11-27 18:57:59 -08007829 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007830 */
7831 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007832 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007833 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007834 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007835
7836 final long identity = Binder.clearCallingIdentity();
7837 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007838 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7839 if (response instanceof CarrierRestrictionRules) {
7840 return (CarrierRestrictionRules) response;
7841 }
7842 // Response is an Exception of some kind,
7843 // which is signalled to the user as a NULL retval
7844 return null;
7845 } catch (Exception e) {
7846 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7847 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848 } finally {
7849 Binder.restoreCallingIdentity(identity);
7850 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007851 }
7852
fionaxu59545b42016-05-25 15:53:37 -07007853 /**
fionaxu59545b42016-05-25 15:53:37 -07007854 * Action set from carrier signalling broadcast receivers to enable/disable radio
7855 * @param subId the subscription ID that this action applies to.
7856 * @param enabled control enable or disable radio.
7857 * {@hide}
7858 */
7859 @Override
7860 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7861 enforceModifyPermission();
7862 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007863
7864 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007865 if (phone == null) {
7866 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7867 return;
7868 }
7869 try {
7870 phone.carrierActionSetRadioEnabled(enabled);
7871 } catch (Exception e) {
7872 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 } finally {
7874 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007875 }
7876 }
7877
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007878 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007879 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7880 * network status based on which carrier apps could apply actions accordingly,
7881 * enable/disable default url handler for example.
7882 *
7883 * @param subId the subscription ID that this action applies to.
7884 * @param report control start/stop reporting the default network status.
7885 * {@hide}
7886 */
7887 @Override
7888 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7889 enforceModifyPermission();
7890 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891
7892 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007893 if (phone == null) {
7894 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7895 return;
7896 }
7897 try {
7898 phone.carrierActionReportDefaultNetworkStatus(report);
7899 } catch (Exception e) {
7900 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901 } finally {
7902 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007903 }
7904 }
7905
7906 /**
fionaxud9622282017-07-17 17:51:30 -07007907 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7908 * @param subId the subscription ID that this action applies to.
7909 * {@hide}
7910 */
7911 @Override
7912 public void carrierActionResetAll(int subId) {
7913 enforceModifyPermission();
7914 final Phone phone = getPhone(subId);
7915 if (phone == null) {
7916 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7917 return;
7918 }
7919 try {
7920 phone.carrierActionResetAll();
7921 } catch (Exception e) {
7922 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7923 }
7924 }
7925
7926 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007927 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7928 * bug report is being generated.
7929 */
7930 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007931 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007932 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7933 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007934 writer.println("Permission Denial: can't dump Phone from pid="
7935 + Binder.getCallingPid()
7936 + ", uid=" + Binder.getCallingUid()
7937 + "without permission "
7938 + android.Manifest.permission.DUMP);
7939 return;
7940 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007941 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007942 }
Jack Yueb89b242016-06-22 13:27:47 -07007943
Brad Ebingerdac2f002018-04-03 15:17:52 -07007944 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007945 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7946 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7947 @NonNull String[] args) {
7948 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7949 this, in.getFileDescriptor(), out.getFileDescriptor(),
7950 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007951 }
7952
Jack Yueb89b242016-06-22 13:27:47 -07007953 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007954 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007955 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007956 * @param reason the reason the data enable change is taking place
7957 * @param enabled True if enabling the data, otherwise disabling.
7958 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007959 */
7960 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007961 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007962 boolean enabled) {
7963 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7964 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7965 try {
7966 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007967 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007968 } catch (SecurityException se) {
7969 enforceModifyPermission();
7970 }
7971 } else {
7972 enforceModifyPermission();
7973 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007974
7975 final long identity = Binder.clearCallingIdentity();
7976 try {
7977 Phone phone = getPhone(subId);
7978 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007979 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7980 phone.carrierActionSetMeteredApnsEnabled(enabled);
7981 } else {
7982 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007984 }
7985 } finally {
7986 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007987 }
7988 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007989
7990 /**
7991 * Get Client request stats
7992 * @return List of Client Request Stats
7993 * @hide
7994 */
7995 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007996 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7997 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007998 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007999 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008000 return null;
8001 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008002 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004 final long identity = Binder.clearCallingIdentity();
8005 try {
8006 if (phone != null) {
8007 return phone.getClientRequestStats();
8008 }
8009
8010 return null;
8011 } finally {
8012 Binder.restoreCallingIdentity(identity);
8013 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008014 }
8015
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008016 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008017 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008018 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008019 }
Jack Yueb4124c2017-02-16 15:32:43 -08008020
8021 /**
Grace Chen70990072017-03-24 17:21:30 -07008022 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008023 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008024 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008025 * @param state State of SIM (power down, power up, pass through)
8026 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8027 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8028 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008029 *
8030 **/
8031 @Override
Grace Chen70990072017-03-24 17:21:30 -07008032 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008033 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008034 Phone phone = PhoneFactory.getPhone(slotIndex);
8035
vagdeviaf9a5b92018-08-15 16:01:53 -07008036 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8037
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 final long identity = Binder.clearCallingIdentity();
8039 try {
8040 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008041 phone.setSimPowerState(state, null, workSource);
8042 }
8043 } finally {
8044 Binder.restoreCallingIdentity(identity);
8045 }
8046 }
8047
8048 /**
8049 * Set SIM card power state.
8050 *
8051 * @param slotIndex SIM slot id.
8052 * @param state State of SIM (power down, power up, pass through)
8053 * @param callback callback to trigger after success or failure
8054 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8055 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8056 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8057 *
8058 **/
8059 @Override
8060 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8061 IIntegerConsumer callback) {
8062 enforceModifyPermission();
8063 Phone phone = PhoneFactory.getPhone(slotIndex);
8064
8065 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8066
8067 final long identity = Binder.clearCallingIdentity();
8068 try {
8069 if (phone != null) {
8070 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8071 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008072 }
8073 } finally {
8074 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008075 }
8076 }
Shuo Qiandd210312017-04-12 22:11:33 +00008077
Tyler Gunn65d45c22017-06-05 11:22:26 -07008078 private boolean isUssdApiAllowed(int subId) {
8079 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008080 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008081 if (configManager == null) {
8082 return false;
8083 }
8084 PersistableBundle pb = configManager.getConfigForSubId(subId);
8085 if (pb == null) {
8086 return false;
8087 }
8088 return pb.getBoolean(
8089 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8090 }
8091
Shuo Qiandd210312017-04-12 22:11:33 +00008092 /**
8093 * Check if phone is in emergency callback mode
8094 * @return true if phone is in emergency callback mode
8095 * @param subId sub id
8096 */
goneil9c5f4872017-12-05 14:07:56 -08008097 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008098 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008099 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008100 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008101
8102 final long identity = Binder.clearCallingIdentity();
8103 try {
8104 if (phone != null) {
8105 return phone.isInEcm();
8106 } else {
8107 return false;
8108 }
8109 } finally {
8110 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008111 }
8112 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008113
8114 /**
8115 * Get the current signal strength information for the given subscription.
8116 * Because this information is not updated when the device is in a low power state
8117 * it should not be relied-upon to be current.
8118 * @param subId Subscription index
8119 * @return the most recent cached signal strength info from the modem
8120 */
8121 @Override
8122 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008123 final long identity = Binder.clearCallingIdentity();
8124 try {
8125 Phone p = getPhone(subId);
8126 if (p == null) {
8127 return null;
8128 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008130 return p.getSignalStrength();
8131 } finally {
8132 Binder.restoreCallingIdentity(identity);
8133 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008134 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008135
Pengquan Meng77b7f132018-08-22 14:49:57 -07008136 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008137 * Get the current modem radio state for the given slot.
8138 * @param slotIndex slot index.
8139 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008140 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008141 * @return the current radio power state from the modem
8142 */
8143 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008144 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008145 Phone phone = PhoneFactory.getPhone(slotIndex);
8146 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008147 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8148 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008149 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8150 }
8151
8152 final long identity = Binder.clearCallingIdentity();
8153 try {
8154 return phone.getRadioPowerState();
8155 } finally {
8156 Binder.restoreCallingIdentity(identity);
8157 }
8158 }
8159 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8160 }
8161
8162 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008163 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8164 *
8165 * <p>Requires one of the following permissions:
8166 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8167 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8168 * privileges.
8169 *
8170 * @param subId subscription id
8171 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8172 * {@code false}.
8173 */
8174 @Override
8175 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008176 try {
8177 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8178 null);
8179 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008180 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008181 mApp, subId, "isDataRoamingEnabled");
8182 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008183
Pengquan Menga1bb6272018-09-06 09:59:22 -07008184 boolean isEnabled = false;
8185 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008186 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008187 Phone phone = getPhone(subId);
8188 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008189 } finally {
8190 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008191 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008192 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008193 }
8194
8195
8196 /**
8197 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8198 *
8199 * <p> Requires permission:
8200 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8201 * privileges.
8202 *
8203 * @param subId subscription id
8204 * @param isEnabled {@code true} means enable, {@code false} means disable.
8205 */
8206 @Override
8207 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8209 mApp, subId, "setDataRoamingEnabled");
8210
Pengquan Menga1bb6272018-09-06 09:59:22 -07008211 final long identity = Binder.clearCallingIdentity();
8212 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008213 Phone phone = getPhone(subId);
8214 if (phone != null) {
8215 phone.setDataRoamingEnabled(isEnabled);
8216 }
8217 } finally {
8218 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008219 }
8220 }
8221
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008222 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008223 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008224 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008225 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008226 mApp, subId, "isManualNetworkSelectionAllowed");
8227
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008228 boolean isAllowed = true;
8229 final long identity = Binder.clearCallingIdentity();
8230 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008231 Phone phone = getPhone(subId);
8232 if (phone != null) {
8233 isAllowed = phone.isCspPlmnEnabled();
8234 }
8235 } finally {
8236 Binder.restoreCallingIdentity(identity);
8237 }
8238 return isAllowed;
8239 }
8240
8241 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008242 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008243 // Verify that tha callingPackage belongs to the calling UID
8244 mApp.getSystemService(AppOpsManager.class)
8245 .checkPackage(Binder.getCallingUid(), callingPackage);
8246
Jordan Liu1e142fc2019-04-22 15:10:43 -07008247 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008248 try {
8249 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008250 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008251 } catch (SecurityException e) {
8252 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8253 // has carrier privileges on an active UICC
8254 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8255 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008256 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008257 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008258 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008259
8260 final long identity = Binder.clearCallingIdentity();
8261 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008262 UiccController uiccController = UiccController.getInstance();
8263 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008264 if (hasReadPermission) {
8265 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008266 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008267
8268 // Remove private info if the caller doesn't have access
8269 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8270 for (UiccCardInfo cardInfo : cardInfos) {
8271 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8272 // is available
8273 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8274 if (card == null || card.getUiccProfile() == null) {
8275 // assume no access if the card or profile is unavailable
8276 filteredInfos.add(cardInfo.getUnprivileged());
8277 continue;
8278 }
8279 UiccProfile profile = card.getUiccProfile();
8280 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8281 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8282 filteredInfos.add(cardInfo);
8283 } else {
8284 filteredInfos.add(cardInfo.getUnprivileged());
8285 }
8286 }
8287 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008288 } finally {
8289 Binder.restoreCallingIdentity(identity);
8290 }
8291 }
8292
8293 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008294 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008295 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297 final long identity = Binder.clearCallingIdentity();
8298 try {
8299 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8300 if (slots == null) {
8301 Rlog.i(LOG_TAG, "slots is null.");
8302 return null;
8303 }
8304
8305 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8306 for (int i = 0; i < slots.length; i++) {
8307 UiccSlot slot = slots[i];
8308 if (slot == null) {
8309 continue;
8310 }
8311
Jordan Liu7be7e652019-05-06 18:55:02 +00008312 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 UiccCard card = slot.getUiccCard();
8314 if (card != null) {
8315 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008316 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008317 cardId = slot.getEid();
8318 if (TextUtils.isEmpty(cardId)) {
8319 cardId = slot.getIccId();
8320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321 }
8322
Jordan Liu857451f2019-05-09 16:35:35 -07008323 if (cardId != null) {
8324 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8325 // if cardId is an EID, it's all digits so this is fine
8326 cardId = IccUtils.stripTrailingFs(cardId);
8327 }
8328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 int cardState = 0;
8330 switch (slot.getCardState()) {
8331 case CARDSTATE_ABSENT:
8332 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8333 break;
8334 case CARDSTATE_PRESENT:
8335 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8336 break;
8337 case CARDSTATE_ERROR:
8338 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8339 break;
8340 case CARDSTATE_RESTRICTED:
8341 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8342 break;
8343 default:
8344 break;
8345
8346 }
8347
8348 infos[i] = new UiccSlotInfo(
8349 slot.isActive(),
8350 slot.isEuicc(),
8351 cardId,
8352 cardState,
8353 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008354 slot.isExtendedApduSupported(),
8355 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008356 }
8357 return infos;
8358 } finally {
8359 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008360 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008361 }
8362
8363 @Override
8364 public boolean switchSlots(int[] physicalSlots) {
8365 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008366
8367 final long identity = Binder.clearCallingIdentity();
8368 try {
8369 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8370 } finally {
8371 Binder.restoreCallingIdentity(identity);
8372 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008373 }
Jack Yu4c988042018-02-27 15:30:01 -08008374
8375 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008376 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008377 final long identity = Binder.clearCallingIdentity();
8378 try {
8379 return UiccController.getInstance().getCardIdForDefaultEuicc();
8380 } finally {
8381 Binder.restoreCallingIdentity(identity);
8382 }
8383 }
8384
Pengquan Meng85728fb2018-03-12 16:31:21 -07008385 /**
goneil47ffb6e2018-04-06 15:40:58 -07008386 * A test API to reload the UICC profile.
8387 *
8388 * <p>Requires that the calling app has permission
8389 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8390 * @hide
8391 */
8392 @Override
8393 public void refreshUiccProfile(int subId) {
8394 enforceModifyPermission();
8395
8396 final long identity = Binder.clearCallingIdentity();
8397 try {
8398 Phone phone = getPhone(subId);
8399 if (phone == null) {
8400 return;
8401 }
8402 UiccCard uiccCard = phone.getUiccCard();
8403 if (uiccCard == null) {
8404 return;
8405 }
8406 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8407 if (uiccProfile == null) {
8408 return;
8409 }
8410 uiccProfile.refresh();
8411 } finally {
8412 Binder.restoreCallingIdentity(identity);
8413 }
8414 }
8415
8416 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008417 * Returns false if the mobile data is disabled by default, otherwise return true.
8418 */
8419 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008420 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008421 }
8422
8423 /**
8424 * Returns true if the data roaming is enabled by default, i.e the system property
8425 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8426 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8427 */
8428 private boolean getDefaultDataRoamingEnabled(int subId) {
8429 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008430 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008431 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008432 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8433 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8434 return isDataRoamingEnabled;
8435 }
8436
8437 /**
8438 * Returns the default network type for the given {@code subId}, if the default network type is
8439 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8440 */
8441 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008442 List<Integer> list = TelephonyProperties.default_network();
8443 int phoneId = mSubscriptionController.getPhoneId(subId);
8444 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8445 return list.get(phoneId);
8446 }
8447 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008448 }
fionaxua13278b2018-03-21 00:08:13 -07008449
8450 @Override
8451 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008452 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008453 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008454
8455 final long identity = Binder.clearCallingIdentity();
8456 try {
8457 final Phone phone = getPhone(subId);
8458 if (phone == null) {
8459 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8460 return;
8461 }
chen xueaba88a2019-03-15 13:15:10 -07008462 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8463 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008464 if (carrierPrivilegeRules == null) {
8465 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8466 } else {
8467 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008469 } finally {
8470 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008471 }
fionaxua13278b2018-03-21 00:08:13 -07008472 }
8473
8474 @Override
8475 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008476 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008477
8478 final long identity = Binder.clearCallingIdentity();
8479 try {
8480 final Phone phone = getPhone(subId);
8481 if (phone == null) {
8482 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8483 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8484 }
8485 return phone.getCarrierIdListVersion();
8486 } finally {
8487 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008488 }
fionaxua13278b2018-03-21 00:08:13 -07008489 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008490
8491 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008492 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8493 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008495 mApp, subId, callingPackage, callingFeatureId,
8496 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008497 return -1;
8498 }
8499
8500 final long identity = Binder.clearCallingIdentity();
8501 try {
8502 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
8505 }
8506 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008507
8508 @Override
8509 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008510 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008511 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008512 mApp, subId, "getCdmaRoamingMode");
8513
8514 final long identity = Binder.clearCallingIdentity();
8515 try {
8516 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
8520 }
8521
8522 @Override
8523 public boolean setCdmaRoamingMode(int subId, int mode) {
8524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8525 mApp, subId, "setCdmaRoamingMode");
8526
8527 final long identity = Binder.clearCallingIdentity();
8528 try {
8529 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
8532 }
8533 }
8534
8535 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008536 public int getCdmaSubscriptionMode(int subId) {
8537 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008538 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008539 mApp, subId, "getCdmaSubscriptionMode");
8540
8541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8544 } finally {
8545 Binder.restoreCallingIdentity(identity);
8546 }
8547 }
8548
8549 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008550 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8552 mApp, subId, "setCdmaSubscriptionMode");
8553
8554 final long identity = Binder.clearCallingIdentity();
8555 try {
8556 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8557 } finally {
8558 Binder.restoreCallingIdentity(identity);
8559 }
8560 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008561
sqianc5eccab2018-10-19 18:46:41 -07008562 @Override
sqian8c685422019-02-22 15:55:18 -08008563 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008564 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008566 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8567 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008568 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8569 }
8570 final long identity = Binder.clearCallingIdentity();
8571 try {
sqian854d44b2018-12-12 16:48:18 -08008572 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8573 for (Phone phone: PhoneFactory.getPhones()) {
8574 if (phone.getEmergencyNumberTracker() != null
8575 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8576 emergencyNumberListInternal.put(
8577 phone.getSubId(),
8578 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8579 }
sqian11b7a0e2018-12-05 18:48:28 -08008580 }
sqian854d44b2018-12-12 16:48:18 -08008581 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008582 } finally {
8583 Binder.restoreCallingIdentity(identity);
8584 }
sqianc5eccab2018-10-19 18:46:41 -07008585 }
8586
8587 @Override
sqian8c685422019-02-22 15:55:18 -08008588 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008589 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008590 if (!exactMatch) {
8591 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008592 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008593 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008594 }
8595 final long identity = Binder.clearCallingIdentity();
8596 try {
sqian854d44b2018-12-12 16:48:18 -08008597 for (Phone phone: PhoneFactory.getPhones()) {
8598 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008599 && phone.getEmergencyNumberTracker()
8600 .isEmergencyNumber(number, exactMatch)) {
8601 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008602 }
sqian11b7a0e2018-12-05 18:48:28 -08008603 }
8604 return false;
8605 } finally {
8606 Binder.restoreCallingIdentity(identity);
8607 }
8608 }
8609
sqianf4ca7ed2019-01-15 18:32:07 -08008610 /**
Shuo Qian479dd9e2021-02-22 18:32:21 -08008611 * Start emergency callback mode for GsmCdmaPhone for testing.
8612 */
8613 @Override
8614 public void startEmergencyCallbackMode() {
8615 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8616 "startEmergencyCallbackMode");
8617 enforceModifyPermission();
8618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 for (Phone phone : PhoneFactory.getPhones()) {
8621 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8622 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8623 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8624 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8625 gsmCdmaPhone.obtainMessage(
8626 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8627 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8628 }
8629 }
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
8633 }
8634
8635 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008636 * Update emergency number list for test mode.
8637 */
8638 @Override
8639 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8640 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8641 "updateEmergencyNumberListTestMode");
8642
8643 final long identity = Binder.clearCallingIdentity();
8644 try {
8645 for (Phone phone: PhoneFactory.getPhones()) {
8646 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8647 if (tracker != null) {
8648 tracker.executeEmergencyNumberTestModeCommand(action, num);
8649 }
8650 }
8651 } finally {
8652 Binder.restoreCallingIdentity(identity);
8653 }
8654 }
8655
8656 /**
8657 * Get the full emergency number list for test mode.
8658 */
8659 @Override
8660 public List<String> getEmergencyNumberListTestMode() {
8661 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8662 "getEmergencyNumberListTestMode");
8663
8664 final long identity = Binder.clearCallingIdentity();
8665 try {
8666 Set<String> emergencyNumbers = new HashSet<>();
8667 for (Phone phone: PhoneFactory.getPhones()) {
8668 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8669 if (tracker != null) {
8670 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8671 emergencyNumbers.add(num.getNumber());
8672 }
8673 }
8674 }
8675 return new ArrayList<>(emergencyNumbers);
8676 } finally {
8677 Binder.restoreCallingIdentity(identity);
8678 }
8679 }
8680
chen xud6b45bd2018-10-30 22:27:10 -07008681 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008682 public int getEmergencyNumberDbVersion(int subId) {
8683 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8684
8685 final long identity = Binder.clearCallingIdentity();
8686 try {
8687 final Phone phone = getPhone(subId);
8688 if (phone == null) {
8689 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8690 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8691 }
8692 return phone.getEmergencyNumberDbVersion();
8693 } finally {
8694 Binder.restoreCallingIdentity(identity);
8695 }
8696 }
8697
8698 @Override
8699 public void notifyOtaEmergencyNumberDbInstalled() {
8700 enforceModifyPermission();
8701
8702 final long identity = Binder.clearCallingIdentity();
8703 try {
8704 for (Phone phone: PhoneFactory.getPhones()) {
8705 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8706 if (tracker != null) {
8707 tracker.updateOtaEmergencyNumberDatabase();
8708 }
8709 }
8710 } finally {
8711 Binder.restoreCallingIdentity(identity);
8712 }
8713 }
8714
8715 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008716 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008717 enforceActiveEmergencySessionPermission();
8718
8719 final long identity = Binder.clearCallingIdentity();
8720 try {
8721 for (Phone phone: PhoneFactory.getPhones()) {
8722 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8723 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008724 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8725 }
8726 }
8727 } finally {
8728 Binder.restoreCallingIdentity(identity);
8729 }
8730 }
8731
8732 @Override
8733 public void resetOtaEmergencyNumberDbFilePath() {
8734 enforceActiveEmergencySessionPermission();
8735
8736 final long identity = Binder.clearCallingIdentity();
8737 try {
8738 for (Phone phone: PhoneFactory.getPhones()) {
8739 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8740 if (tracker != null) {
8741 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008742 }
8743 }
8744 } finally {
8745 Binder.restoreCallingIdentity(identity);
8746 }
8747 }
8748
8749 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008750 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8751 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8752 Phone phone = getPhone(subId);
8753 if (phone == null) {
8754 return null;
8755 }
8756 final long identity = Binder.clearCallingIdentity();
8757 try {
8758 UiccProfile profile = UiccController.getInstance()
8759 .getUiccProfileForPhone(phone.getPhoneId());
8760 if (profile != null) {
8761 return profile.getCertsFromCarrierPrivilegeAccessRules();
8762 }
8763 } finally {
8764 Binder.restoreCallingIdentity(identity);
8765 }
8766 return null;
8767 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008768
8769 /**
8770 * Enable or disable a modem stack.
8771 */
8772 @Override
8773 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8774 enforceModifyPermission();
8775
8776 final long identity = Binder.clearCallingIdentity();
8777 try {
8778 Phone phone = PhoneFactory.getPhone(slotIndex);
8779 if (phone == null) {
8780 return false;
8781 } else {
8782 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8783 }
8784 } finally {
8785 Binder.restoreCallingIdentity(identity);
8786 }
8787 }
Michelecea4cf22018-12-21 15:00:11 -08008788
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008789 /**
8790 * Whether a modem stack is enabled or not.
8791 */
8792 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008793 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8794 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008795 Phone phone = PhoneFactory.getPhone(slotIndex);
8796 if (phone == null) return false;
8797
8798 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008799 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8800 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008801 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8802 }
8803
8804 final long identity = Binder.clearCallingIdentity();
8805 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008806 try {
8807 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8808 } catch (NoSuchElementException ex) {
8809 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8810 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008811 } finally {
8812 Binder.restoreCallingIdentity(identity);
8813 }
8814 }
8815
Michelecea4cf22018-12-21 15:00:11 -08008816 @Override
Michele0ea7d782019-03-19 14:58:42 -07008817 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008818 enforceModifyPermission();
8819
8820 final long identity = Binder.clearCallingIdentity();
8821 try {
8822 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008823 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008824 .commit();
8825 } finally {
8826 Binder.restoreCallingIdentity(identity);
8827 }
8828 }
8829
8830 @Override
Michele0ea7d782019-03-19 14:58:42 -07008831 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008832 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008834 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8835 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008836 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008837 }
Michelecea4cf22018-12-21 15:00:11 -08008838
8839 final long identity = Binder.clearCallingIdentity();
8840 try {
Michele0ea7d782019-03-19 14:58:42 -07008841 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008842 } finally {
8843 Binder.restoreCallingIdentity(identity);
8844 }
8845 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008846
Michele0ea7d782019-03-19 14:58:42 -07008847 @TelephonyManager.IsMultiSimSupportedResult
8848 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008849 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8850 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8851 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008852 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8853 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008854 }
8855 // Check if the hardware supports multisim functionality. If usage of multisim is not
8856 // supported by the modem, indicate that it is restricted.
8857 PhoneCapability staticCapability =
8858 mPhoneConfigurationManager.getStaticPhoneCapability();
8859 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008860 loge("isMultiSimSupportedInternal: no static configuration available");
8861 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008862 }
SongFerngWang2c4309d2021-01-17 21:51:44 +08008863 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008864 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8865 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008866 }
8867 // Check if support of multiple SIMs is restricted by carrier
8868 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008869 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008870 }
8871
Michele0ea7d782019-03-19 14:58:42 -07008872 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008873 }
8874
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008875 /**
8876 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008877 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8878 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8879 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008880 * @param numOfSims number of active sims we want to switch to
8881 */
8882 @Override
8883 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008884 if (numOfSims == 1) {
8885 enforceModifyPermission();
8886 } else {
8887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8888 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8889 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008890 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008891
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008892 try {
Michele30b57b22019-03-01 12:01:14 -08008893 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008894 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008895 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8896 return;
8897 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008898 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8899 } finally {
8900 Binder.restoreCallingIdentity(identity);
8901 }
8902 }
8903
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008904 @Override
8905 public boolean isApplicationOnUicc(int subId, int appType) {
8906 enforceReadPrivilegedPermission("isApplicationOnUicc");
8907 Phone phone = getPhone(subId);
8908 if (phone == null) {
8909 return false;
8910 }
8911 final long identity = Binder.clearCallingIdentity();
8912 try {
8913 UiccCard uiccCard = phone.getUiccCard();
8914 if (uiccCard == null) {
8915 return false;
8916 }
8917 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8918 if (uiccProfile == null) {
8919 return false;
8920 }
8921 if (TelephonyManager.APPTYPE_SIM <= appType
8922 && appType <= TelephonyManager.APPTYPE_ISIM) {
8923 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8924 }
8925 return false;
8926 } finally {
8927 Binder.restoreCallingIdentity(identity);
8928 }
8929 }
8930
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008931 /**
chen xub4baa772019-04-03 10:23:41 -07008932 * Get whether making changes to modem configurations will trigger reboot.
8933 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008934 */
8935 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008936 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8937 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008938 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008939 mApp, subId, callingPackage, callingFeatureId,
8940 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008941 return false;
8942 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008943 final long identity = Binder.clearCallingIdentity();
8944 try {
8945 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8946 } finally {
8947 Binder.restoreCallingIdentity(identity);
8948 }
8949 }
8950
Nathan Harold29f5f052019-02-15 13:41:57 -08008951 private void updateModemStateMetrics() {
8952 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8953 // TODO: check the state for each modem if the api is ready.
8954 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8955 }
8956
Pengquan Meng3889a572019-01-23 11:16:29 -08008957 @Override
8958 public int[] getSlotsMapping() {
8959 enforceReadPrivilegedPermission("getSlotsMapping");
8960
8961 final long identity = Binder.clearCallingIdentity();
8962 try {
8963 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8964 // All logical slots should have a mapping to a physical slot.
8965 int[] logicalSlotsMapping = new int[phoneCount];
8966 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8967 for (int i = 0; i < slotInfos.length; i++) {
8968 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8969 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8970 }
8971 }
8972 return logicalSlotsMapping;
8973 } finally {
8974 Binder.restoreCallingIdentity(identity);
8975 }
8976 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008977
8978 /**
8979 * Get the IRadio HAL Version
8980 */
8981 @Override
8982 public int getRadioHalVersion() {
8983 Phone phone = getDefaultPhone();
8984 if (phone == null) return -1;
8985 HalVersion hv = phone.getHalVersion();
8986 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8987 return hv.major * 100 + hv.minor;
8988 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008989
8990 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008991 * Get the current calling package name.
8992 * @return the current calling package name
8993 */
8994 @Override
8995 public String getCurrentPackageName() {
8996 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8997 }
8998
8999 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009000 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9001 * corresponding network requests on a subId.
9002 *
9003 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009004 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009005 * 2) APN is un-metered for this subscription, or
9006 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07009007 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009008 *
9009 * @return whether data is allowed for a apn type.
9010 *
9011 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009012 */
9013 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009014 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009015 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9016 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009017
9018 // Now that all security checks passes, perform the operation as ourselves.
9019 final long identity = Binder.clearCallingIdentity();
9020 try {
9021 Phone phone = getPhone(subId);
9022 if (phone == null) return false;
9023
Jack Yu41407ee2019-05-13 16:54:09 -07009024 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009025 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9026 } finally {
9027 Binder.restoreCallingIdentity(identity);
9028 }
9029 }
9030
9031 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009032 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009033 enforceReadPrivilegedPermission("isApnMetered");
9034
9035 // Now that all security checks passes, perform the operation as ourselves.
9036 final long identity = Binder.clearCallingIdentity();
9037 try {
9038 Phone phone = getPhone(subId);
9039 if (phone == null) return true; // By default return true.
9040
Jack Yu41407ee2019-05-13 16:54:09 -07009041 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009042 } finally {
9043 Binder.restoreCallingIdentity(identity);
9044 }
9045 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009046
9047 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009048 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9049 int subscriptionId, IBooleanConsumer resultCallback) {
9050 enforceModifyPermission();
9051 long token = Binder.clearCallingIdentity();
9052 try {
9053 Phone phone = getPhone(subscriptionId);
9054 if (phone == null) {
9055 try {
9056 if (resultCallback != null) {
9057 resultCallback.accept(false);
9058 }
9059 } catch (RemoteException e) {
9060 // ignore
9061 }
9062 return;
9063 }
9064 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9065 Pair.create(specifiers, (x) -> {
9066 try {
9067 if (resultCallback != null) {
9068 resultCallback.accept(x);
9069 }
9070 } catch (RemoteException e) {
9071 // ignore
9072 }
9073 });
9074 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9075 } finally {
9076 Binder.restoreCallingIdentity(token);
9077 }
9078 }
9079
9080 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009081 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9082 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07009083 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08009084 mApp, subId, "getSystemSelectionChannels");
9085 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9086 final long identity = Binder.clearCallingIdentity();
9087 try {
Sarah Chin58691872021-03-13 03:17:40 -08009088 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9089 if (result instanceof IllegalStateException) {
9090 throw (IllegalStateException) result;
9091 }
9092 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chincc055732020-11-18 13:39:35 -08009093 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9094 return specifiers;
9095 } finally {
9096 Binder.restoreCallingIdentity(identity);
9097 }
9098 }
9099
9100 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009101 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009102 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009103 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9104 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9105 if (iccRecords == null) {
9106 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9107 return false;
9108 }
9109 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9110 }
9111
9112 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009113 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9114 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009115 if (callingPackage == null) {
9116 callingPackage = getCurrentPackageName();
9117 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009118 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9119 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009120 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9121 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009122 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9123 }
9124 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9125 Intent intent = new Intent();
9126 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9127 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9128 // Bring up choose default SMS subscription dialog right now
9129 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9130 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9131 mApp.startActivity(intent);
9132 }
chen xud5ca2d52019-05-28 15:20:57 -07009133
9134 @Override
9135 public String getMmsUAProfUrl(int subId) {
9136 //TODO investigate if this API should require proper permission check in R b/133791609
9137 final long identity = Binder.clearCallingIdentity();
9138 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009139 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9140 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9141 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9142 return carrierUAProfUrl;
9143 }
chen xud5ca2d52019-05-28 15:20:57 -07009144 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9145 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9146 } finally {
9147 Binder.restoreCallingIdentity(identity);
9148 }
9149 }
9150
9151 @Override
9152 public String getMmsUserAgent(int subId) {
9153 //TODO investigate if this API should require proper permission check in R b/133791609
9154 final long identity = Binder.clearCallingIdentity();
9155 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009156 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9157 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9158 if (!TextUtils.isEmpty(carrierUserAgent)) {
9159 return carrierUserAgent;
9160 }
chen xud5ca2d52019-05-28 15:20:57 -07009161 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9162 .getString(com.android.internal.R.string.config_mms_user_agent);
9163 } finally {
9164 Binder.restoreCallingIdentity(identity);
9165 }
9166 }
Jack Yub07d4972019-05-28 16:12:25 -07009167
9168 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009169 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9170 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9171
9172 final long identity = Binder.clearCallingIdentity();
9173 try {
9174 Phone phone = getPhone(subscriptionId);
9175 if (phone == null) return false;
9176
9177 switch (policy) {
9178 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9179 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9180 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9181 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9182 default:
9183 throw new IllegalArgumentException(policy + " is not a valid policy");
9184 }
9185 } finally {
9186 Binder.restoreCallingIdentity(identity);
9187 }
9188 }
9189
9190 @Override
9191 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9192 boolean enabled) {
9193 enforceModifyPermission();
9194
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 Phone phone = getPhone(subscriptionId);
9198 if (phone == null) return;
9199
9200 switch (policy) {
9201 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9202 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9203 break;
9204 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9205 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9206 break;
9207 default:
9208 throw new IllegalArgumentException(policy + " is not a valid policy");
9209 }
9210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
9213 }
9214
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009215 /**
Hall Liub48cf452020-09-25 11:13:49 -07009216 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009217 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9218 * otherwise.
9219 */
9220 @Override
9221 public void setCepEnabled(boolean isCepEnabled) {
9222 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9223
9224 final long identity = Binder.clearCallingIdentity();
9225 try {
9226 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9227 for (Phone phone : PhoneFactory.getPhones()) {
9228 Phone defaultPhone = phone.getImsPhone();
9229 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9230 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9231 ImsPhoneCallTracker imsPhoneCallTracker =
9232 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9233 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9234 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9235 + imsPhone.getMsisdn());
9236 }
9237 }
9238 } finally {
9239 Binder.restoreCallingIdentity(identity);
9240 }
9241 }
allenwtsu46dcc572020-01-08 18:24:03 +08009242
9243 /**
9244 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9245 *
9246 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9247 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9248 * before being read.
9249 */
9250 @Override
9251 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9252 isCompressed) {
9253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9254 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009255 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9256 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9257 }
9258 if (!isImsAvailableOnDevice()) {
9259 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9260 "IMS not available on device.");
9261 }
9262
9263 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009264 try {
Hui Wang068ab862020-10-31 05:12:53 +00009265 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9266 } finally {
9267 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009268 }
9269 }
zoey chenf95ca592019-12-30 16:11:23 +08009270
9271 @Override
9272 public boolean isIccLockEnabled(int subId) {
9273 enforceReadPrivilegedPermission("isIccLockEnabled");
9274
9275 // Now that all security checks passes, perform the operation as ourselves.
9276 final long identity = Binder.clearCallingIdentity();
9277 try {
9278 Phone phone = getPhone(subId);
9279 if (phone != null && phone.getIccCard() != null) {
9280 return phone.getIccCard().getIccLockEnabled();
9281 } else {
9282 return false;
9283 }
9284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 }
9288
9289 /**
zoey chene02881a2019-12-30 16:11:23 +08009290 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009291 *
zoey chene02881a2019-12-30 16:11:23 +08009292 * @return an integer representing the status of IccLock enabled or disabled in the following
9293 * three cases:
9294 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9295 * successfully.
9296 * - Positive number and zero for remaining password attempts.
9297 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009298 *
9299 */
9300 @Override
9301 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9302 enforceModifyPermission();
9303
9304 Phone phone = getPhone(subId);
9305 if (phone == null) {
9306 return 0;
9307 }
9308 // Now that all security checks passes, perform the operation as ourselves.
9309 final long identity = Binder.clearCallingIdentity();
9310 try {
9311 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9312 new Pair<Boolean, String>(enabled, password), phone, null);
9313 return attemptsRemaining;
9314
9315 } catch (Exception e) {
9316 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9317 } finally {
9318 Binder.restoreCallingIdentity(identity);
9319 }
9320 return 0;
9321 }
9322
9323 /**
9324 * Change the ICC password used in ICC pin lock.
9325 *
zoey chene02881a2019-12-30 16:11:23 +08009326 * @return an integer representing the status of IccLock changed in the following three cases:
9327 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9328 * - Positive number and zero for remaining password attempts.
9329 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009330 *
9331 */
9332 @Override
9333 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9334 enforceModifyPermission();
9335
9336 Phone phone = getPhone(subId);
9337 if (phone == null) {
9338 return 0;
9339 }
9340 // Now that all security checks passes, perform the operation as ourselves.
9341 final long identity = Binder.clearCallingIdentity();
9342 try {
9343 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9344 new Pair<String, String>(oldPassword, newPassword), phone, null);
9345 return attemptsRemaining;
9346
9347 } catch (Exception e) {
9348 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9349 } finally {
9350 Binder.restoreCallingIdentity(identity);
9351 }
9352 return 0;
9353 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009354
Peter Wangdafb9ac2020-01-15 14:13:38 -08009355 /**
9356 * Request for receiving user activity notification
9357 */
9358 @Override
9359 public void requestUserActivityNotification() {
9360 if (!mNotifyUserActivity.get()
9361 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9362 mNotifyUserActivity.set(true);
9363 }
9364 }
9365
9366 /**
9367 * Called when userActivity is signalled in the power manager.
9368 * This is safe to call from any thread, with any window manager locks held or not.
9369 */
9370 @Override
9371 public void userActivity() {
9372 // ***************************************
9373 // * Inherited from PhoneWindowManager *
9374 // ***************************************
9375 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9376 // WITH ITS LOCKS HELD.
9377 //
9378 // This code must be VERY careful about the locks
9379 // it acquires.
9380 // In fact, the current code acquires way too many,
9381 // and probably has lurking deadlocks.
9382
9383 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9384 throw new SecurityException("Only the OS may call notifyUserActivity()");
9385 }
9386
9387 if (mNotifyUserActivity.getAndSet(false)) {
9388 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9389 USER_ACTIVITY_NOTIFICATION_DELAY);
9390 }
9391 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009392
Malcolm Chen884180b2020-04-13 11:59:40 -07009393 @Override
9394 public boolean canConnectTo5GInDsdsMode() {
9395 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9396 }
Jack Yud10cdd42020-09-28 20:28:01 -07009397
9398 @Override
9399 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9400 String callingFeatureId) {
9401 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9402 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9403 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9404 }
9405
9406 Phone phone = getPhone(subId);
9407 if (phone == null) {
9408 throw new RuntimeException("phone is not available");
9409 }
9410 // Now that all security checks passes, perform the operation as ourselves.
9411 final long identity = Binder.clearCallingIdentity();
9412 try {
9413 return phone.getEquivalentHomePlmns();
9414 } finally {
9415 Binder.restoreCallingIdentity(identity);
9416 }
9417 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009418
Hui Wang0866fcc2020-10-12 12:14:23 -07009419 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009420 public boolean isRadioInterfaceCapabilitySupported(
9421 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009422 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009423 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009424 if (radioInterfaceCapabilities == null) {
9425 throw new RuntimeException("radio interface capabilities are not available");
9426 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009427 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009428 }
9429 }
9430
9431 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009432 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9433 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009434 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9435 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9436 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9437 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9438 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009439 if (DBG) {
9440 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9441 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9442 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9443 }
9444
9445 if (!SubscriptionManager.isValidSubscriptionId(subId)
9446 || appType < TelephonyManager.APPTYPE_UNKNOWN
9447 || appType > TelephonyManager.APPTYPE_ISIM
9448 || nafUrl == null || securityProtocol == null || callback == null) {
9449 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9450 if (callback != null) {
9451 try {
9452 callback.onAuthenticationFailure(
9453 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9454 } catch (RemoteException exception) {
9455 log("Fail to notify onAuthenticationFailure due to " + exception);
9456 }
9457 return;
9458 }
9459 }
9460
9461 final long token = Binder.clearCallingIdentity();
9462 try {
9463 getGbaManager(subId).bootstrapAuthenticationRequest(
9464 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9465 forceBootStrapping, callback));
9466 } finally {
9467 Binder.restoreCallingIdentity(token);
9468 }
9469 }
9470
Jack Nudelman24d51a52020-11-24 12:08:04 -08009471 /**
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009472 * Attempts to set the radio power state for all phones for thermal reason.
9473 * This does not guarantee that the
Jack Nudelman24d51a52020-11-24 12:08:04 -08009474 * requested radio power state will actually be set. See {@link
9475 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9476 *
Jack Nudelman24d51a52020-11-24 12:08:04 -08009477 * @param enable {@code true} if trying to turn radio on.
9478 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9479 * false}.
9480 */
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009481 private boolean setRadioPowerForThermal(boolean enable) {
9482 boolean isPhoneAvailable = false;
9483 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9484 Phone phone = PhoneFactory.getPhone(i);
9485 if (phone != null) {
9486 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9487 isPhoneAvailable = true;
9488 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009489 }
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009490
9491 // return true if successfully informed the phone object about the thermal radio power
9492 // request.
9493 return isPhoneAvailable;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009494 }
9495
9496 private int handleDataThrottlingRequest(int subId,
9497 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009498 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9499 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9500 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9501 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9502 throw new IllegalArgumentException("modem does not support data throttling");
9503 }
9504
Jack Nudelman24d51a52020-11-24 12:08:04 -08009505 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9506 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009507 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009508 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9509 }
9510
9511 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9512
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009513 if (isDataThrottlingSupported) {
9514 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009515 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009516 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9517 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9518 } else if (thermalMitigationResult
9519 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman20352592021-05-20 13:57:30 -07009520 log("Modem likely does not support data throttling on secondary carrier. Data " +
9521 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9522 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009523 }
9524 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009525 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009526
9527 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009528 }
9529
Jack Nudelman644b91a2021-03-12 14:09:48 -08009530 private static List<String> getThermalMitigationAllowlist(Context context) {
9531 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9532 for (String pckg : context.getResources()
9533 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9534 sThermalMitigationAllowlistedPackages.add(pckg);
9535 }
9536 }
9537
9538 return sThermalMitigationAllowlistedPackages;
9539 }
9540
Jack Nudelmane634f962021-05-13 10:00:15 -07009541 private boolean isAnyPhoneInEmergencyState() {
9542 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9543 if (tm.isInEmergencyCall()) {
9544 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9545 return true;
9546 }
9547 for (Phone phone : PhoneFactory.getPhones()) {
9548 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9549 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9550 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9551 + phone.isInEcm());
9552 return true;
9553 }
9554 }
9555
9556 return false;
9557 }
9558
Jack Nudelman644b91a2021-03-12 14:09:48 -08009559 /**
9560 * Used by shell commands to add an authorized package name for thermal mitigation.
9561 * @param packageName name of package to be allowlisted
9562 * @param context
9563 */
9564 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9565 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9566 sThermalMitigationAllowlistedPackages.add(packageName);
9567 }
9568
9569 /**
9570 * Used by shell commands to remove an authorized package name for thermal mitigation.
9571 * @param packageName name of package to remove from allowlist
9572 * @param context
9573 */
9574 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9575 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9576 sThermalMitigationAllowlistedPackages.remove(packageName);
9577 }
9578
Jack Nudelman24d51a52020-11-24 12:08:04 -08009579 /**
9580 * Thermal mitigation request to control functionalities at modem.
9581 *
9582 * @param subId the id of the subscription.
9583 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009584 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009585 *
9586 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9587 */
9588 @Override
9589 @ThermalMitigationResult
9590 public int sendThermalMitigationRequest(
9591 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009592 ThermalMitigationRequest thermalMitigationRequest,
9593 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009594 enforceModifyPermission();
9595
Jack Nudelman644b91a2021-03-12 14:09:48 -08009596 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9597 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9598 .contains(callingPackage)) {
9599 throw new SecurityException("Calling package must be configured in the device config. "
9600 + "calling package: " + callingPackage);
9601 }
9602
Jack Nudelman24d51a52020-11-24 12:08:04 -08009603 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9604 final long identity = Binder.clearCallingIdentity();
9605
9606 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9607 try {
9608 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9609 switch (thermalMitigationAction) {
9610 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9611 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009612 handleDataThrottlingRequest(subId,
9613 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009614 break;
9615 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9616 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9617 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9618 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9619 }
9620
9621 // Ensure that radio is on. If not able to power on due to phone being
9622 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009623 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009624 thermalMitigationResult =
9625 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9626 break;
9627 }
9628
9629 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9630 false);
9631 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9632 break;
9633 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9634 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9635 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9636 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9637 }
9638
9639 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9640 if (registry != null) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009641 Phone phone = getPhone(subId);
9642 if (phone == null) {
9643 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009644 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009645 break;
9646 }
9647
Jack Nudelmane634f962021-05-13 10:00:15 -07009648 TelephonyConnectionService service =
9649 registry.getTelephonyConnectionService();
Jack Nudelmana80c0012021-06-17 15:39:58 -07009650 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane634f962021-05-13 10:00:15 -07009651 Log.e(LOG_TAG, "An emergency call is pending");
9652 thermalMitigationResult =
9653 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9654 break;
9655 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009656 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009657 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009658 break;
9659 }
9660 } else {
9661 thermalMitigationResult =
9662 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9663 break;
9664 }
9665
9666 // Turn radio off. If not able to power off due to phone being unavailable,
9667 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009668 if (!setRadioPowerForThermal(false)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009669 thermalMitigationResult =
9670 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9671 break;
9672 }
9673 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009674 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009675 break;
9676 default:
9677 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9678 + "not exist. Requested action: " + thermalMitigationAction);
9679 }
9680 } catch (IllegalArgumentException e) {
9681 throw e;
9682 } catch (Exception e) {
9683 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9684 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9685 } finally {
9686 Binder.restoreCallingIdentity(identity);
9687 }
9688
9689 if (DBG) {
9690 log("thermalMitigationRequest returning with thermalMitigationResult: "
9691 + thermalMitigationResult);
9692 }
9693
9694 return thermalMitigationResult;
9695 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009696
9697 /**
9698 * Set the GbaService Package Name that Telephony will bind to.
9699 *
9700 * @param subId The sim that the GbaService is associated with.
9701 * @param packageName The name of the package to be replaced with.
9702 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9703 */
9704 @Override
9705 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9706 enforceModifyPermission();
9707
9708 final long identity = Binder.clearCallingIdentity();
9709 try {
9710 return getGbaManager(subId).overrideServicePackage(packageName);
9711 } finally {
9712 Binder.restoreCallingIdentity(identity);
9713 }
9714 }
9715
9716 /**
9717 * Return the package name of the currently bound GbaService.
9718 *
9719 * @param subId The sim that the GbaService is associated with.
9720 * @return the package name of the GbaService configuration, null if GBA is not supported.
9721 */
9722 @Override
9723 public String getBoundGbaService(int subId) {
9724 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9725
9726 final long identity = Binder.clearCallingIdentity();
9727 try {
9728 return getGbaManager(subId).getServicePackage();
9729 } finally {
9730 Binder.restoreCallingIdentity(identity);
9731 }
9732 }
9733
9734 /**
9735 * Set the release time for telephony to unbind GbaService.
9736 *
9737 * @param subId The sim that the GbaService is associated with.
9738 * @param interval The release time to unbind GbaService by millisecond.
9739 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9740 */
9741 @Override
9742 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9743 enforceModifyPermission();
9744
9745 final long identity = Binder.clearCallingIdentity();
9746 try {
9747 return getGbaManager(subId).overrideReleaseTime(interval);
9748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
9752
9753 /**
9754 * Return the release time for telephony to unbind GbaService.
9755 *
9756 * @param subId The sim that the GbaService is associated with.
9757 * @return The release time to unbind GbaService by millisecond.
9758 */
9759 @Override
9760 public int getGbaReleaseTime(int subId) {
9761 enforceReadPrivilegedPermission("getGbaReleaseTime");
9762
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
9765 return getGbaManager(subId).getReleaseTime();
9766 } finally {
9767 Binder.restoreCallingIdentity(identity);
9768 }
9769 }
9770
9771 private GbaManager getGbaManager(int subId) {
9772 GbaManager instance = GbaManager.getInstance(subId);
9773 if (instance == null) {
9774 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9775 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9776 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9777 }
9778 return instance;
9779 }
Hui Wang068ab862020-10-31 05:12:53 +00009780
9781 /**
9782 * indicate whether the device and the carrier can support
9783 * RCS VoLTE single registration.
9784 */
9785 @Override
9786 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009787 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9788 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9789 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9790 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009791
9792 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9793 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9794 }
9795
9796 final long identity = Binder.clearCallingIdentity();
9797 try {
9798 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9799 if (rpm != null) {
Hui Wang048c10a2021-06-21 18:05:57 +00009800 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
9801 if (isCapable != null) {
9802 return isCapable;
9803 }
Hui Wang068ab862020-10-31 05:12:53 +00009804 }
Hui Wang048c10a2021-06-21 18:05:57 +00009805 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
9806 "service is temporarily unavailable.");
Hui Wang068ab862020-10-31 05:12:53 +00009807 } finally {
9808 Binder.restoreCallingIdentity(identity);
9809 }
9810 }
9811
9812 /**
9813 * Register RCS provisioning callback.
9814 */
9815 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009816 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009817 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009818 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009819 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009820 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9821 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009822
9823 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9824 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9825 }
9826 if (!isImsAvailableOnDevice()) {
9827 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9828 "IMS not available on device.");
9829 }
9830
9831 final long identity = Binder.clearCallingIdentity();
9832 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009833 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009834 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009835 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9836 "Service not available for the subscription.");
9837 }
Hui Wang068ab862020-10-31 05:12:53 +00009838 } finally {
9839 Binder.restoreCallingIdentity(identity);
9840 }
9841 }
9842
9843 /**
9844 * Unregister RCS provisioning callback.
9845 */
9846 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009847 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009848 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009849 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009850 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009851 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9852 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009853
9854 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9855 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9856 }
9857 if (!isImsAvailableOnDevice()) {
9858 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9859 "IMS not available on device.");
9860 }
9861
9862 final long identity = Binder.clearCallingIdentity();
9863 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009864 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009865 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009866 } finally {
9867 Binder.restoreCallingIdentity(identity);
9868 }
9869 }
9870
9871 /**
9872 * trigger RCS reconfiguration.
9873 */
9874 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009875 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9876 "triggerRcsReconfiguration",
9877 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009878
9879 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9880 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9881 }
9882 if (!isImsAvailableOnDevice()) {
9883 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9884 "IMS not available on device.");
9885 }
9886
9887 final long identity = Binder.clearCallingIdentity();
9888 try {
9889 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9890 } finally {
9891 Binder.restoreCallingIdentity(identity);
9892 }
9893 }
9894
9895 /**
9896 * Provide the client configuration parameters of the RCS application.
9897 */
9898 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009899 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9900 "setRcsClientConfiguration",
9901 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009902
9903 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9904 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9905 }
9906 if (!isImsAvailableOnDevice()) {
9907 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9908 "IMS not available on device.");
9909 }
9910
9911 final long identity = Binder.clearCallingIdentity();
9912
9913 try {
9914 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9915 if (configBinder == null) {
9916 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9917 } else {
9918 configBinder.setRcsClientConfiguration(rcc);
9919 }
9920 } catch (RemoteException e) {
9921 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9922 } finally {
9923 Binder.restoreCallingIdentity(identity);
9924 }
9925 }
9926
9927 /**
Hui Wang19a21872021-02-19 20:45:36 -08009928 * Enables or disables the test mode for RCS VoLTE single registration.
9929 */
9930 @Override
9931 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9932 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9933 "setRcsSingleRegistrationTestModeEnabled");
9934
9935 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9936 }
9937
9938 /**
9939 * Gets the test mode for RCS VoLTE single registration.
9940 */
9941 @Override
9942 public boolean getRcsSingleRegistrationTestModeEnabled() {
9943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9944 "getRcsSingleRegistrationTestModeEnabled");
9945
9946 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9947 }
9948
9949 /**
Hui Wang068ab862020-10-31 05:12:53 +00009950 * Overrides the config of RCS VoLTE single registration enabled for the device.
9951 */
9952 @Override
9953 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9954 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9955 "setDeviceSingleRegistrationEnabledOverride");
9956 enforceModifyPermission();
9957
9958 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9959 : Boolean.parseBoolean(enabledStr);
9960 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009961 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009962 }
9963
9964 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009965 * Sends a device to device communication message. Only usable via shell.
9966 * @param message message to send.
9967 * @param value message value.
9968 */
9969 @Override
9970 public void sendDeviceToDeviceMessage(int message, int value) {
9971 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9972 "setCarrierSingleRegistrationEnabledOverride");
9973 enforceModifyPermission();
9974
9975 final long identity = Binder.clearCallingIdentity();
9976 try {
9977 TelephonyConnectionService service =
9978 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9979 if (service == null) {
9980 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9981 return;
9982 }
9983 service.sendTestDeviceToDeviceMessage(message, value);
9984 } finally {
9985 Binder.restoreCallingIdentity(identity);
9986 }
9987 }
9988
9989
9990 /**
Hui Wang068ab862020-10-31 05:12:53 +00009991 * Gets the config of RCS VoLTE single registration enabled for the device.
9992 */
9993 @Override
9994 public boolean getDeviceSingleRegistrationEnabled() {
9995 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9996 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9997 }
9998
9999 /**
10000 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10001 */
10002 @Override
10003 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10004 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10005 "setCarrierSingleRegistrationEnabledOverride");
10006 enforceModifyPermission();
10007
10008 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10009 : Boolean.parseBoolean(enabledStr);
10010 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10011 subId, enabled);
10012 }
10013
10014 /**
10015 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10016 */
10017 @Override
10018 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10019 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10020 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10021 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010022
10023 /**
Hui Wangeadb2562021-02-26 09:33:38 -080010024 * Overrides the ims feature validation result
10025 */
10026 @Override
10027 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10028 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10029 "setImsFeatureValidationOverride");
10030
10031 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10032 : Boolean.parseBoolean(enabledStr);
10033 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10034 subId, enabled);
10035 }
10036
10037 /**
10038 * Gets the ims feature validation override value
10039 */
10040 @Override
10041 public boolean getImsFeatureValidationOverride(int subId) {
10042 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10043 "getImsFeatureValidationOverride");
10044 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10045 }
10046
10047 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010048 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10049 * their mobile plan.
10050 */
10051 @Override
10052 public String getMobileProvisioningUrl() {
10053 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10054 final long identity = Binder.clearCallingIdentity();
10055 try {
10056 return getDefaultPhone().getMobileProvisioningUrl();
10057 } finally {
10058 Binder.restoreCallingIdentity(identity);
10059 }
10060 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010061
James.cf Linbcdf8b32021-01-14 16:44:13 +080010062 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010063 * Get the EAB contact from the EAB database.
10064 */
10065 @Override
10066 public String getContactFromEab(String contact) {
10067 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10068 enforceModifyPermission();
10069 final long identity = Binder.clearCallingIdentity();
10070 try {
10071 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10072 } finally {
10073 Binder.restoreCallingIdentity(identity);
10074 }
10075 }
10076
10077 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010078 * Remove the EAB contacts from the EAB database.
10079 */
10080 @Override
10081 public int removeContactFromEab(int subId, String contacts) {
10082 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10083 enforceModifyPermission();
10084 final long identity = Binder.clearCallingIdentity();
10085 try {
10086 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10087 } finally {
10088 Binder.restoreCallingIdentity(identity);
10089 }
10090 }
10091
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010092 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010093 public boolean getDeviceUceEnabled() {
10094 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10095 final long identity = Binder.clearCallingIdentity();
10096 try {
10097 return mApp.getDeviceUceEnabled();
10098 } finally {
10099 Binder.restoreCallingIdentity(identity);
10100 }
10101 }
10102
10103 @Override
10104 public void setDeviceUceEnabled(boolean isEnabled) {
10105 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10106 final long identity = Binder.clearCallingIdentity();
10107 try {
10108 mApp.setDeviceUceEnabled(isEnabled);
10109 } finally {
10110 Binder.restoreCallingIdentity(identity);
10111 }
10112 }
10113
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010114 /**
10115 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10116 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10117 */
10118 // Used for SHELL command only right now.
10119 @Override
10120 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10121 List<String> featureTags) {
10122 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10123 "addUceRegistrationOverrideShell");
10124 final long identity = Binder.clearCallingIdentity();
10125 try {
10126 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10127 new ArraySet<>(featureTags));
10128 } catch (ImsException e) {
10129 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10130 } finally {
10131 Binder.restoreCallingIdentity(identity);
10132 }
10133 }
10134
10135 /**
10136 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10137 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10138 */
10139 // Used for SHELL command only right now.
10140 @Override
10141 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10142 List<String> featureTags) {
10143 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10144 "removeUceRegistrationOverrideShell");
10145 final long identity = Binder.clearCallingIdentity();
10146 try {
10147 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10148 new ArraySet<>(featureTags));
10149 } catch (ImsException e) {
10150 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10151 } finally {
10152 Binder.restoreCallingIdentity(identity);
10153 }
10154 }
10155
10156 /**
10157 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10158 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10159 */
10160 // Used for SHELL command only right now.
10161 @Override
10162 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10163 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10164 "clearUceRegistrationOverrideShell");
10165 final long identity = Binder.clearCallingIdentity();
10166 try {
10167 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10168 } catch (ImsException e) {
10169 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10170 } finally {
10171 Binder.restoreCallingIdentity(identity);
10172 }
10173 }
10174
10175 /**
10176 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10177 */
10178 // Used for SHELL command only right now.
10179 @Override
10180 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10181 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10182 "getLatestRcsContactUceCapabilityShell");
10183 final long identity = Binder.clearCallingIdentity();
10184 try {
10185 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10186 } catch (ImsException e) {
10187 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10188 } finally {
10189 Binder.restoreCallingIdentity(identity);
10190 }
10191 }
10192
10193 /**
10194 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10195 * device does not have an active PUBLISH.
10196 */
10197 // Used for SHELL command only right now.
10198 @Override
10199 public String getLastUcePidfXmlShell(int subId) {
10200 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10201 final long identity = Binder.clearCallingIdentity();
10202 try {
10203 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10204 } catch (ImsException e) {
10205 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10206 } finally {
10207 Binder.restoreCallingIdentity(identity);
10208 }
10209 }
10210
James.cf Line8713a42021-04-29 16:04:26 +080010211 /**
10212 * Remove UCE requests cannot be sent to the network status.
10213 */
10214 // Used for SHELL command only right now.
10215 @Override
10216 public boolean removeUceRequestDisallowedStatus(int subId) {
10217 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10218 final long identity = Binder.clearCallingIdentity();
10219 try {
10220 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10221 } catch (ImsException e) {
10222 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10223 } finally {
10224 Binder.restoreCallingIdentity(identity);
10225 }
10226 }
10227
James.cf Lin18bb9002021-05-25 01:37:38 +080010228 /**
10229 * Remove UCE requests cannot be sent to the network status.
10230 */
10231 // Used for SHELL command only.
10232 @Override
10233 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10234 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10235 final long identity = Binder.clearCallingIdentity();
10236 try {
10237 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10238 } catch (ImsException e) {
10239 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10240 } finally {
10241 Binder.restoreCallingIdentity(identity);
10242 }
10243 }
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010244
James.cf Lin4b784aa2021-01-31 03:25:15 +080010245 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010246 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10247 String callingPackage) {
10248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10249 mApp, subId, "setSignalStrengthUpdateRequest");
10250
10251 final int callingUid = Binder.getCallingUid();
10252 // Verify that tha callingPackage belongs to the calling UID
10253 mApp.getSystemService(AppOpsManager.class)
10254 .checkPackage(callingUid, callingPackage);
10255
10256 validateSignalStrengthUpdateRequest(request, callingUid);
10257
10258 final long identity = Binder.clearCallingIdentity();
10259 try {
10260 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10261 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10262
10263 if (result instanceof IllegalStateException) {
10264 throw (IllegalStateException) result;
10265 }
10266 } finally {
10267 Binder.restoreCallingIdentity(identity);
10268 }
10269 }
10270
10271 @Override
10272 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10273 String callingPackage) {
10274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10275 mApp, subId, "clearSignalStrengthUpdateRequest");
10276
10277 final int callingUid = Binder.getCallingUid();
10278 // Verify that tha callingPackage belongs to the calling UID
10279 mApp.getSystemService(AppOpsManager.class)
10280 .checkPackage(callingUid, callingPackage);
10281
10282 final long identity = Binder.clearCallingIdentity();
10283 try {
10284 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10285 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10286
10287 if (result instanceof IllegalStateException) {
10288 throw (IllegalStateException) result;
10289 }
10290 } finally {
10291 Binder.restoreCallingIdentity(identity);
10292 }
10293 }
10294
10295 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10296 int callingUid) {
10297 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10298 // phone/system process do not have further restriction on request
10299 return;
10300 }
10301
10302 // Applications has restrictions on how to use the request:
10303 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10304 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10305 // This is not system caller which has been checked above
10306 throw new IllegalArgumentException(
10307 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10308 }
10309
10310 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10311 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10312 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10313 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10314 || info.isEnabled()) {
10315 throw new IllegalArgumentException(
10316 "Only system can set hide fields in SignalThresholdInfo");
10317 }
10318
10319 // Thresholds length for each RAN need in range. This has been validated in
10320 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10321 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10322 final int[] thresholds = info.getThresholds();
10323 Objects.requireNonNull(thresholds);
10324 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10325 || thresholds.length
10326 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10327 throw new IllegalArgumentException(
10328 "thresholds length is out of range: " + thresholds.length);
10329 }
10330 }
10331 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010332
10333 /**
10334 * Prepare TelephonyManager for an unattended reboot. The reboot is
10335 * required to be done shortly after the API is invoked.
10336 */
10337 @Override
10338 @TelephonyManager.PrepareUnattendedRebootResult
10339 public int prepareForUnattendedReboot() {
10340 enforceRebootPermission();
10341
10342 final long identity = Binder.clearCallingIdentity();
10343 try {
10344 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10345 } finally {
10346 Binder.restoreCallingIdentity(identity);
10347 }
10348 }
SongFerngWang2c4309d2021-01-17 21:51:44 +080010349
10350 /**
10351 * Gets the current phone capability.
10352 *
10353 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10354 * @return the PhoneCapability which describes the data connection capability of modem.
10355 * It's used to evaluate possible phone config change, for example from single
10356 * SIM device to multi-SIM device.
10357 */
10358 @Override
10359 public PhoneCapability getPhoneCapability() {
10360 enforceReadPrivilegedPermission("getPhoneCapability");
10361 final long identity = Binder.clearCallingIdentity();
10362 try {
10363 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10364 } finally {
10365 Binder.restoreCallingIdentity(identity);
10366 }
10367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010368}