blob: a25e3551763f43f041c84ed1d8a55d48ae3e5142 [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,
1223 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1224 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001225 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001226 break;
1227
1228 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1229 ar = (AsyncResult) msg.obj;
1230 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001231 ResultReceiver result = (ResultReceiver) request.argument;
1232
1233 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001234 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001235 // Update the last modem activity info and the result of the request.
1236 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1237 if (isModemActivityInfoValid(info)) {
1238 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1239 int[] txTimeMs = info.getTransmitTimeMillis();
1240 int[] lastModemTxTimeMs = mLastModemActivityInfo
1241 .getTransmitTimeMillis();
1242 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1243 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1244 }
1245 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1246 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1247 + mLastModemActivityInfo.getSleepTimeMillis());
1248 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1249 + mLastModemActivityInfo.getIdleTimeMillis());
1250 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1251 mLastModemActivityInfo.setReceiveTimeMillis(
1252 info.getReceiveTimeMillis()
1253 + mLastModemActivityInfo.getReceiveTimeMillis());
1254 }
1255 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1256 mLastModemActivityInfo.getSleepTimeMillis(),
1257 mLastModemActivityInfo.getIdleTimeMillis(),
1258 mLastModemActivityInfo.getTransmitTimeMillis(),
1259 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001260 } else {
1261 if (ar.result == null) {
1262 loge("queryModemActivityInfo: Empty response");
1263 } else if (ar.exception instanceof CommandException) {
1264 loge("queryModemActivityInfo: CommandException: " +
1265 ar.exception);
1266 } else {
1267 loge("queryModemActivityInfo: Unknown exception");
1268 }
1269 }
sqian1a1be542020-03-05 11:37:28 -08001270 Bundle bundle = new Bundle();
1271 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1272 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001273 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001274 break;
1275
Meng Wang1a7c35a2016-05-05 20:56:15 -07001276 case CMD_SET_ALLOWED_CARRIERS:
1277 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001278 CarrierRestrictionRules argument =
1279 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001280 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001281 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001282 break;
1283
1284 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1285 ar = (AsyncResult) msg.obj;
1286 request = (MainThreadRequest) ar.userObj;
1287 if (ar.exception == null && ar.result != null) {
1288 request.result = ar.result;
1289 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001290 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1291 if (ar.exception instanceof CommandException) {
1292 loge("setAllowedCarriers: CommandException: " + ar.exception);
1293 CommandException.Error error =
1294 ((CommandException) (ar.exception)).getCommandError();
1295 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1296 request.result =
1297 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1298 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 } else {
1300 loge("setAllowedCarriers: Unknown exception");
1301 }
1302 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001303 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001304 break;
1305
1306 case CMD_GET_ALLOWED_CARRIERS:
1307 request = (MainThreadRequest) msg.obj;
1308 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001309 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001310 break;
1311
1312 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1313 ar = (AsyncResult) msg.obj;
1314 request = (MainThreadRequest) ar.userObj;
1315 if (ar.exception == null && ar.result != null) {
1316 request.result = ar.result;
1317 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001318 request.result = new IllegalStateException(
1319 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001320 if (ar.result == null) {
1321 loge("getAllowedCarriers: Empty response");
1322 } else if (ar.exception instanceof CommandException) {
1323 loge("getAllowedCarriers: CommandException: " +
1324 ar.exception);
1325 } else {
1326 loge("getAllowedCarriers: Unknown exception");
1327 }
1328 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001329 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001330 break;
1331
Nathan Haroldb3014052017-01-25 15:57:32 -08001332 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1333 ar = (AsyncResult) msg.obj;
1334 request = (MainThreadRequest) ar.userObj;
1335 if (ar.exception == null && ar.result != null) {
1336 request.result = ar.result;
1337 } else {
1338 request.result = new IllegalArgumentException(
1339 "Failed to retrieve Forbidden Plmns");
1340 if (ar.result == null) {
1341 loge("getForbiddenPlmns: Empty response");
1342 } else {
1343 loge("getForbiddenPlmns: Unknown exception");
1344 }
1345 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001346 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001347 break;
1348
1349 case CMD_GET_FORBIDDEN_PLMNS:
1350 request = (MainThreadRequest) msg.obj;
1351 uiccCard = getUiccCardFromRequest(request);
1352 if (uiccCard == null) {
1353 loge("getForbiddenPlmns() UiccCard is null");
1354 request.result = new IllegalArgumentException(
1355 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001356 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001357 break;
1358 }
1359 Integer appType = (Integer) request.argument;
1360 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1361 if (uiccApp == null) {
1362 loge("getForbiddenPlmns() no app with specified type -- "
1363 + appType);
1364 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001365 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001366 break;
1367 } else {
1368 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1369 + " specified type -- " + appType);
1370 }
1371 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1372 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1373 onCompleted);
1374 break;
1375
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001376 case CMD_SWITCH_SLOTS:
1377 request = (MainThreadRequest) msg.obj;
1378 int[] physicalSlots = (int[]) request.argument;
1379 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1380 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1381 break;
1382
1383 case EVENT_SWITCH_SLOTS_DONE:
1384 ar = (AsyncResult) msg.obj;
1385 request = (MainThreadRequest) ar.userObj;
1386 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001387 notifyRequester(request);
1388 break;
1389 case CMD_GET_NETWORK_SELECTION_MODE:
1390 request = (MainThreadRequest) msg.obj;
1391 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1392 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1393 break;
1394
1395 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1396 ar = (AsyncResult) msg.obj;
1397 request = (MainThreadRequest) ar.userObj;
1398 if (ar.exception != null) {
1399 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1400 } else {
1401 int mode = ((int[]) ar.result)[0];
1402 if (mode == 0) {
1403 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1404 } else {
1405 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1406 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001407 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001408 notifyRequester(request);
1409 break;
1410 case CMD_GET_CDMA_ROAMING_MODE:
1411 request = (MainThreadRequest) msg.obj;
1412 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1413 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1414 break;
1415 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1416 ar = (AsyncResult) msg.obj;
1417 request = (MainThreadRequest) ar.userObj;
1418 if (ar.exception != null) {
1419 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1420 } else {
1421 request.result = ((int[]) ar.result)[0];
1422 }
1423 notifyRequester(request);
1424 break;
1425 case CMD_SET_CDMA_ROAMING_MODE:
1426 request = (MainThreadRequest) msg.obj;
1427 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1428 int mode = (int) request.argument;
1429 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1430 break;
1431 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1432 ar = (AsyncResult) msg.obj;
1433 request = (MainThreadRequest) ar.userObj;
1434 request.result = ar.exception == null;
1435 notifyRequester(request);
1436 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001437 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1438 request = (MainThreadRequest) msg.obj;
1439 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1440 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1441 break;
1442 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1443 ar = (AsyncResult) msg.obj;
1444 request = (MainThreadRequest) ar.userObj;
1445 if (ar.exception != null) {
1446 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1447 } else {
1448 request.result = ((int[]) ar.result)[0];
1449 }
1450 notifyRequester(request);
1451 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001452 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1453 request = (MainThreadRequest) msg.obj;
1454 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1455 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001456 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1457 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001458 break;
1459 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 request.result = ar.exception == null;
1463 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001464 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001465 case CMD_GET_ALL_CELL_INFO:
1466 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001467 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001468 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001469 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001470 case EVENT_GET_ALL_CELL_INFO_DONE:
1471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001473 // If a timeout occurs, the response will be null
1474 request.result = (ar.exception == null && ar.result != null)
1475 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001476 synchronized (request) {
1477 request.notifyAll();
1478 }
1479 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001480 case CMD_REQUEST_CELL_INFO_UPDATE:
1481 request = (MainThreadRequest) msg.obj;
1482 request.phone.requestCellInfoUpdate(request.workSource,
1483 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1484 break;
1485 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1486 ar = (AsyncResult) msg.obj;
1487 request = (MainThreadRequest) ar.userObj;
1488 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1489 try {
1490 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001491 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001492 cb.onError(
1493 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1494 ar.exception.getClass().getName(),
1495 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001496 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001497 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001498 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001499 } else {
1500 // use the result as returned
1501 cb.onCellInfo((List<CellInfo>) ar.result);
1502 }
1503 } catch (RemoteException re) {
1504 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1505 }
1506 break;
Sarah Chincc055732020-11-18 13:39:35 -08001507 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001508 request = (MainThreadRequest) msg.obj;
1509 WorkSource ws = (WorkSource) request.argument;
1510 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001511 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001512 break;
Sarah Chincc055732020-11-18 13:39:35 -08001513 }
1514 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001515 ar = (AsyncResult) msg.obj;
1516 request = (MainThreadRequest) ar.userObj;
1517 if (ar.exception == null) {
1518 request.result = ar.result;
1519 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001520 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001521 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001522 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001523 }
1524
1525 synchronized (request) {
1526 request.notifyAll();
1527 }
1528 break;
Sarah Chincc055732020-11-18 13:39:35 -08001529 }
chen xu6dac5ab2018-10-26 17:39:23 -07001530 case CMD_MODEM_REBOOT:
1531 request = (MainThreadRequest) msg.obj;
1532 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001533 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001534 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001535 case EVENT_CMD_MODEM_REBOOT_DONE:
1536 handleNullReturnEvent(msg, "rebootModem");
1537 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001538 case CMD_REQUEST_ENABLE_MODEM:
1539 request = (MainThreadRequest) msg.obj;
1540 boolean enable = (boolean) request.argument;
1541 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001542 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001543 PhoneConfigurationManager.getInstance()
1544 .enablePhone(request.phone, enable, onCompleted);
1545 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001546 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001547 ar = (AsyncResult) msg.obj;
1548 request = (MainThreadRequest) ar.userObj;
1549 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001550 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001551 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001552 if ((boolean) request.result) {
1553 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1554 updateModemStateMetrics();
1555 } else {
1556 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1557 + ar.exception);
1558 }
1559 notifyRequester(request);
1560 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001561 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001562 case CMD_GET_MODEM_STATUS:
1563 request = (MainThreadRequest) msg.obj;
1564 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1565 PhoneConfigurationManager.getInstance()
1566 .getPhoneStatusFromModem(request.phone, onCompleted);
1567 break;
1568 case EVENT_GET_MODEM_STATUS_DONE:
1569 ar = (AsyncResult) msg.obj;
1570 request = (MainThreadRequest) ar.userObj;
1571 int id = request.phone.getPhoneId();
1572 if (ar.exception == null && ar.result != null) {
1573 request.result = ar.result;
1574 //update the cache as modem status has changed
1575 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1576 (boolean) request.result);
1577 } else {
1578 // Return true if modem status cannot be retrieved. For most cases,
1579 // modem status is on. And for older version modems, GET_MODEM_STATUS
1580 // and disable modem are not supported. Modem is always on.
1581 // TODO: this should be fixed in R to support a third
1582 // status UNKNOWN b/131631629
1583 request.result = true;
1584 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1585 + ar.exception);
1586 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001587 notifyRequester(request);
1588 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001589 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1590 request = (MainThreadRequest) msg.obj;
1591 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1592 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1593 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1594 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1595 break;
1596 }
1597 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1598 ar = (AsyncResult) msg.obj;
1599 request = (MainThreadRequest) ar.userObj;
1600 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1601 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1602 args.second.accept(ar.exception == null);
1603 notifyRequester(request);
1604 break;
1605 }
Sarah Chincc055732020-11-18 13:39:35 -08001606 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1607 request = (MainThreadRequest) msg.obj;
1608 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1609 Phone phone = getPhoneFromRequest(request);
1610 if (phone != null) {
1611 phone.getSystemSelectionChannels(onCompleted);
1612 } else {
1613 loge("getSystemSelectionChannels: No phone object");
1614 request.result = new ArrayList<RadioAccessSpecifier>();
1615 notifyRequester(request);
1616 }
1617 break;
1618 }
1619 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 if (ar.exception == null && ar.result != null) {
1623 request.result = ar.result;
1624 } else {
Sarah Chin58691872021-03-13 03:17:40 -08001625 request.result = new IllegalStateException(
1626 "Failed to retrieve system selecton channels");
Sarah Chincc055732020-11-18 13:39:35 -08001627 if (ar.result == null) {
1628 loge("getSystemSelectionChannels: Empty response");
1629 } else {
1630 loge("getSystemSelectionChannels: Unknown exception");
1631 }
1632 }
1633 notifyRequester(request);
1634 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001635 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1636 ar = (AsyncResult) msg.obj;
1637 request = (MainThreadRequest) ar.userObj;
1638 if (ar.exception == null && ar.result != null) {
1639 request.result = ar.result;
1640 } else {
1641 request.result = -1;
1642 loge("Failed to set Forbidden Plmns");
1643 if (ar.result == null) {
1644 loge("setForbidenPlmns: Empty response");
1645 } else if (ar.exception != null) {
1646 loge("setForbiddenPlmns: Exception: " + ar.exception);
1647 request.result = -1;
1648 } else {
1649 loge("setForbiddenPlmns: Unknown exception");
1650 }
1651 }
1652 notifyRequester(request);
1653 break;
1654 case CMD_SET_FORBIDDEN_PLMNS:
1655 request = (MainThreadRequest) msg.obj;
1656 uiccCard = getUiccCardFromRequest(request);
1657 if (uiccCard == null) {
1658 loge("setForbiddenPlmns: UiccCard is null");
1659 request.result = -1;
1660 notifyRequester(request);
1661 break;
1662 }
1663 Pair<Integer, List<String>> setFplmnsArgs =
1664 (Pair<Integer, List<String>>) request.argument;
1665 appType = setFplmnsArgs.first;
1666 List<String> fplmns = setFplmnsArgs.second;
1667 uiccApp = uiccCard.getApplicationByType(appType);
1668 if (uiccApp == null) {
1669 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1670 request.result = -1;
1671 loge("Failed to get UICC App");
1672 notifyRequester(request);
1673 } else {
1674 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1675 ((SIMRecords) uiccApp.getIccRecords())
1676 .setForbiddenPlmns(onCompleted, fplmns);
1677 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001678 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001679 case CMD_ERASE_MODEM_CONFIG:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1682 defaultPhone.eraseModemConfig(onCompleted);
1683 break;
1684 case EVENT_ERASE_MODEM_CONFIG_DONE:
1685 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001686 break;
zoey chenf95ca592019-12-30 16:11:23 +08001687
1688 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1689 request = (MainThreadRequest) msg.obj;
1690 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1691 Pair<String, String> changed = (Pair<String, String>) request.argument;
1692 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1693 changed.first, changed.second, onCompleted);
1694 break;
1695 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1696 ar = (AsyncResult) msg.obj;
1697 request = (MainThreadRequest) ar.userObj;
1698 if (ar.exception == null) {
1699 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001700 // If the operation is successful, update the PIN storage
1701 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1702 int phoneId = getPhoneFromRequest(request).getPhoneId();
1703 UiccController.getInstance().getPinStorage()
1704 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001705 } else {
1706 request.result = msg.arg1;
1707 }
1708 notifyRequester(request);
1709 break;
1710
Michele Berionned9fbae52020-11-13 02:36:59 +00001711 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001712 request = (MainThreadRequest) msg.obj;
1713 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1714 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1715 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1716 enabled.first, enabled.second, onCompleted);
1717 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001718 }
zoey chenf95ca592019-12-30 16:11:23 +08001719 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1720 ar = (AsyncResult) msg.obj;
1721 request = (MainThreadRequest) ar.userObj;
1722 if (ar.exception == null) {
1723 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001724 // If the operation is successful, update the PIN storage
1725 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1726 int phoneId = getPhoneFromRequest(request).getPhoneId();
1727 if (enabled.first) {
1728 UiccController.getInstance().getPinStorage()
1729 .storePin(enabled.second, phoneId);
1730 } else {
1731 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1732 }
zoey chenf95ca592019-12-30 16:11:23 +08001733 } else {
1734 request.result = msg.arg1;
1735 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001736
1737
zoey chenf95ca592019-12-30 16:11:23 +08001738 notifyRequester(request);
1739 break;
1740
Peter Wangdafb9ac2020-01-15 14:13:38 -08001741 case MSG_NOTIFY_USER_ACTIVITY:
1742 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001743 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001744 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1745 getDefaultPhone().getContext().sendBroadcastAsUser(
1746 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1747 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001748
1749 case CMD_SET_DATA_THROTTLING: {
1750 request = (MainThreadRequest) msg.obj;
1751 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1752 DataThrottlingRequest dataThrottlingRequest =
1753 (DataThrottlingRequest) request.argument;
1754 Phone phone = getPhoneFromRequest(request);
1755 if (phone != null) {
1756 phone.setDataThrottling(onCompleted,
1757 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1758 dataThrottlingRequest.getCompletionDurationMillis());
1759 } else {
1760 loge("setDataThrottling: No phone object");
1761 request.result =
1762 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1763 notifyRequester(request);
1764 }
1765
1766 break;
1767 }
1768 case EVENT_SET_DATA_THROTTLING_DONE:
1769 ar = (AsyncResult) msg.obj;
1770 request = (MainThreadRequest) ar.userObj;
1771
1772 if (ar.exception == null) {
1773 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1774 } else if (ar.exception instanceof CommandException) {
1775 loge("setDataThrottling: CommandException: " + ar.exception);
1776 CommandException.Error error =
1777 ((CommandException) (ar.exception)).getCommandError();
1778
1779 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1780 request.result = TelephonyManager
1781 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1782 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1783 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001784 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1785 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001786 } else {
1787 request.result =
1788 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1789 }
1790 } else {
1791 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1792 }
1793 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1794 notifyRequester(request);
1795 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001796
1797 case CMD_SET_SIM_POWER: {
1798 request = (MainThreadRequest) msg.obj;
1799 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1800 request = (MainThreadRequest) msg.obj;
1801 int stateToSet =
1802 ((Pair<Integer, IIntegerConsumer>)
1803 request.argument).first;
1804 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1805 break;
1806 }
1807 case EVENT_SET_SIM_POWER_DONE: {
1808 ar = (AsyncResult) msg.obj;
1809 request = (MainThreadRequest) ar.userObj;
1810 IIntegerConsumer callback =
1811 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1812 if (ar.exception != null) {
1813 loge("setSimPower exception: " + ar.exception);
1814 int errorCode = TelephonyManager.CallForwardingInfoCallback
1815 .RESULT_ERROR_UNKNOWN;
1816 if (ar.exception instanceof CommandException) {
1817 CommandException.Error error =
1818 ((CommandException) (ar.exception)).getCommandError();
1819 if (error == CommandException.Error.SIM_ERR) {
1820 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1821 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1822 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1823 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1824 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1825 } else {
1826 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1827 }
1828 }
1829 try {
1830 callback.accept(errorCode);
1831 } catch (RemoteException e) {
1832 // Ignore if the remote process is no longer available to call back.
1833 Log.w(LOG_TAG, "setSimPower: callback not available.");
1834 }
1835 } else {
1836 try {
1837 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1838 } catch (RemoteException e) {
1839 // Ignore if the remote process is no longer available to call back.
1840 Log.w(LOG_TAG, "setSimPower: callback not available.");
1841 }
1842 }
1843 break;
1844 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001845 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1846 request = (MainThreadRequest) msg.obj;
1847
1848 final Phone phone = getPhoneFromRequest(request);
1849 if (phone == null || phone.getServiceStateTracker() == null) {
1850 request.result = new IllegalStateException("Phone or SST is null");
1851 notifyRequester(request);
1852 break;
1853 }
1854
1855 Pair<Integer, SignalStrengthUpdateRequest> pair =
1856 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1857 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1858 request);
1859 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1860 request.subId, pair.first /*callingUid*/,
1861 pair.second /*request*/, onCompleted);
1862 break;
1863 }
1864 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1865 ar = (AsyncResult) msg.obj;
1866 request = (MainThreadRequest) ar.userObj;
1867 // request.result will be the exception of ar if present, true otherwise.
1868 // Be cautious not to leave result null which will wait() forever
1869 request.result = ar.exception != null ? ar.exception : true;
1870 notifyRequester(request);
1871 break;
1872 }
1873 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1874 request = (MainThreadRequest) msg.obj;
1875
1876 Phone phone = getPhoneFromRequest(request);
1877 if (phone == null || phone.getServiceStateTracker() == null) {
1878 request.result = new IllegalStateException("Phone or SST is null");
1879 notifyRequester(request);
1880 break;
1881 }
1882
1883 Pair<Integer, SignalStrengthUpdateRequest> pair =
1884 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1885 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1886 request);
1887 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1888 request.subId, pair.first /*callingUid*/,
1889 pair.second /*request*/, onCompleted);
1890 break;
1891 }
1892 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1893 ar = (AsyncResult) msg.obj;
1894 request = (MainThreadRequest) ar.userObj;
1895 request.result = ar.exception != null ? ar.exception : true;
1896 notifyRequester(request);
1897 break;
1898 }
Jordan Liud5366d92020-11-24 14:50:34 -08001899
Michele Berionned9fbae52020-11-13 02:36:59 +00001900 case CMD_PREPARE_UNATTENDED_REBOOT:
1901 request = (MainThreadRequest) msg.obj;
1902 request.result =
Rafael Higuera Silvacd3aef22021-08-30 15:16:50 +00001903 UiccController.getInstance().getPinStorage()
1904 .prepareUnattendedReboot(request.workSource);
Michele Berionned9fbae52020-11-13 02:36:59 +00001905 notifyRequester(request);
1906 break;
1907
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 default:
1909 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1910 break;
1911 }
1912 }
Jake Hambye994d462014-02-03 13:10:13 -08001913
Pengquan Menga1bb6272018-09-06 09:59:22 -07001914 private void notifyRequester(MainThreadRequest request) {
1915 synchronized (request) {
1916 request.notifyAll();
1917 }
1918 }
1919
Jake Hambye994d462014-02-03 13:10:13 -08001920 private void handleNullReturnEvent(Message msg, String command) {
1921 AsyncResult ar = (AsyncResult) msg.obj;
1922 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1923 if (ar.exception == null) {
1924 request.result = true;
1925 } else {
1926 request.result = false;
1927 if (ar.exception instanceof CommandException) {
1928 loge(command + ": CommandException: " + ar.exception);
1929 } else {
1930 loge(command + ": Unknown exception");
1931 }
1932 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001933 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001934 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935 }
1936
1937 /**
1938 * Posts the specified command to be executed on the main thread,
1939 * waits for the request to complete, and returns the result.
1940 * @see #sendRequestAsync
1941 */
1942 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001943 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1944 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001945 }
1946
1947 /**
1948 * Posts the specified command to be executed on the main thread,
1949 * waits for the request to complete, and returns the result.
1950 * @see #sendRequestAsync
1951 */
1952 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1953 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001954 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001955 }
1956
1957 /**
1958 * Posts the specified command to be executed on the main thread,
1959 * waits for the request to complete, and returns the result.
1960 * @see #sendRequestAsync
1961 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001962 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001963 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1964 }
1965
1966 /**
1967 * Posts the specified command to be executed on the main thread,
1968 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1969 * if not timeout or null otherwise.
1970 * @see #sendRequestAsync
1971 */
1972 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1973 long timeoutInMs) {
1974 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001975 }
1976
1977 /**
1978 * Posts the specified command to be executed on the main thread,
1979 * waits for the request to complete, and returns the result.
1980 * @see #sendRequestAsync
1981 */
Nathan Harold92bed182018-10-12 18:16:49 -07001982 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001983 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001984 }
1985
1986 /**
1987 * Posts the specified command to be executed on the main thread,
1988 * waits for the request to complete, and returns the result.
1989 * @see #sendRequestAsync
1990 */
1991 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001992 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1993 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001994 }
1995
1996 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001997 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1998 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1999 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002000 * @see #sendRequestAsync
2001 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002002 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2003 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2005 throw new RuntimeException("This method will deadlock if called from the main thread.");
2006 }
2007
Nathan Harold92bed182018-10-12 18:16:49 -07002008 MainThreadRequest request = null;
2009 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2010 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2011 } else if (phone != null) {
2012 request = new MainThreadRequest(argument, phone, workSource);
2013 } else {
2014 request = new MainThreadRequest(argument, subId, workSource);
2015 }
2016
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 Message msg = mMainThreadHandler.obtainMessage(command, request);
2018 msg.sendToTarget();
2019
Rambo Wang0f050d82021-02-12 11:43:36 -08002020
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002022 if (timeoutInMs >= 0) {
2023 // Wait for at least timeoutInMs before returning null request result
2024 long now = SystemClock.elapsedRealtime();
2025 long deadline = now + timeoutInMs;
2026 while (request == null && now < deadline) {
2027 try {
2028 request.wait(deadline - now);
2029 } catch (InterruptedException e) {
2030 // Do nothing, go back and check if request is completed or timeout
2031 } finally {
2032 now = SystemClock.elapsedRealtime();
2033 }
2034 }
2035 } else {
2036 // Wait for the request to complete
2037 while (request.result == null) {
2038 try {
2039 request.wait();
2040 } catch (InterruptedException e) {
2041 // Do nothing, go back and wait until the request is complete
2042 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043 }
2044 }
2045 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002046 if (request.result == null) {
2047 Log.wtf(LOG_TAG,
2048 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2049 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002050 return request.result;
2051 }
2052
2053 /**
2054 * Asynchronous ("fire and forget") version of sendRequest():
2055 * Posts the specified command to be executed on the main thread, and
2056 * returns immediately.
2057 * @see #sendRequest
2058 */
2059 private void sendRequestAsync(int command) {
2060 mMainThreadHandler.sendEmptyMessage(command);
2061 }
2062
2063 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002064 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002065 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002066 */
2067 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002068 sendRequestAsync(command, argument, null, null);
2069 }
2070
2071 /**
2072 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2073 * @see {@link #sendRequest(int,Object)}
2074 */
2075 private void sendRequestAsync(
2076 int command, Object argument, Phone phone, WorkSource workSource) {
2077 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002078 Message msg = mMainThreadHandler.obtainMessage(command, request);
2079 msg.sendToTarget();
2080 }
2081
2082 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 * Initialize the singleton PhoneInterfaceManager instance.
2084 * This is only done once, at startup, from PhoneApp.onCreate().
2085 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002086 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 synchronized (PhoneInterfaceManager.class) {
2088 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002089 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 } else {
2091 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2092 }
2093 return sInstance;
2094 }
2095 }
2096
2097 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002098 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerc9c432e2021-05-17 20:54:49 +00002101 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002102 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2104 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002105 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002106 mTelephonySharedPreferences =
2107 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002108 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002109 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002110 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002111 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002112
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 publish();
2114 }
2115
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002116 private Phone getDefaultPhone() {
2117 Phone thePhone = getPhone(getDefaultSubscription());
2118 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2119 }
2120
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 private void publish() {
2122 if (DBG) log("publish: " + this);
2123
Peter Wangc035ce42020-01-08 21:00:22 -08002124 TelephonyFrameworkInitializer
2125 .getTelephonyServiceManager()
2126 .getTelephonyServiceRegisterer()
2127 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
2129
Stuart Scott584921c2015-01-15 17:10:34 -08002130 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002131 if (request.phone != null) {
2132 return request.phone;
2133 } else {
2134 return getPhoneFromSubId(request.subId);
2135 }
2136 }
2137
2138 private Phone getPhoneFromSubId(int subId) {
2139 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2140 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002141 }
2142
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002143 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2144 Phone phone = getPhoneFromRequest(request);
2145 return phone == null ? null :
2146 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2147 }
2148
Wink Saville36469e72014-06-11 15:17:00 -07002149 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002150 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002151 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002152 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002154 private void sendEraseModemConfig(Phone phone) {
2155 if (phone != null) {
2156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2157 mApp, phone.getSubId(), "eraseModemConfig");
2158 final long identity = Binder.clearCallingIdentity();
2159 try {
2160 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2161 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2162 } finally {
2163 Binder.restoreCallingIdentity(identity);
2164 }
2165 }
2166 }
2167
Peter Wang050bb052020-01-13 23:33:09 -08002168 private boolean isImsAvailableOnDevice() {
2169 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2170 if (pm == null) {
2171 // For some reason package manger is not available.. This will fail internally anyway,
2172 // so do not throw error and allow.
2173 return true;
2174 }
2175 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2176 }
2177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002179 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002180 }
2181
Wink Savilleb564aae2014-10-23 10:18:09 -07002182 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 if (DBG) log("dial: " + number);
2184 // No permission check needed here: This is just a wrapper around the
2185 // ACTION_DIAL intent, which is available to any app since it puts up
2186 // the UI before it does anything.
2187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002188 final long identity = Binder.clearCallingIdentity();
2189 try {
2190 String url = createTelUrl(number);
2191 if (url == null) {
2192 return;
2193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002195 // PENDING: should we just silently fail if phone is offhook or ringing?
2196 PhoneConstants.State state = mCM.getState(subId);
2197 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2198 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2199 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2200 mApp.startActivity(intent);
2201 }
2202 } finally {
2203 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 }
2205 }
2206
2207 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002208 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002209 }
2210
Wink Savilleb564aae2014-10-23 10:18:09 -07002211 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212 if (DBG) log("call: " + number);
2213
2214 // This is just a wrapper around the ACTION_CALL intent, but we still
2215 // need to do a permission check since we're calling startActivity()
2216 // from the context of the phone app.
2217 enforceCallPermission();
2218
Jordan Liu1617b712019-07-10 15:06:26 -07002219 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 != AppOpsManager.MODE_ALLOWED) {
2221 return;
2222 }
2223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 String url = createTelUrl(number);
2227 if (url == null) {
2228 return;
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231 boolean isValid = false;
2232 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2233 if (slist != null) {
2234 for (SubscriptionInfo subInfoRecord : slist) {
2235 if (subInfoRecord.getSubscriptionId() == subId) {
2236 isValid = true;
2237 break;
2238 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002239 }
Wink Saville08874612014-08-31 19:19:58 -07002240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241 if (!isValid) {
2242 return;
2243 }
Wink Saville08874612014-08-31 19:19:58 -07002244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2246 intent.putExtra(SUBSCRIPTION_KEY, subId);
2247 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2248 mApp.startActivity(intent);
2249 } finally {
2250 Binder.restoreCallingIdentity(identity);
2251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 }
2253
Wink Savilleb564aae2014-10-23 10:18:09 -07002254 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002255 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002256 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2257 }
2258
Wink Savilleb564aae2014-10-23 10:18:09 -07002259 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002260 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002261 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2262 }
2263
Wink Savilleb564aae2014-10-23 10:18:09 -07002264 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002266
2267 final long identity = Binder.clearCallingIdentity();
2268 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002269 Phone phone = getPhone(subId);
2270 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271 checkSimPin.start();
2272 return checkSimPin.unlockSim(null, pin);
2273 } finally {
2274 Binder.restoreCallingIdentity(identity);
2275 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 }
2277
Wink Savilleb564aae2014-10-23 10:18:09 -07002278 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002280
2281 final long identity = Binder.clearCallingIdentity();
2282 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002283 Phone phone = getPhone(subId);
2284 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285 checkSimPuk.start();
2286 return checkSimPuk.unlockSim(puk, pin);
2287 } finally {
2288 Binder.restoreCallingIdentity(identity);
2289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 }
2291
2292 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002293 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 * a synchronous one.
2295 */
2296 private static class UnlockSim extends Thread {
2297
2298 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002299 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300
2301 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002302 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2303 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002304
2305 // For replies from SimCard interface
2306 private Handler mHandler;
2307
2308 // For async handler to identify request type
2309 private static final int SUPPLY_PIN_COMPLETE = 100;
2310
Michele Berionned9fbae52020-11-13 02:36:59 +00002311 UnlockSim(int phoneId, IccCard simCard) {
2312 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 mSimCard = simCard;
2314 }
2315
2316 @Override
2317 public void run() {
2318 Looper.prepare();
2319 synchronized (UnlockSim.this) {
2320 mHandler = new Handler() {
2321 @Override
2322 public void handleMessage(Message msg) {
2323 AsyncResult ar = (AsyncResult) msg.obj;
2324 switch (msg.what) {
2325 case SUPPLY_PIN_COMPLETE:
2326 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2327 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002328 mRetryCount = msg.arg1;
2329 if (ar.exception != null) {
2330 if (ar.exception instanceof CommandException &&
2331 ((CommandException)(ar.exception)).getCommandError()
2332 == CommandException.Error.PASSWORD_INCORRECT) {
2333 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002334 } //When UiccCardApp dispose,handle message and return exception
2335 else if (ar.exception instanceof CommandException &&
2336 ((CommandException) (ar.exception)).getCommandError()
2337 == CommandException.Error.ABORTED) {
2338 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002339 } else {
2340 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2341 }
2342 } else {
2343 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 mDone = true;
2346 UnlockSim.this.notifyAll();
2347 }
2348 break;
2349 }
2350 }
2351 };
2352 UnlockSim.this.notifyAll();
2353 }
2354 Looper.loop();
2355 }
2356
2357 /*
2358 * Use PIN or PUK to unlock SIM card
2359 *
2360 * If PUK is null, unlock SIM card with PIN
2361 *
2362 * If PUK is not null, unlock SIM card with PUK and set PIN code
2363 */
Wink Saville9de0f752013-10-22 19:04:03 -07002364 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365
2366 while (mHandler == null) {
2367 try {
2368 wait();
2369 } catch (InterruptedException e) {
2370 Thread.currentThread().interrupt();
2371 }
2372 }
2373 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2374
2375 if (puk == null) {
2376 mSimCard.supplyPin(pin, callback);
2377 } else {
2378 mSimCard.supplyPuk(puk, pin, callback);
2379 }
2380
2381 while (!mDone) {
2382 try {
2383 Log.d(LOG_TAG, "wait for done");
2384 wait();
2385 } catch (InterruptedException e) {
2386 // Restore the interrupted status
2387 Thread.currentThread().interrupt();
2388 }
2389 }
2390 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002391 int[] resultArray = new int[2];
2392 resultArray[0] = mResult;
2393 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002394
2395 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2396 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2397 }
2398
Wink Saville9de0f752013-10-22 19:04:03 -07002399 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 }
2401 }
2402
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002403 /**
2404 * This method has been removed due to privacy and stability concerns.
2405 */
2406 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002408 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2409 return;
Wink Saville36469e72014-06-11 15:17:00 -07002410 }
2411
Nathan Harold1f889d82020-06-04 17:05:26 -07002412 @Override
2413 public void updateServiceLocationWithPackageName(String callingPackage) {
2414 mApp.getSystemService(AppOpsManager.class)
2415 .checkPackage(Binder.getCallingUid(), callingPackage);
2416
Nathan Haroldf096d982020-11-18 17:18:06 -08002417 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002418 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2419 // Callers targeting S have no business invoking this method.
2420 return;
2421 }
2422
2423 LocationAccessPolicy.LocationPermissionResult locationResult =
2424 LocationAccessPolicy.checkLocationPermission(mApp,
2425 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2426 .setCallingPackage(callingPackage)
2427 .setCallingFeatureId(null)
2428 .setCallingPid(Binder.getCallingPid())
2429 .setCallingUid(Binder.getCallingUid())
2430 .setMethod("updateServiceLocation")
2431 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2432 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2433 .build());
2434 // Apps that lack location permission have no business calling this method;
2435 // however, because no permission was declared in the public API, denials must
2436 // all be "soft".
2437 switch (locationResult) {
2438 case DENIED_HARD: /* fall through */
2439 case DENIED_SOFT:
2440 return;
2441 }
2442
2443 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002444 final long identity = Binder.clearCallingIdentity();
2445 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002446 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002448 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002449 }
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 }
2454
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002455 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002456 @Override
2457 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002458 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002459 }
2460
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002461
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002462 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002463 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2464 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2465 callingFeatureId);
2466 }
2467
2468 @Deprecated
2469 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002470 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002471 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2472 }
2473
2474 @Override
2475 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2476 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002478 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002479 return false;
2480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002481
2482 final long identity = Binder.clearCallingIdentity();
2483 try {
2484 return isRadioOnForSubscriber(subId);
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
2487 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002488 }
2489
2490 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 final Phone phone = getPhone(subId);
2494 if (phone != null) {
2495 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2496 } else {
2497 return false;
2498 }
2499 } finally {
2500 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 }
2503
2504 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002505 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 }
Wink Saville36469e72014-06-11 15:17:00 -07002507
Wink Savilleb564aae2014-10-23 10:18:09 -07002508 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510
2511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 final Phone phone = getPhone(subId);
2514 if (phone != null) {
2515 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2516 }
2517 } finally {
2518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002519 }
Wink Saville36469e72014-06-11 15:17:00 -07002520 }
2521
2522 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002523 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002524 }
2525
Wink Savilleb564aae2014-10-23 10:18:09 -07002526 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002528
2529 final long identity = Binder.clearCallingIdentity();
2530 try {
2531 final Phone phone = getPhone(subId);
2532 if (phone == null) {
2533 return false;
2534 }
2535 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2536 toggleRadioOnOffForSubscriber(subId);
2537 }
2538 return true;
2539 } finally {
2540 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 }
Wink Saville36469e72014-06-11 15:17:00 -07002543
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002544 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002545 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002546 /*
2547 * If any of the Radios are available, it will need to be
2548 * shutdown. So return true if any Radio is available.
2549 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002550 final long identity = Binder.clearCallingIdentity();
2551 try {
2552 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2553 Phone phone = PhoneFactory.getPhone(i);
2554 if (phone != null && phone.isRadioAvailable()) return true;
2555 }
2556 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2557 return false;
2558 } finally {
2559 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002560 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002561 }
2562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002564 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565 enforceModifyPermission();
2566
2567 final long identity = Binder.clearCallingIdentity();
2568 try {
2569 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2570 logv("Shutting down Phone " + i);
2571 shutdownRadioUsingPhoneId(i);
2572 }
2573 } finally {
2574 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002575 }
2576 }
2577
2578 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002579 Phone phone = PhoneFactory.getPhone(phoneId);
2580 if (phone != null && phone.isRadioAvailable()) {
2581 phone.shutdownRadio();
2582 }
2583 }
2584
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002585 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002586 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587
2588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2591 if (defaultPhone != null) {
2592 defaultPhone.setRadioPower(turnOn);
2593 return true;
2594 } else {
2595 loge("There's no default phone.");
2596 return false;
2597 }
2598 } finally {
2599 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002600 }
Wink Saville36469e72014-06-11 15:17:00 -07002601 }
2602
Wink Savilleb564aae2014-10-23 10:18:09 -07002603 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605
2606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 final Phone phone = getPhone(subId);
2609 if (phone != null) {
2610 phone.setRadioPower(turnOn);
2611 return true;
2612 } else {
2613 return false;
2614 }
2615 } finally {
2616 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619
Wink Saville36469e72014-06-11 15:17:00 -07002620 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002621 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 public boolean enableDataConnectivity() {
2623 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624
2625 final long identity = Binder.clearCallingIdentity();
2626 try {
2627 int subId = mSubscriptionController.getDefaultDataSubId();
2628 final Phone phone = getPhone(subId);
2629 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002630 phone.getDataEnabledSettings().setDataEnabled(
2631 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632 return true;
2633 } else {
2634 return false;
2635 }
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 }
2640
Wink Saville36469e72014-06-11 15:17:00 -07002641 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002642 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 public boolean disableDataConnectivity() {
2644 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645
2646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 int subId = mSubscriptionController.getDefaultDataSubId();
2649 final Phone phone = getPhone(subId);
2650 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002651 phone.getDataEnabledSettings().setDataEnabled(
2652 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653 return true;
2654 } else {
2655 return false;
2656 }
2657 } finally {
2658 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 }
2661
Sanket Padawe356d7632015-06-22 14:03:32 -07002662 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002663 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664 final long identity = Binder.clearCallingIdentity();
2665 try {
2666 final Phone phone = getPhone(subId);
2667 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002668 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669 } else {
2670 return false;
2671 }
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 }
2676
2677 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002678 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002679 }
2680
pkanwarae03a6b2016-11-06 20:37:09 -08002681 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682 enforceCallPermission();
2683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2687 return;
2688 }
2689 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2690 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
2693 }
pkanwar32d516d2016-10-14 19:37:38 -07002694 };
2695
Wink Savilleb564aae2014-10-23 10:18:09 -07002696 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698
2699 final long identity = Binder.clearCallingIdentity();
2700 try {
2701 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2702 return false;
2703 }
2704 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 }
2709
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002711 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002712 }
2713
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002714 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 Phone phone = PhoneFactory.getPhone(slotIndex);
2718 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2719 PhoneConstantConversions.convertCallState(phone.getState());
2720 } finally {
2721 Binder.restoreCallingIdentity(identity);
2722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002726 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002727 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2728 }
2729
2730 @Override
2731 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 final long identity = Binder.clearCallingIdentity();
2733 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002734 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 if (phone != null) {
2736 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2737 } else {
2738 return PhoneConstantConversions.convertDataState(
2739 PhoneConstants.DataState.DISCONNECTED);
2740 }
2741 } finally {
2742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 }
2745
Sanket Padawe356d7632015-06-22 14:03:32 -07002746 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002747 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002748 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2749 }
2750
2751 @Override
2752 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753 final long identity = Binder.clearCallingIdentity();
2754 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002755 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756 if (phone != null) {
2757 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2758 } else {
2759 return TelephonyManager.DATA_ACTIVITY_NONE;
2760 }
2761 } finally {
2762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002764 }
2765
2766 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002767 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002768 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002769 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002770
2771 LocationAccessPolicy.LocationPermissionResult locationResult =
2772 LocationAccessPolicy.checkLocationPermission(mApp,
2773 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2774 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002775 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002776 .setCallingPid(Binder.getCallingPid())
2777 .setCallingUid(Binder.getCallingUid())
2778 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002779 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002780 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2781 .build());
2782 switch (locationResult) {
2783 case DENIED_HARD:
2784 throw new SecurityException("Not allowed to access cell location");
2785 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002786 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2787 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002788 }
2789
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002790 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002794 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002795 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796 } finally {
2797 Binder.restoreCallingIdentity(identity);
2798 }
Svetoslav64fad262015-04-14 14:35:21 -07002799 }
2800
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002801 @Override
Jack Yu01425032020-02-22 19:38:58 -08002802 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002803 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2804 // registered cell info, so return a NULL country instead.
2805 final long identity = Binder.clearCallingIdentity();
2806 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002807 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2808 // Get default phone in this case.
2809 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2810 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002811 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002813 if (phone == null) return "";
2814 ServiceStateTracker sst = phone.getServiceStateTracker();
2815 if (sst == null) return "";
2816 LocaleTracker lt = sst.getLocaleTracker();
2817 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002818 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002819 } finally {
2820 Binder.restoreCallingIdentity(identity);
2821 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002822 }
2823
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002824 /**
2825 * This method was removed due to potential issues caused by performing partial
2826 * updates of service state, and lack of a credible use case.
2827 *
2828 * This has the ability to break the telephony implementation by disabling notification of
2829 * changes in device connectivity. DO NOT USE THIS!
2830 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002831 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 public void enableLocationUpdates() {
2833 mApp.enforceCallingOrSelfPermission(
2834 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002835 }
2836
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002837 /**
2838 * This method was removed due to potential issues caused by performing partial
2839 * updates of service state, and lack of a credible use case.
2840 *
2841 * This has the ability to break the telephony implementation by disabling notification of
2842 * changes in device connectivity. DO NOT USE THIS!
2843 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 @Override
2845 public void disableLocationUpdates() {
2846 mApp.enforceCallingOrSelfPermission(
2847 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 }
2849
2850 @Override
2851 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002852 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2853 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002854 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002855 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2856 throw new SecurityException(
2857 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2858 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002859
Jordan Liu1617b712019-07-10 15:06:26 -07002860 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2862 return null;
2863 }
Svetoslav64fad262015-04-14 14:35:21 -07002864
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002865 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002866
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002867 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002868 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869
Nathan Haroldf180aac2018-06-01 18:43:55 -07002870 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2871 for (CellInfo ci : info) {
2872 if (ci instanceof CellInfoGsm) {
2873 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2874 } else if (ci instanceof CellInfoWcdma) {
2875 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002878 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879 }
2880
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002881 private List<CellInfo> getCachedCellInfo() {
2882 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2883 for (Phone phone : PhoneFactory.getPhones()) {
2884 List<CellInfo> info = phone.getAllCellInfo();
2885 if (info != null) cellInfos.addAll(info);
2886 }
2887 return cellInfos;
2888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002889
2890 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002891 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002892 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002893 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002894
2895 LocationAccessPolicy.LocationPermissionResult locationResult =
2896 LocationAccessPolicy.checkLocationPermission(mApp,
2897 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2898 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002899 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002900 .setCallingPid(Binder.getCallingPid())
2901 .setCallingUid(Binder.getCallingUid())
2902 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002903 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002904 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2905 .build());
2906 switch (locationResult) {
2907 case DENIED_HARD:
2908 throw new SecurityException("Not allowed to access cell info");
2909 case DENIED_SOFT:
2910 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 }
2912
Nathan Haroldf096d982020-11-18 17:18:06 -08002913 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002914 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2915 return getCachedCellInfo();
2916 }
2917
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002918 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002919 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2923 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002924 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002925 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 if (info != null) cellInfos.addAll(info);
2927 }
2928 return cellInfos;
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
2932 }
2933
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002934 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002935 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2936 String callingFeatureId) {
2937 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2938 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002939 }
2940
2941 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002942 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2943 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002944 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002945 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002946 }
2947
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002948 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2949 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002950 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002951 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002952
2953 LocationAccessPolicy.LocationPermissionResult locationResult =
2954 LocationAccessPolicy.checkLocationPermission(mApp,
2955 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2956 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002957 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002958 .setCallingPid(Binder.getCallingPid())
2959 .setCallingUid(Binder.getCallingUid())
2960 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002961 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2962 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002963 .build());
2964 switch (locationResult) {
2965 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002966 if (TelephonyPermissions
2967 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002968 // Safetynet logging for b/154934934
2969 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2970 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002971 throw new SecurityException("Not allowed to access cell info");
2972 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002973 if (TelephonyPermissions
2974 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002975 // Safetynet logging for b/154934934
2976 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2977 }
Nathan Harold5320c422019-05-09 10:26:08 -07002978 try {
2979 cb.onCellInfo(new ArrayList<CellInfo>());
2980 } catch (RemoteException re) {
2981 // Drop without consequences
2982 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002983 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002984 }
2985
Nathan Harolda939a962019-05-09 10:13:47 -07002986
2987 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002988 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2989
2990 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2991 }
2992
2993 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002994 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002995 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002996 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997
2998 final long identity = Binder.clearCallingIdentity();
2999 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003000 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003004 }
3005
Shishir Agrawala9f32182016-04-12 12:00:16 -07003006 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003007 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003008 Phone phone = PhoneFactory.getPhone(slotIndex);
3009 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003010 return null;
3011 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003012 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003013 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003014 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003015 return null;
3016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003017
3018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 return phone.getImei();
3021 } finally {
3022 Binder.restoreCallingIdentity(identity);
3023 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003024 }
3025
3026 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003027 public String getTypeAllocationCodeForSlot(int slotIndex) {
3028 Phone phone = PhoneFactory.getPhone(slotIndex);
3029 String tac = null;
3030 if (phone != null) {
3031 String imei = phone.getImei();
3032 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3033 }
3034 return tac;
3035 }
3036
3037 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003038 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003039 Phone phone = PhoneFactory.getPhone(slotIndex);
3040 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003041 return null;
3042 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003043
Jeff Davidson913390f2018-02-23 17:11:49 -08003044 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003045 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003046 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003047 return null;
3048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049
3050 final long identity = Binder.clearCallingIdentity();
3051 try {
3052 return phone.getMeid();
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
Jack Yu2af8d712017-03-15 17:14:14 -07003056 }
3057
3058 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003059 public String getManufacturerCodeForSlot(int slotIndex) {
3060 Phone phone = PhoneFactory.getPhone(slotIndex);
3061 String manufacturerCode = null;
3062 if (phone != null) {
3063 String meid = phone.getMeid();
3064 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3065 }
3066 return manufacturerCode;
3067 }
3068
3069 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003070 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3071 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003072 Phone phone = PhoneFactory.getPhone(slotIndex);
3073 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003074 return null;
3075 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003076 int subId = phone.getSubId();
3077 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003078 mApp, subId, callingPackage, callingFeatureId,
3079 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003080 return null;
3081 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 return phone.getDeviceSvn();
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003089 }
3090
fionaxu43304da2017-11-27 22:51:16 -08003091 @Override
3092 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093 final long identity = Binder.clearCallingIdentity();
3094 try {
3095 final Phone phone = getPhone(subId);
3096 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3097 } finally {
3098 Binder.restoreCallingIdentity(identity);
3099 }
fionaxu43304da2017-11-27 22:51:16 -08003100 }
3101
3102 @Override
3103 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 final Phone phone = getPhone(subId);
3107 return phone == null ? null : phone.getCarrierName();
3108 } finally {
3109 Binder.restoreCallingIdentity(identity);
3110 }
fionaxu43304da2017-11-27 22:51:16 -08003111 }
3112
calvinpanffe225e2018-11-01 19:43:06 +08003113 @Override
chen xu0026ca62019-03-06 15:28:50 -08003114 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 final Phone phone = getPhone(subId);
3118 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003119 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
3123 }
3124
3125 @Override
chen xu0026ca62019-03-06 15:28:50 -08003126 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003127 final long identity = Binder.clearCallingIdentity();
3128 try {
3129 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003130 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003131 } finally {
3132 Binder.restoreCallingIdentity(identity);
3133 }
3134 }
3135
chen xu651eec72018-11-11 19:03:44 -08003136 @Override
chen xu864e11c2018-12-06 22:10:03 -08003137 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3138 if (!isSubscriptionMccMnc) {
3139 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3140 }
chen xu651eec72018-11-11 19:03:44 -08003141 final Phone phone = PhoneFactory.getPhone(slotIndex);
3142 if (phone == null) {
3143 return TelephonyManager.UNKNOWN_CARRIER_ID;
3144 }
3145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
3150 }
3151 }
3152
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003153 //
3154 // Internal helper methods.
3155 //
3156
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003157 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3159 *
3160 * @throws SecurityException if the caller does not have the required permission
3161 */
3162 private void enforceModifyPermission() {
3163 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3164 }
3165
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003166 /**
3167 * Make sure the caller is system.
3168 *
3169 * @throws SecurityException if the caller is not system.
3170 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003171 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003172 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3173 throw new SecurityException("Caller must be system");
3174 }
3175 }
3176
Shuo Qianf2b2df42019-11-13 17:43:31 -08003177 private void enforceActiveEmergencySessionPermission() {
3178 mApp.enforceCallingOrSelfPermission(
3179 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3180 }
3181
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003182 /**
3183 * Make sure the caller has the CALL_PHONE permission.
3184 *
3185 * @throws SecurityException if the caller does not have the required permission
3186 */
3187 private void enforceCallPermission() {
3188 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3189 }
3190
paulhu423b5f22019-08-23 19:17:33 +08003191 private void enforceSettingsPermission() {
3192 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003193 }
3194
Michele Berionned9fbae52020-11-13 02:36:59 +00003195 private void enforceRebootPermission() {
3196 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3197 }
3198
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 private String createTelUrl(String number) {
3200 if (TextUtils.isEmpty(number)) {
3201 return null;
3202 }
3203
Jake Hambye994d462014-02-03 13:10:13 -08003204 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 }
3206
Ihab Awadf9e92732013-12-05 18:02:52 -08003207 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3209 }
3210
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003211 private static void logv(String msg) {
3212 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3213 }
3214
Ihab Awadf9e92732013-12-05 18:02:52 -08003215 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3217 }
3218
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003219 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003220 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003221 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003222 }
3223
Sanket Padawe356d7632015-06-22 14:03:32 -07003224 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003225 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 final Phone phone = PhoneFactory.getPhone(slotIndex);
3229 if (phone == null) {
3230 return PhoneConstants.PHONE_TYPE_NONE;
3231 } else {
3232 return phone.getPhoneType();
3233 }
3234 } finally {
3235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003237 }
3238
3239 /**
3240 * Returns the CDMA ERI icon index to display
3241 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003242 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003243 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3244 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3245 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003246 }
3247
Sanket Padawe356d7632015-06-22 14:03:32 -07003248 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003249 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3250 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003252 mApp, subId, callingPackage, callingFeatureId,
3253 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003254 return -1;
3255 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003256
3257 final long identity = Binder.clearCallingIdentity();
3258 try {
3259 final Phone phone = getPhone(subId);
3260 if (phone != null) {
3261 return phone.getCdmaEriIconIndex();
3262 } else {
3263 return -1;
3264 }
3265 } finally {
3266 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 }
3269
3270 /**
3271 * Returns the CDMA ERI icon mode,
3272 * 0 - ON
3273 * 1 - FLASHING
3274 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003275 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003276 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3277 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3278 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003279 }
3280
Sanket Padawe356d7632015-06-22 14:03:32 -07003281 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003282 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3283 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003285 mApp, subId, callingPackage, callingFeatureId,
3286 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003287 return -1;
3288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003289
3290 final long identity = Binder.clearCallingIdentity();
3291 try {
3292 final Phone phone = getPhone(subId);
3293 if (phone != null) {
3294 return phone.getCdmaEriIconMode();
3295 } else {
3296 return -1;
3297 }
3298 } finally {
3299 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301 }
3302
3303 /**
3304 * Returns the CDMA ERI text,
3305 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003306 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003307 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3308 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3309 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003310 }
3311
Sanket Padawe356d7632015-06-22 14:03:32 -07003312 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003313 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3314 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003316 mApp, subId, callingPackage, callingFeatureId,
3317 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003318 return null;
3319 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003320
3321 final long identity = Binder.clearCallingIdentity();
3322 try {
3323 final Phone phone = getPhone(subId);
3324 if (phone != null) {
3325 return phone.getCdmaEriText();
3326 } else {
3327 return null;
3328 }
3329 } finally {
3330 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003332 }
3333
3334 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003335 * Returns the CDMA MDN.
3336 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003337 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003338 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3340 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003341
3342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003345 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346 return phone.getLine1Number();
3347 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349 return null;
3350 }
3351 } finally {
3352 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003353 }
3354 }
3355
3356 /**
3357 * Returns the CDMA MIN.
3358 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003359 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003360 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3362 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003363
3364 final long identity = Binder.clearCallingIdentity();
3365 try {
3366 final Phone phone = getPhone(subId);
3367 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3368 return phone.getCdmaMin();
3369 } else {
3370 return null;
3371 }
3372 } finally {
3373 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003374 }
3375 }
3376
Hall Liud892bec2018-11-30 14:51:45 -08003377 @Override
3378 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3379 INumberVerificationCallback callback, String callingPackage) {
3380 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3381 != PERMISSION_GRANTED) {
3382 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3383 }
3384 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3385
3386 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3387 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003388 throw new SecurityException("Calling package must be configured in the device config: "
3389 + "calling package: " + callingPackage
3390 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003391 }
3392
3393 if (range == null) {
3394 throw new NullPointerException("Range must be non-null");
3395 }
3396
3397 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003398 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003399
3400 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3401 }
3402
Junda Liuca05d5d2014-08-14 22:36:34 -07003403 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003404 * Returns true if CDMA provisioning needs to run.
3405 */
3406 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407 final long identity = Binder.clearCallingIdentity();
3408 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003409 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003410 } finally {
3411 Binder.restoreCallingIdentity(identity);
3412 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 }
3414
3415 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003416 * Sets the voice mail number of a given subId.
3417 */
3418 @Override
3419 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003420 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3421 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422
3423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3426 new Pair<String, String>(alphaTag, number), new Integer(subId));
3427 return success;
3428 } finally {
3429 Binder.restoreCallingIdentity(identity);
3430 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003431 }
3432
Ta-wei Yen87c49842016-05-13 21:19:52 -07003433 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003434 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3435 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003436 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3437 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003438 if (!TextUtils.equals(callingPackage, systemDialer)) {
3439 throw new SecurityException("caller must be system dialer");
3440 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003441
3442 final long identity = Binder.clearCallingIdentity();
3443 try {
3444 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3445 if (phoneAccountHandle == null) {
3446 return null;
3447 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003448 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003449 } finally {
3450 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003451 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003452 }
3453
3454 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003455 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3456 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003459 mApp, subId, callingPackage, callingFeatureId,
3460 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003461 return null;
3462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003464 final long identity = Binder.clearCallingIdentity();
3465 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003466 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003470 }
3471
3472 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003473 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3474 VisualVoicemailSmsFilterSettings settings) {
3475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003476
3477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003480 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003481 } finally {
3482 Binder.restoreCallingIdentity(identity);
3483 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003484 }
3485
3486 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003487 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3488 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003489
3490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003493 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003494 } finally {
3495 Binder.restoreCallingIdentity(identity);
3496 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003497 }
3498
3499 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003500 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3501 String callingPackage, int subId) {
3502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003503
3504 final long identity = Binder.clearCallingIdentity();
3505 try {
3506 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003507 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003508 } finally {
3509 Binder.restoreCallingIdentity(identity);
3510 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003511 }
3512
3513 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003514 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003516
3517 final long identity = Binder.clearCallingIdentity();
3518 try {
3519 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003520 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003524 }
3525
3526 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003527 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3528 String callingAttributionTag, int subId, String number, int port, String text,
3529 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003530 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003531 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003532 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003533 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003534 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3535 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003536 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003537
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003538 /**
fionaxu0152e512016-11-14 13:36:14 -08003539 * Sets the voice activation state of a given subId.
3540 */
3541 @Override
3542 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3544 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 final Phone phone = getPhone(subId);
3549 if (phone != null) {
3550 phone.setVoiceActivationState(activationState);
3551 } else {
3552 loge("setVoiceActivationState fails with invalid subId: " + subId);
3553 }
3554 } finally {
3555 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003556 }
3557 }
3558
3559 /**
3560 * Sets the data activation state of a given subId.
3561 */
3562 @Override
3563 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3565 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003566
3567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 final Phone phone = getPhone(subId);
3570 if (phone != null) {
3571 phone.setDataActivationState(activationState);
3572 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003573 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003574 }
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003577 }
3578 }
3579
3580 /**
3581 * Returns the voice activation state of a given subId.
3582 */
3583 @Override
3584 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586
fionaxu0152e512016-11-14 13:36:14 -08003587 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 if (phone != null) {
3591 return phone.getVoiceActivationState();
3592 } else {
3593 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3594 }
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003597 }
3598 }
3599
3600 /**
3601 * Returns the data activation state of a given subId.
3602 */
3603 @Override
3604 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003605 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606
fionaxu0152e512016-11-14 13:36:14 -08003607 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003608 final long identity = Binder.clearCallingIdentity();
3609 try {
3610 if (phone != null) {
3611 return phone.getDataActivationState();
3612 } else {
3613 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3614 }
3615 } finally {
3616 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003617 }
3618 }
3619
3620 /**
Wink Saville36469e72014-06-11 15:17:00 -07003621 * Returns the unread count of voicemails for a subId
3622 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003623 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003624 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3625 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003627 mApp, subId, callingPackage, callingFeatureId,
3628 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003629 return 0;
3630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003631 final long identity = Binder.clearCallingIdentity();
3632 try {
3633 final Phone phone = getPhone(subId);
3634 if (phone != null) {
3635 return phone.getVoiceMessageCount();
3636 } else {
3637 return 0;
3638 }
3639 } finally {
3640 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003642 }
3643
3644 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003645 * returns true, if the device is in a state where both voice and data
3646 * are supported simultaneously. This can change based on location or network condition.
3647 */
3648 @Override
3649 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 final Phone phone = getPhone(subId);
3653 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003657 }
3658
3659 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003660 * Send the dialer code if called from the current default dialer or the caller has
3661 * carrier privilege.
3662 * @param inputCode The dialer code to send
3663 */
3664 @Override
3665 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003666 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003667 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003668 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3669 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003670 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003671 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003672 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003674
3675 final long identity = Binder.clearCallingIdentity();
3676 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003677 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
fionaxu235cc5e2017-03-06 22:25:57 -08003681 }
3682
Pengquan Menga1bb6272018-09-06 09:59:22 -07003683 @Override
3684 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003685 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07003686 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003687 mApp, subId, "getNetworkSelectionMode");
3688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 if (!isActiveSubscription(subId)) {
3691 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3692 }
3693 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003696 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003697 }
3698
Brad Ebinger35c841c2018-10-01 10:40:55 -07003699 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003700 public boolean isInEmergencySmsMode() {
3701 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3702 final long identity = Binder.clearCallingIdentity();
3703 try {
3704 for (Phone phone : PhoneFactory.getPhones()) {
3705 if (phone.isInEmergencySmsMode()) {
3706 return true;
3707 }
3708 }
3709 } finally {
3710 Binder.restoreCallingIdentity(identity);
3711 }
3712 return false;
3713 }
3714
shilu366312e2019-12-17 09:28:10 -08003715 /**
3716 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3717 * @param subId The subscription to use to check the configuration.
3718 * @param c The callback that will be used to send the result.
3719 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003720 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003721 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3722 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003723 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003724 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003725
Brad Ebinger77b832e2019-10-17 17:03:22 -07003726 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3727 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3728 "IMS not available on device.");
3729 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003730 final long token = Binder.clearCallingIdentity();
3731 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003732 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003733 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003734 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003735 } catch (ImsException e) {
3736 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003737 } finally {
3738 Binder.restoreCallingIdentity(token);
3739 }
3740 }
3741
shilu366312e2019-12-17 09:28:10 -08003742 /**
3743 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3744 * @param subId The subscription to use to check the configuration.
3745 * @param c The callback that will be used to send the result.
3746 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003748 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003749 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003750 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003751 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3752 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3753 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003754 final long token = Binder.clearCallingIdentity();
3755 try {
3756 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3757 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3758 .removeRegistrationCallbackForSubscription(c, subId);
3759 } catch (ImsException e) {
3760 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3761 + "is inactive, ignoring unregister.");
3762 // If the subscription is no longer active, just return, since the callback
3763 // will already have been removed internally.
3764 } finally {
3765 Binder.restoreCallingIdentity(token);
3766 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003767 }
3768
Brad Ebinger774ba362019-10-22 17:36:18 -07003769 /**
3770 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3771 */
3772 @Override
3773 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3774 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3775 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3776 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3777 "IMS not available on device.");
3778 }
3779 final long token = Binder.clearCallingIdentity();
3780 try {
3781 Phone phone = getPhone(subId);
3782 if (phone == null) {
3783 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3784 + subId + "'");
3785 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3786 }
3787 phone.getImsRegistrationState(regState -> {
3788 try {
3789 consumer.accept((regState == null)
3790 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3791 } catch (RemoteException e) {
3792 // Ignore if the remote process is no longer available to call back.
3793 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3794 }
3795 });
3796 } finally {
3797 Binder.restoreCallingIdentity(token);
3798 }
3799 }
3800
3801 /**
3802 * Get the transport type for the IMS service registration state.
3803 */
3804 @Override
3805 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003806 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003807 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003808 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3809 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3810 "IMS not available on device.");
3811 }
3812 final long token = Binder.clearCallingIdentity();
3813 try {
3814 Phone phone = getPhone(subId);
3815 if (phone == null) {
3816 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3817 + subId + "'");
3818 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3819 }
3820 phone.getImsRegistrationTech(regTech -> {
3821 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3822 int regTechConverted = (regTech == null)
3823 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3824 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3825 regTechConverted);
3826 try {
3827 consumer.accept(regTechConverted);
3828 } catch (RemoteException e) {
3829 // Ignore if the remote process is no longer available to call back.
3830 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3831 }
3832 });
3833 } finally {
3834 Binder.restoreCallingIdentity(token);
3835 }
3836 }
3837
shilu366312e2019-12-17 09:28:10 -08003838 /**
3839 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3840 * @param subId The subscription to use to check the configuration.
3841 * @param c The callback that will be used to send the result.
3842 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003844 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3845 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003846 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003847 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003848 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3849 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3850 "IMS not available on device.");
3851 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3853 final long token = Binder.clearCallingIdentity();
3854 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003855 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003856 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003857 } catch (ImsException e) {
3858 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003859 } finally {
3860 Binder.restoreCallingIdentity(token);
3861 }
3862 }
3863
shilu366312e2019-12-17 09:28:10 -08003864 /**
3865 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3866 * @param subId The subscription to use to check the configuration.
3867 * @param c The callback that will be used to send the result.
3868 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003869 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003870 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003871 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003872 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3874 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3875 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003876
3877 final long token = Binder.clearCallingIdentity();
3878 try {
3879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3880 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003881 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003882 } catch (ImsException e) {
3883 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3884 + "is inactive, ignoring unregister.");
3885 // If the subscription is no longer active, just return, since the callback
3886 // will already have been removed internally.
3887 } finally {
3888 Binder.restoreCallingIdentity(token);
3889 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 }
3891
3892 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003893 public boolean isCapable(int subId, int capability, int regTech) {
3894 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3896 final long token = Binder.clearCallingIdentity();
3897 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003898 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003900 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3902 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003903 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003904 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3905 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 } finally {
3907 Binder.restoreCallingIdentity(token);
3908 }
3909 }
3910
3911 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003912 public boolean isAvailable(int subId, int capability, int regTech) {
3913 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 final long token = Binder.clearCallingIdentity();
3915 try {
3916 Phone phone = getPhone(subId);
3917 if (phone == null) return false;
3918 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003919 } catch (com.android.ims.ImsException e) {
3920 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3921 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003922 } finally {
3923 Binder.restoreCallingIdentity(token);
3924 }
3925 }
3926
Brad Ebinger77b832e2019-10-17 17:03:22 -07003927 /**
3928 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3929 * subscription.
3930 * @param subId The subscription to use to check the configuration.
3931 * @param callback The callback that will be used to send the result.
3932 * @param capability The MmTelFeature capability that will be used to send the result.
3933 * @param transportType The transport type of the MmTelFeature capability.
3934 */
3935 @Override
3936 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3937 int transportType) {
3938 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3939 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3940 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3941 "IMS not available on device.");
3942 }
3943 final long token = Binder.clearCallingIdentity();
3944 try {
3945 int slotId = getSlotIndex(subId);
3946 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3947 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3948 + subId + "'");
3949 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3950 }
3951 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3952 transportType, aBoolean -> {
3953 try {
3954 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3955 } catch (RemoteException e) {
3956 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3957 + "running. Ignore");
3958 }
3959 });
3960 } finally {
3961 Binder.restoreCallingIdentity(token);
3962 }
3963 }
3964
shilu366312e2019-12-17 09:28:10 -08003965 /**
3966 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3967 * @param subId The subscription to use to check the configuration.
3968 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 @Override
3970 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003971 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003972 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003973
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3975 final long token = Binder.clearCallingIdentity();
3976 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003977 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003978 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003979 } catch (ImsException e) {
3980 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 } finally {
3982 Binder.restoreCallingIdentity(token);
3983 }
3984 }
3985
3986 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003987 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003989 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003993 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003995 } catch (ImsException e) {
3996 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003997 } finally {
3998 Binder.restoreCallingIdentity(identity);
3999 }
4000 }
4001
shilu366312e2019-12-17 09:28:10 -08004002 /**
4003 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4004 * @param subId The subscription to use to check the configuration.
4005 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004007 public boolean isVtSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004008 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004009 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004013 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4014 } catch (ImsException e) {
4015 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004016 } finally {
4017 Binder.restoreCallingIdentity(identity);
4018 }
4019 }
4020
4021 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004022 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004024 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 final long identity = Binder.clearCallingIdentity();
4026 try {
4027 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004028 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004029 } catch (ImsException e) {
4030 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
4034 }
4035
shilu366312e2019-12-17 09:28:10 -08004036 /**
4037 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4038 * @param subId The subscription to use to check the configuration.
4039 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 @Override
4041 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004042 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004043 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 final long identity = Binder.clearCallingIdentity();
4045 try {
4046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004047 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004049 } catch (ImsException e) {
4050 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004051 } finally {
4052 Binder.restoreCallingIdentity(identity);
4053 }
4054 }
4055
4056 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004057 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004059 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 final long identity = Binder.clearCallingIdentity();
4061 try {
4062 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004063 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004064 } catch (ImsException e) {
4065 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 } finally {
4067 Binder.restoreCallingIdentity(identity);
4068 }
4069 }
4070
shilu366312e2019-12-17 09:28:10 -08004071 /**
4072 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4073 * @param subId The subscription to use to check the configuration.
4074 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 @Override
4076 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004077 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004078 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004079 final long identity = Binder.clearCallingIdentity();
4080 try {
4081 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004082 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004084 } catch (ImsException e) {
4085 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
4089 }
4090
4091 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004092 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004094 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004095 final long identity = Binder.clearCallingIdentity();
4096 try {
4097 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004098 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004099 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004100 } catch (ImsException e) {
4101 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004102 } finally {
4103 Binder.restoreCallingIdentity(identity);
4104 }
4105 }
4106
4107 @Override
4108 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4110 "setVoWiFiNonPersistent");
4111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004114 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004115 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004116 } catch (ImsException e) {
4117 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
4121 }
4122
shilu366312e2019-12-17 09:28:10 -08004123 /**
4124 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4125 * @param subId The subscription to use to check the configuration.
4126 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 @Override
4128 public int getVoWiFiModeSetting(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004129 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004130 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 final long identity = Binder.clearCallingIdentity();
4132 try {
4133 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004134 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004136 } catch (ImsException e) {
4137 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
4141 }
4142
4143 @Override
4144 public void setVoWiFiModeSetting(int subId, int mode) {
4145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4146 "setVoWiFiModeSetting");
4147 final long identity = Binder.clearCallingIdentity();
4148 try {
4149 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004150 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004152 } catch (ImsException e) {
4153 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 } finally {
4155 Binder.restoreCallingIdentity(identity);
4156 }
4157 }
4158
4159 @Override
4160 public int getVoWiFiRoamingModeSetting(int subId) {
4161 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004165 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004167 } catch (ImsException e) {
4168 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
4172 }
4173
4174 @Override
4175 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4177 "setVoWiFiRoamingModeSetting");
4178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004181 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004183 } catch (ImsException e) {
4184 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 } finally {
4186 Binder.restoreCallingIdentity(identity);
4187 }
4188 }
4189
4190 @Override
4191 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4193 "setRttCapabilityEnabled");
4194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004197 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4198 } catch (ImsException e) {
4199 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
4203 }
4204
shilu366312e2019-12-17 09:28:10 -08004205 /**
4206 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4207 * @param subId The subscription to use to check the configuration.
4208 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 @Override
4210 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004211 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004212 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004216 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004218 } catch (ImsException e) {
4219 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 } finally {
4221 Binder.restoreCallingIdentity(identity);
4222 }
4223 }
4224
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004225 @Override
4226 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4227 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4228 final long identity = Binder.clearCallingIdentity();
4229 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004230 if (!isImsAvailableOnDevice()) {
4231 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4232 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004233 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004234 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004235 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004236 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004237 } catch (ImsException e) {
4238 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
4242 }
4243
4244 @Override
4245 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4246 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4247 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004248 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4249 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4250 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004251 try {
4252 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004253 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004254 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004255 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004256 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4257 + "is inactive, ignoring unregister.");
4258 // If the subscription is no longer active, just return, since the callback will already
4259 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004260 } finally {
4261 Binder.restoreCallingIdentity(identity);
4262 }
4263 }
4264
allenwtsu99c623b2020-01-03 18:24:23 +08004265
4266 private void checkModifyPhoneStatePermission(int subId, String message) {
4267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4268 message);
4269 }
4270
4271 private boolean isImsProvisioningRequired(int subId, int capability,
4272 boolean isMmtelCapability) {
4273 Phone phone = getPhone(subId);
4274 if (phone == null) {
4275 loge("phone instance null for subid " + subId);
4276 return false;
4277 }
4278 if (isMmtelCapability) {
4279 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4280 return false;
4281 }
4282 } else {
4283 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4284 return false;
4285 }
4286 }
4287 return true;
4288 }
4289
4290 @Override
4291 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4292 boolean isProvisioned) {
4293 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4294
4295 final long identity = Binder.clearCallingIdentity();
4296 try {
4297 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4298 if (!isImsProvisioningRequired(subId, capability, false)) {
4299 return;
4300 }
4301
4302 // this capability requires provisioning, route to the correct API.
4303 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4304 switch (capability) {
4305 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4306 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4307 ims.setEabProvisioned(isProvisioned);
4308 break;
4309 default: {
4310 throw new IllegalArgumentException("Tried to set provisioning for "
4311 + "rcs capability '" + capability + "', which does not require "
4312 + "provisioning.");
4313 }
4314 }
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
4318
4319 }
4320
4321
4322 @Override
4323 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4324 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4325 final long identity = Binder.clearCallingIdentity();
4326 try {
4327 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4328 if (!isImsProvisioningRequired(subId, capability, false)) {
4329 return true;
4330 }
4331
4332 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4333 switch (capability) {
4334 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4335 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4336 return ims.isEabProvisionedOnDevice();
4337
4338 default: {
4339 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4340 + "capability '" + capability + "', which does not require "
4341 + "provisioning.");
4342 }
4343 }
4344
4345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
4348 }
4349
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004350 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004351 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4352 boolean isProvisioned) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004353 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4354 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004355 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4356 }
allenwtsu99c623b2020-01-03 18:24:23 +08004357 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004358 final long identity = Binder.clearCallingIdentity();
4359 try {
4360 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004361 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004362 return;
4363 }
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004364 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4365 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4366 loge("setImsProvisioningStatusForCapability: called for technology that does "
4367 + "not support provisioning - " + tech);
4368 return;
4369 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004370
4371 // this capability requires provisioning, route to the correct API.
4372 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4373 switch (capability) {
4374 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4375 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4376 ims.setVolteProvisioned(isProvisioned);
4377 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4378 ims.setWfcProvisioned(isProvisioned);
4379 }
4380 break;
4381 }
4382 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4383 // There is currently no difference in VT provisioning type.
4384 ims.setVtProvisioned(isProvisioned);
4385 break;
4386 }
4387 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4388 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4389 // change the capability of the feature instead if needed.
4390 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4391 == isProvisioned) {
4392 // No change in provisioning.
4393 return;
4394 }
4395 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4396 try {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004397 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004398 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004399 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4400 + ", Exception" + e.getMessage());
4401 }
4402 break;
4403 }
4404 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004405 throw new IllegalArgumentException("Tried to set provisioning for "
4406 + "MmTel capability '" + capability + "', which does not require "
4407 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004408 }
4409 }
4410
4411 } finally {
4412 Binder.restoreCallingIdentity(identity);
4413 }
4414 }
4415
4416 @Override
4417 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004418 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4419 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004420 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4421 }
4422 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4423 final long identity = Binder.clearCallingIdentity();
4424 try {
4425 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004426 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004427 return true;
4428 }
4429
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004430 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4431 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4432 loge("getImsProvisioningStatusForCapability: called for technology that does "
4433 + "not support provisioning - " + tech);
4434 return true;
4435 }
4436
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004437 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4438 switch (capability) {
4439 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4440 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4441 return ims.isVolteProvisionedOnDevice();
4442 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4443 return ims.isWfcProvisionedOnDevice();
4444 }
4445 // This should never happen, since we are checking tech above to make sure it
4446 // is either LTE or IWLAN.
4447 throw new IllegalArgumentException("Invalid radio technology for voice "
4448 + "capability.");
4449 }
4450 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4451 // There is currently no difference in VT provisioning type.
4452 return ims.isVtProvisionedOnDevice();
4453 }
4454 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4455 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4456 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4457 }
4458 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004459 throw new IllegalArgumentException(
4460 "Tried to get provisioning for MmTel capability '" + capability
4461 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004462 }
4463 }
4464
4465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
4468 }
4469
4470 @Override
4471 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4472 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4473 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4474 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4475 }
4476 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4477 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4478 return (provisionedBits & capability) > 0;
4479 }
4480
4481 @Override
4482 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4483 boolean isProvisioned) {
4484 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4485 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4486 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4487 }
4488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4489 "setProvisioningStatusForCapability");
4490 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4491 // If the current provisioning status for capability already matches isProvisioned,
4492 // do nothing.
4493 if (((provisionedBits & capability) > 0) == isProvisioned) {
4494 return;
4495 }
4496 if (isProvisioned) {
4497 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4498 } else {
4499 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4500 }
4501 }
4502
4503 /**
4504 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4505 * technology. The bitfield should mirror the bitfield defined by
4506 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4507 */
4508 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4509 String key = getMmTelProvisioningKey(subId, tech);
4510 // Default is no capabilities are provisioned.
4511 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4512 }
4513
4514 /**
4515 * Sets the MmTel capability provisioning bitfield (defined by
4516 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4517 * technology specified.
4518 *
4519 * Note: This is a synchronous command and should not be called on UI thread.
4520 */
4521 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4522 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4523 String key = getMmTelProvisioningKey(subId, tech);
4524 editor.putInt(key, newField);
4525 editor.commit();
4526 }
4527
4528 private static String getMmTelProvisioningKey(int subId, int tech) {
4529 // resulting key is provision_ims_mmtel_{subId}_{tech}
4530 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4531 }
4532
4533 /**
4534 * Query CarrierConfig to see if the specified capability requires provisioning for the
4535 * carrier associated with the subscription id.
4536 */
4537 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4538 int capability) {
4539 CarrierConfigManager configManager = new CarrierConfigManager(context);
4540 PersistableBundle c = configManager.getConfigForSubId(subId);
4541 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004542 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004543 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4544 false);
4545 boolean requireVoiceVtProvisioning = c.getBoolean(
4546 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4547
4548 // First check to make sure that the capability requires provisioning.
4549 switch (capability) {
4550 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4551 // intentional fallthrough
4552 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4553 if (requireVoiceVtProvisioning) {
4554 // Voice and Video requires provisioning
4555 return true;
4556 }
4557 break;
4558 }
4559 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4560 if (requireUtProvisioning) {
4561 // UT requires provisioning
4562 return true;
4563 }
4564 break;
4565 }
4566 }
4567 return false;
4568 }
4569
allenwtsu99c623b2020-01-03 18:24:23 +08004570 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4571 int capability) {
4572 CarrierConfigManager configManager = new CarrierConfigManager(context);
4573 PersistableBundle c = configManager.getConfigForSubId(subId);
4574
4575 boolean requireRcsProvisioning = c.getBoolean(
4576 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4577
4578 // First check to make sure that the capability requires provisioning.
4579 switch (capability) {
4580 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4581 // intentional fallthrough
4582 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4583 if (requireRcsProvisioning) {
4584 // OPTION or PRESENCE requires provisioning
4585 return true;
4586 }
4587 break;
4588 }
4589 }
4590 return false;
4591 }
4592
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004593 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004594 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004595 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4596 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4597 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004598 enforceReadPrivilegedPermission("getImsProvisioningInt");
4599 final long identity = Binder.clearCallingIdentity();
4600 try {
4601 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004602 int slotId = getSlotIndex(subId);
4603 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4604 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4605 + subId + "' for key:" + key);
4606 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4607 }
calvinpan9cfff472021-02-08 19:59:36 +08004608 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004609 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004610 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4611 + subId + "' for key:" + key);
4612 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004613 } finally {
4614 Binder.restoreCallingIdentity(identity);
4615 }
4616 }
4617
4618 @Override
4619 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004620 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4621 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4622 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004623 enforceReadPrivilegedPermission("getImsProvisioningString");
4624 final long identity = Binder.clearCallingIdentity();
4625 try {
4626 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004627 int slotId = getSlotIndex(subId);
4628 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4629 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4630 + subId + "' for key:" + key);
4631 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4632 }
calvinpan9cfff472021-02-08 19:59:36 +08004633 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004634 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004635 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4636 + subId + "' for key:" + key);
4637 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004638 } finally {
4639 Binder.restoreCallingIdentity(identity);
4640 }
4641 }
4642
4643 @Override
4644 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4646 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4647 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4649 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004650 final long identity = Binder.clearCallingIdentity();
4651 try {
4652 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004653 int slotId = getSlotIndex(subId);
4654 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4655 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4656 + subId + "' for key:" + key);
4657 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4658 }
calvinpan9cfff472021-02-08 19:59:36 +08004659 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4660 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004661 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004662 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004663 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004664 } finally {
4665 Binder.restoreCallingIdentity(identity);
4666 }
4667 }
4668
4669 @Override
4670 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004671 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4672 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4673 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4675 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004676 final long identity = Binder.clearCallingIdentity();
4677 try {
4678 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004679 int slotId = getSlotIndex(subId);
4680 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4681 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4682 + subId + "' for key:" + key);
4683 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4684 }
calvinpan9cfff472021-02-08 19:59:36 +08004685 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4686 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004687 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004688 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004689 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004690 } finally {
4691 Binder.restoreCallingIdentity(identity);
4692 }
4693 }
4694
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004695 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004696 int slotId = SubscriptionManager.getSlotIndex(subId);
4697 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004698 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4699 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004700 }
4701 return slotId;
4702 }
4703
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004704 private int getSlotIndex(int subId) {
4705 int slotId = SubscriptionManager.getSlotIndex(subId);
4706 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4707 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4708 }
4709 return slotId;
4710 }
4711
Wink Saville36469e72014-06-11 15:17:00 -07004712 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004713 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004714 */
4715 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004716 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4717 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004718 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004719 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004720 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004721 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004722 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004723 mApp, subId, callingPackage, callingFeatureId,
4724 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004725 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4726 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728 final long identity = Binder.clearCallingIdentity();
4729 try {
4730 final Phone phone = getPhone(subId);
4731 if (phone != null) {
4732 return phone.getServiceState().getDataNetworkType();
4733 } else {
4734 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4735 }
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004739 }
4740
4741 /**
4742 * Returns the data network type
4743 */
4744 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004745 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004746 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4747 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004748 }
4749
4750 /**
4751 * Returns the data network type for a subId
4752 */
4753 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004754 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4755 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004757 mApp, subId, callingPackage, callingFeatureId,
4758 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004759 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4760 }
4761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 final long identity = Binder.clearCallingIdentity();
4763 try {
4764 final Phone phone = getPhone(subId);
4765 if (phone != null) {
4766 return phone.getServiceState().getDataNetworkType();
4767 } else {
4768 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4769 }
4770 } finally {
4771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004773 }
4774
4775 /**
Wink Saville36469e72014-06-11 15:17:00 -07004776 * Returns the Voice network type for a subId
4777 */
4778 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004779 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4780 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004781 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004782 mApp, subId, callingPackage, callingFeatureId,
4783 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004784 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4785 }
4786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004787 final long identity = Binder.clearCallingIdentity();
4788 try {
4789 final Phone phone = getPhone(subId);
4790 if (phone != null) {
4791 return phone.getServiceState().getVoiceNetworkType();
4792 } else {
4793 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4794 }
4795 } finally {
4796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004798 }
4799
4800 /**
4801 * @return true if a ICC card is present
4802 */
4803 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004804 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004805 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4806 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004807 }
4808
4809 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004810 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004811 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004812 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004813 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 final Phone phone = PhoneFactory.getPhone(slotIndex);
4817 if (phone != null) {
4818 return phone.getIccCard().hasIccCard();
4819 } else {
4820 return false;
4821 }
4822 } finally {
4823 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004825 }
4826
4827 /**
4828 * Return if the current radio is LTE on CDMA. This
4829 * is a tri-state return value as for a period of time
4830 * the mode may be unknown.
4831 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004832 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004833 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004834 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004835 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004836 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004837 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4838 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4839 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004840 }
4841
Sanket Padawe356d7632015-06-22 14:03:32 -07004842 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004843 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4844 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004845 try {
4846 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4847 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004848 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4849 }
4850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 final long identity = Binder.clearCallingIdentity();
4852 try {
4853 final Phone phone = getPhone(subId);
4854 if (phone == null) {
4855 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4856 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004857 return TelephonyProperties.lte_on_cdma_device()
4858 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 }
4860 } finally {
4861 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004862 }
Wink Saville36469e72014-06-11 15:17:00 -07004863 }
4864
Wink Saville36469e72014-06-11 15:17:00 -07004865 /**
4866 * {@hide}
4867 * Returns Default subId, 0 in the case of single standby.
4868 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004869 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004870 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004871 }
4872
Shishir Agrawala9f32182016-04-12 12:00:16 -07004873 private int getSlotForDefaultSubscription() {
4874 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4875 }
4876
Wink Savilleb564aae2014-10-23 10:18:09 -07004877 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004878 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004879 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004880
Pengquan Menge92a50d2018-09-21 15:54:48 -07004881 private boolean isActiveSubscription(int subId) {
4882 return mSubscriptionController.isActiveSubId(subId);
4883 }
4884
Ihab Awadf2177b72013-11-25 13:33:23 -08004885 /**
4886 * @see android.telephony.TelephonyManager.WifiCallingChoices
4887 */
4888 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 final long identity = Binder.clearCallingIdentity();
4890 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004891 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4893 getWhenToMakeWifiCallsDefaultPreference());
4894 } finally {
4895 Binder.restoreCallingIdentity(identity);
4896 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004897 }
4898
4899 /**
4900 * @see android.telephony.TelephonyManager.WifiCallingChoices
4901 */
4902 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 final long identity = Binder.clearCallingIdentity();
4904 try {
4905 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004906 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4908 } finally {
4909 Binder.restoreCallingIdentity(identity);
4910 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004911 }
4912
Sailesh Nepald1e68152013-12-12 19:08:02 -08004913 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004914 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004915 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004916 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004917
Jordan Liu4c733742019-02-28 12:03:40 -08004918 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4919 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4920 if (phoneId == -1) {
4921 throw new IllegalArgumentException("Given slot index: " + slotIndex
4922 + " does not correspond to an active phone");
4923 }
4924 return PhoneFactory.getPhone(phoneId);
4925 }
4926
Shishir Agrawal566b7612013-10-28 14:41:00 -07004927 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004928 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4929 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4931 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004933 if (DBG) {
4934 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4935 }
4936 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4937 p2);
4938 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004939
Jordan Liu4c733742019-02-28 12:03:40 -08004940
4941 @Override
4942 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4943 int slotIndex, String callingPackage, String aid, int p2) {
4944 enforceModifyPermission();
4945 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4946 if (DBG) {
4947 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4948 }
4949 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4950 callingPackage, aid, p2);
4951 }
4952
4953 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4954 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004955 final long identity = Binder.clearCallingIdentity();
4956 try {
4957 if (TextUtils.equals(ISDR_AID, aid)) {
4958 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004959 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4960 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961 if (bestComponent == null
4962 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4963 loge("The calling package is not allowed to access ISD-R.");
4964 throw new SecurityException(
4965 "The calling package is not allowed to access ISD-R.");
4966 }
Derek Tan740e1672017-06-27 14:56:27 -07004967 }
Derek Tan740e1672017-06-27 14:56:27 -07004968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004970 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4971 null /* workSource */);
4972 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 return response;
4974 } finally {
4975 Binder.restoreCallingIdentity(identity);
4976 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004977 }
4978
4979 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004980 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4982 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004983 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4984 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4985 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004986
Jordan Liu4c733742019-02-28 12:03:40 -08004987 @Override
4988 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4989 enforceModifyPermission();
4990 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4991 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4992 channel);
4993 }
4994
4995 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996 final long identity = Binder.clearCallingIdentity();
4997 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 if (channel < 0) {
4999 return false;
5000 }
Jordan Liu4c733742019-02-28 12:03:40 -08005001 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5002 null /* workSource */);
5003 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 return success;
5005 } finally {
5006 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005007 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005008 }
5009
5010 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005011 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005012 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5014 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005015 if (DBG) {
5016 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5017 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5018 + p3 + " data=" + data);
5019 }
5020 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5021 command, p1, p2, p3, data);
5022 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005023
Jordan Liu4c733742019-02-28 12:03:40 -08005024 @Override
5025 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5026 int command, int p1, int p2, int p3, String data) {
5027 enforceModifyPermission();
5028 if (DBG) {
5029 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5030 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5031 + p3 + " data=" + data);
5032 }
5033 return iccTransmitApduLogicalChannelWithPermission(
5034 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5035 data);
5036 }
5037
5038 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5039 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040 final long identity = Binder.clearCallingIdentity();
5041 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005042 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 return "";
5044 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005047 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5048 null /* workSource */);
5049 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051 // Append the returned status code to the end of the response payload.
5052 String s = Integer.toHexString(
5053 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5054 if (response.payload != null) {
5055 s = IccUtils.bytesToHexString(response.payload) + s;
5056 }
5057 return s;
5058 } finally {
5059 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005060 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005061 }
Jake Hambye994d462014-02-03 13:10:13 -08005062
Evan Charltonc66da362014-05-16 14:06:40 -07005063 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005064 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5065 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5067 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005069 if (DBG) {
5070 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5071 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5072 }
5073 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5074 cla, command, p1, p2, p3, data);
5075 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005076
Jordan Liu4c733742019-02-28 12:03:40 -08005077 @Override
5078 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5079 int command, int p1, int p2, int p3, String data) {
5080 enforceModifyPermission();
5081 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5082 if (DBG) {
5083 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5084 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5085 + " data=" + data);
5086 }
5087
5088 return iccTransmitApduBasicChannelWithPermission(
5089 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5090 p2, p3, data);
5091 }
5092
5093 // open APDU basic channel assuming the caller has sufficient permissions
5094 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5095 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
5098 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5099 && TextUtils.equals(ISDR_AID, data)) {
5100 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005101 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5102 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005103 if (bestComponent == null
5104 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5105 loge("The calling package is not allowed to select ISD-R.");
5106 throw new SecurityException(
5107 "The calling package is not allowed to select ISD-R.");
5108 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005109 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005112 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5113 null /* workSource */);
5114 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 // Append the returned status code to the end of the response payload.
5117 String s = Integer.toHexString(
5118 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5119 if (response.payload != null) {
5120 s = IccUtils.bytesToHexString(response.payload) + s;
5121 }
5122 return s;
5123 } finally {
5124 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005125 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005126 }
5127
5128 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005129 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005130 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5132 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 final long identity = Binder.clearCallingIdentity();
5135 try {
5136 if (DBG) {
5137 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5138 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5139 }
5140
5141 IccIoResult response =
5142 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5143 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5144 subId);
5145
5146 if (DBG) {
5147 log("Exchange SIM_IO [R]" + response);
5148 }
5149
5150 byte[] result = null;
5151 int length = 2;
5152 if (response.payload != null) {
5153 length = 2 + response.payload.length;
5154 result = new byte[length];
5155 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5156 } else {
5157 result = new byte[length];
5158 }
5159
5160 result[length - 1] = (byte) response.sw2;
5161 result[length - 2] = (byte) response.sw1;
5162 return result;
5163 } finally {
5164 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005165 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005166 }
5167
Nathan Haroldb3014052017-01-25 15:57:32 -08005168 /**
5169 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5170 * on a particular subscription
5171 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005172 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5173 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005175 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005176 return null;
5177 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178
5179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 if (appType != TelephonyManager.APPTYPE_USIM
5182 && appType != TelephonyManager.APPTYPE_SIM) {
5183 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5184 return null;
5185 }
5186 Object response = sendRequest(
5187 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5188 if (response instanceof String[]) {
5189 return (String[]) response;
5190 }
yincheng zhaod698b842019-09-06 17:06:54 -07005191 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005193 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005194 } finally {
5195 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005196 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005197 }
5198
yincheng zhaod698b842019-09-06 17:06:54 -07005199 /**
5200 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5201 * subscription.
5202 *
5203 * @param subId the id of the subscription.
5204 * @param appType the uicc app type, must be USIM or SIM.
5205 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5206 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005207 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005208 * @return number of fplmns that is successfully written to the SIM.
5209 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005210 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5211 String callingFeatureId) {
5212 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5213 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005214 if (DBG) logv("no permissions for setForbiddenplmns");
5215 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5216 }
5217 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5218 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5219 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5220 }
5221 if (fplmns == null) {
5222 throw new IllegalArgumentException("Fplmn List provided is null");
5223 }
5224 for (String fplmn : fplmns) {
5225 if (!CellIdentity.isValidPlmn(fplmn)) {
5226 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5227 }
5228 }
5229 final long identity = Binder.clearCallingIdentity();
5230 try {
5231 Object response = sendRequest(
5232 CMD_SET_FORBIDDEN_PLMNS,
5233 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5234 subId);
5235 return (int) response;
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
5239 }
5240
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005241 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005242 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5244 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 final long identity = Binder.clearCallingIdentity();
5247 try {
5248 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5249 if (response.payload == null) {
5250 return "";
5251 }
Evan Charltonc66da362014-05-16 14:06:40 -07005252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005253 // Append the returned status code to the end of the response payload.
5254 String s = Integer.toHexString(
5255 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5256 s = IccUtils.bytesToHexString(response.payload) + s;
5257 return s;
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Evan Charltonc66da362014-05-16 14:06:40 -07005261 }
5262
Jake Hambye994d462014-02-03 13:10:13 -08005263 /**
5264 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5265 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5266 *
5267 * @param itemID the ID of the item to read
5268 * @return the NV item as a String, or null on error.
5269 */
5270 @Override
5271 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005272 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5274 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275
5276 final long identity = Binder.clearCallingIdentity();
5277 try {
5278 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005279 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5281 return value;
5282 } finally {
5283 Binder.restoreCallingIdentity(identity);
5284 }
Jake Hambye994d462014-02-03 13:10:13 -08005285 }
5286
5287 /**
5288 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5289 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5290 *
5291 * @param itemID the ID of the item to read
5292 * @param itemValue the value to write, as a String
5293 * @return true on success; false on any failure
5294 */
5295 @Override
5296 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005297 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5299 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300
5301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5304 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005305 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5307 return success;
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
5310 }
Jake Hambye994d462014-02-03 13:10:13 -08005311 }
5312
5313 /**
5314 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5315 * Used for device configuration by some CDMA operators.
5316 *
5317 * @param preferredRoamingList byte array containing the new PRL
5318 * @return true on success; false on any failure
5319 */
5320 @Override
5321 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5323 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324
5325 final long identity = Binder.clearCallingIdentity();
5326 try {
5327 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5328 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5329 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5330 return success;
5331 } finally {
5332 Binder.restoreCallingIdentity(identity);
5333 }
Jake Hambye994d462014-02-03 13:10:13 -08005334 }
5335
5336 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005337 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005338 * Used for device configuration by some CDMA operators.
5339 *
chen xu6dac5ab2018-10-26 17:39:23 -07005340 * @param slotIndex - device slot.
5341 *
Jake Hambye994d462014-02-03 13:10:13 -08005342 * @return true on success; false on any failure
5343 */
5344 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005345 public boolean resetModemConfig(int slotIndex) {
5346 Phone phone = PhoneFactory.getPhone(slotIndex);
5347 if (phone != null) {
5348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5349 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350
chen xu6dac5ab2018-10-26 17:39:23 -07005351 final long identity = Binder.clearCallingIdentity();
5352 try {
5353 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5354 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5355 return success;
5356 } finally {
5357 Binder.restoreCallingIdentity(identity);
5358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 }
chen xu6dac5ab2018-10-26 17:39:23 -07005360 return false;
5361 }
5362
5363 /**
5364 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5365 *
5366 * @param slotIndex - device slot.
5367 *
5368 * @return true on success; false on any failure
5369 */
5370 @Override
5371 public boolean rebootModem(int slotIndex) {
5372 Phone phone = PhoneFactory.getPhone(slotIndex);
5373 if (phone != null) {
5374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5375 mApp, phone.getSubId(), "rebootModem");
5376
5377 final long identity = Binder.clearCallingIdentity();
5378 try {
5379 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5380 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5381 return success;
5382 } finally {
5383 Binder.restoreCallingIdentity(identity);
5384 }
5385 }
5386 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005387 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005388
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005389 public String[] getPcscfAddress(String apnType, String callingPackage,
5390 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005391 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005392 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5393 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005394 return new String[0];
5395 }
5396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 final long identity = Binder.clearCallingIdentity();
5398 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005399 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 } finally {
5401 Binder.restoreCallingIdentity(identity);
5402 }
Wink Saville36469e72014-06-11 15:17:00 -07005403 }
5404
Brad Ebinger51f743a2017-01-23 13:50:20 -08005405 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005406 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5407 * {@link #disableIms(int)}.
5408 * @param slotIndex device slot.
5409 */
5410 public void resetIms(int slotIndex) {
5411 enforceModifyPermission();
5412
5413 final long identity = Binder.clearCallingIdentity();
5414 try {
5415 if (mImsResolver == null) {
5416 // may happen if the does not support IMS.
5417 return;
5418 }
5419 mImsResolver.disableIms(slotIndex);
5420 mImsResolver.enableIms(slotIndex);
5421 } finally {
5422 Binder.restoreCallingIdentity(identity);
5423 }
5424 }
5425
5426 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005427 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5428 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005429 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005430 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432
5433 final long identity = Binder.clearCallingIdentity();
5434 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005435 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005436 // may happen if the device does not support IMS.
5437 return;
5438 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005439 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440 } finally {
5441 Binder.restoreCallingIdentity(identity);
5442 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005443 }
5444
5445 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005446 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5447 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005448 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005449 public void disableIms(int slotId) {
5450 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451
5452 final long identity = Binder.clearCallingIdentity();
5453 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005454 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005455 // may happen if the device does not support IMS.
5456 return;
5457 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005458 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005462 }
5463
5464 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005465 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5466 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005467 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005468 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005469 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005470 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471
5472 final long identity = Binder.clearCallingIdentity();
5473 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005474 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005475 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5476 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005477 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005478 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479 } finally {
5480 Binder.restoreCallingIdentity(identity);
5481 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005482 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005483 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005484 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5485 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005486 @Override
5487 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005488 enforceModifyPermission();
5489
5490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005493 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005494 } finally {
5495 Binder.restoreCallingIdentity(identity);
5496 }
5497 }
5498
5499 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005500 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005501 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005502 */
5503 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505
5506 final long identity = Binder.clearCallingIdentity();
5507 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005508 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005509 // may happen if the device does not support IMS.
5510 return null;
5511 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005512 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 } finally {
5514 Binder.restoreCallingIdentity(identity);
5515 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005516 }
5517
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005518 /**
5519 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005520 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005521 */
5522 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5523 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524
5525 final long identity = Binder.clearCallingIdentity();
5526 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005527 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005528 // may happen if the device does not support IMS.
5529 return null;
5530 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005531 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 } finally {
5533 Binder.restoreCallingIdentity(identity);
5534 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005535 }
5536
Brad Ebinger884c07b2018-02-15 16:17:40 -08005537 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005538 * Sets the ImsService Package Name that Telephony will bind to.
5539 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005540 * @param slotIndex the slot ID that the ImsService should bind for.
5541 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005542 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005543 * @param featureTypes An integer array of feature types associated with a packageName.
5544 * @param packageName The name of the package that the current configuration will be replaced
5545 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005546 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005547 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005548 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5549 int[] featureTypes, String packageName) {
5550 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5551 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5553 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005554 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556 final long identity = Binder.clearCallingIdentity();
5557 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005558 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005559 // may happen if the device does not support IMS.
5560 return false;
5561 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005562 Map<Integer, String> featureConfig = new HashMap<>();
5563 for (int featureType : featureTypes) {
5564 featureConfig.put(featureType, packageName);
5565 }
5566 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5567 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005571 }
5572
5573 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005574 * Clears any carrier ImsService overrides for the slot index specified that were previously
5575 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5576 *
5577 * This should only be used for testing.
5578 *
5579 * @param slotIndex the slot ID that the ImsService should bind for.
5580 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5581 */
5582 @Override
5583 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5584 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5585 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5586 "clearCarrierImsServiceOverride");
5587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5588 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5589 "clearCarrierImsServiceOverride");
5590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
5593 if (mImsResolver == null) {
5594 // may happen if the device does not support IMS.
5595 return false;
5596 }
5597 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
5601 }
5602
5603 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005604 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005605 *
5606 * @param slotId The slot that the ImsService is associated with.
5607 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5608 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005609 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005610 * @return the package name of the ImsService configuration.
5611 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005612 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5613 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005614 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005615 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005616 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005617 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5618 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 final long identity = Binder.clearCallingIdentity();
5621 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005622 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005623 // may happen if the device does not support IMS.
5624 return "";
5625 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005626 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005627 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5628 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 } finally {
5630 Binder.restoreCallingIdentity(identity);
5631 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005632 }
5633
Brad Ebinger77b832e2019-10-17 17:03:22 -07005634 /**
5635 * Get the MmTelFeature state associated with the requested subscription id.
5636 * @param subId The subscription that the MmTelFeature is associated with.
5637 * @param callback A callback with an integer containing the
5638 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5639 */
5640 @Override
5641 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5642 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5643 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5644 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5645 "IMS not available on device.");
5646 }
5647 final long token = Binder.clearCallingIdentity();
5648 try {
5649 int slotId = getSlotIndex(subId);
5650 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5651 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5652 + subId + "'");
5653 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5654 }
5655 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5656 try {
5657 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5658 } catch (RemoteException e) {
5659 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5660 + "Ignore");
5661 }
5662 });
5663 } finally {
5664 Binder.restoreCallingIdentity(token);
5665 }
5666 }
5667
Daniel Brightbb5840b2021-01-12 15:48:18 -08005668 /**
5669 * Sets the ims registration state on all valid {@link Phone}s.
5670 */
5671 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005672 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005676 // NOTE: Before S, this method only set the default phone.
5677 for (final Phone phone : PhoneFactory.getPhones()) {
5678 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5679 phone.setImsRegistrationState(registered);
5680 }
5681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
Wink Saville36469e72014-06-11 15:17:00 -07005685 }
5686
5687 /**
Stuart Scott54788802015-03-30 13:18:01 -07005688 * Set the network selection mode to automatic.
5689 *
5690 */
5691 @Override
5692 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5694 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695
5696 final long identity = Binder.clearCallingIdentity();
5697 try {
shilufc958392020-01-20 11:36:01 -08005698 if (!isActiveSubscription(subId)) {
5699 return;
5700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005702 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5703 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
Stuart Scott54788802015-03-30 13:18:01 -07005707 }
5708
Jack Yud10cdd42020-09-28 20:28:01 -07005709 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005710 * Ask the radio to connect to the input network and change selection mode to manual.
5711 *
5712 * @param subId the id of the subscription.
5713 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5714 * the operator to attach to.
5715 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5716 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5717 * normal network selection next time.
5718 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005719 */
5720 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005721 public boolean setNetworkSelectionModeManual(
5722 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5724 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005725
5726 if (!isActiveSubscription(subId)) {
5727 return false;
5728 }
5729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 final long identity = Binder.clearCallingIdentity();
5731 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005732 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005734 if (DBG) {
5735 log("setNetworkSelectionModeManual: subId: " + subId
5736 + " operator: " + operatorInfo);
5737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005742 }
shilu84f6e8b2019-12-19 13:58:01 -08005743 /**
5744 * Get the manual network selection
5745 *
5746 * @param subId the id of the subscription.
5747 *
5748 * @return the previously saved user selected PLMN
5749 */
5750 @Override
5751 public String getManualNetworkSelectionPlmn(int subId) {
5752 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005753 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005754 mApp, subId, "getManualNetworkSelectionPlmn");
5755
5756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 if (!isActiveSubscription(subId)) {
5759 return "";
5760 }
5761
5762 final Phone phone = getPhone(subId);
5763 if (phone == null) {
5764 return "";
5765 }
5766 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5767 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5768 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
5772 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005773
5774 /**
5775 * Scans for available networks.
5776 */
5777 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005778 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5779 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5781 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005782 LocationAccessPolicy.LocationPermissionResult locationResult =
5783 LocationAccessPolicy.checkLocationPermission(mApp,
5784 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5785 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005786 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005787 .setCallingPid(Binder.getCallingPid())
5788 .setCallingUid(Binder.getCallingUid())
5789 .setMethod("getCellNetworkScanResults")
5790 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07005791 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5792 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005793 .build());
5794 switch (locationResult) {
5795 case DENIED_HARD:
5796 throw new SecurityException("Not allowed to access scan results -- location");
5797 case DENIED_SOFT:
5798 return null;
5799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800
Pengquan Menga1bb6272018-09-06 09:59:22 -07005801 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005802 try {
5803 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005804 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005809 }
5810
5811 /**
sqian80370722020-01-29 15:02:51 -08005812 * Get the call forwarding info, given the call forwarding reason.
5813 */
5814 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005815 public void getCallForwarding(int subId, int callForwardingReason,
5816 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005817 enforceReadPrivilegedPermission("getCallForwarding");
5818 long identity = Binder.clearCallingIdentity();
5819 try {
5820 if (DBG) {
5821 log("getCallForwarding: subId " + subId
5822 + " callForwardingReason" + callForwardingReason);
5823 }
Hall Liua1acea22020-09-18 19:04:59 -07005824
5825 Phone phone = getPhone(subId);
5826 if (phone == null) {
5827 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005828 callback.onError(
5829 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005830 } catch (RemoteException e) {
5831 // ignore
5832 }
5833 return;
5834 }
5835
5836 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5837 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5838 @Override
5839 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5840 try {
5841 callback.onCallForwardingInfoAvailable(info);
5842 } catch (RemoteException e) {
5843 // ignore
5844 }
5845 }
5846
5847 @Override
5848 public void onError(int error) {
5849 try {
5850 callback.onError(error);
5851 } catch (RemoteException e) {
5852 // ignore
5853 }
5854 }
5855 });
5856 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
5860 }
5861
5862 /**
5863 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5864 * reason, the number to forward, and the timeout before the forwarding is attempted.
5865 */
5866 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005867 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5868 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005869 enforceModifyPermission();
5870 long identity = Binder.clearCallingIdentity();
5871 try {
5872 if (DBG) {
5873 log("setCallForwarding: subId " + subId
5874 + " callForwardingInfo" + callForwardingInfo);
5875 }
Hall Liua1acea22020-09-18 19:04:59 -07005876
5877 Phone phone = getPhone(subId);
5878 if (phone == null) {
5879 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005880 callback.accept(
5881 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005882 } catch (RemoteException e) {
5883 // ignore
5884 }
5885 return;
5886 }
5887
5888 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5889 FunctionalUtils.ignoreRemoteException(callback::accept));
5890
5891 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005892 } finally {
5893 Binder.restoreCallingIdentity(identity);
5894 }
5895 }
5896
5897 /**
Hall Liua1acea22020-09-18 19:04:59 -07005898 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005899 */
5900 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005901 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWangc63cf522021-03-31 22:08:45 +08005902 enforceReadPrivilegedPermission("getCallWaitingStatus");
sqian80370722020-01-29 15:02:51 -08005903 long identity = Binder.clearCallingIdentity();
5904 try {
Hall Liua1acea22020-09-18 19:04:59 -07005905 Phone phone = getPhone(subId);
5906 if (phone == null) {
5907 try {
5908 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5909 } catch (RemoteException e) {
5910 // ignore
5911 }
5912 return;
5913 }
SongFerngWangc63cf522021-03-31 22:08:45 +08005914 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5915 PersistableBundle c = configManager.getConfigForSubId(subId);
5916 boolean requireUssd = c.getBoolean(
5917 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005918
sqian80370722020-01-29 15:02:51 -08005919 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWangc63cf522021-03-31 22:08:45 +08005920 if (requireUssd) {
5921 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5922 getSubscriptionCarrierId(subId));
5923 String newUssdCommand = "";
5924 try {
5925 newUssdCommand = carrierXmlParser.getFeature(
5926 CarrierXmlParser.FEATURE_CALL_WAITING)
5927 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
5928 } catch (NullPointerException e) {
5929 loge("Failed to generate USSD number" + e);
5930 }
5931 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5932 mMainThreadHandler, callback, carrierXmlParser,
5933 CarrierXmlParser.SsEntry.SSAction.QUERY);
5934 final String ussdCommand = newUssdCommand;
5935 Executors.newSingleThreadExecutor().execute(() -> {
5936 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5937 });
5938 } else {
5939 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
5940 callback::accept);
5941 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
5942 }
sqian80370722020-01-29 15:02:51 -08005943 } finally {
5944 Binder.restoreCallingIdentity(identity);
5945 }
5946 }
5947
5948 /**
Hall Liua1acea22020-09-18 19:04:59 -07005949 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005950 */
5951 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005952 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005953 enforceModifyPermission();
5954 long identity = Binder.clearCallingIdentity();
5955 try {
Hall Liua1acea22020-09-18 19:04:59 -07005956 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5957
5958 Phone phone = getPhone(subId);
5959 if (phone == null) {
5960 try {
5961 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5962 } catch (RemoteException e) {
5963 // ignore
5964 }
5965 return;
5966 }
5967
SongFerngWangc63cf522021-03-31 22:08:45 +08005968 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5969 PersistableBundle c = configManager.getConfigForSubId(subId);
5970 boolean requireUssd = c.getBoolean(
5971 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005972
SongFerngWangc63cf522021-03-31 22:08:45 +08005973 if (DBG) log("getCallWaitingStatus: subId " + subId);
5974 if (requireUssd) {
5975 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5976 getSubscriptionCarrierId(subId));
5977 CarrierXmlParser.SsEntry.SSAction ssAction =
5978 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
5979 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
5980 String newUssdCommand = "";
5981 try {
5982 newUssdCommand = carrierXmlParser.getFeature(
5983 CarrierXmlParser.FEATURE_CALL_WAITING)
5984 .makeCommand(ssAction, null);
5985 } catch (NullPointerException e) {
5986 loge("Failed to generate USSD number" + e);
5987 }
5988 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5989 mMainThreadHandler, callback, carrierXmlParser, ssAction);
5990 final String ussdCommand = newUssdCommand;
5991 Executors.newSingleThreadExecutor().execute(() -> {
5992 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5993 });
5994 } else {
5995 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5996 FunctionalUtils.ignoreRemoteException(callback::accept));
5997
5998 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
5999 }
sqian80370722020-01-29 15:02:51 -08006000 } finally {
6001 Binder.restoreCallingIdentity(identity);
6002 }
6003 }
6004
6005 /**
yinxub1bed742017-04-17 11:45:04 -07006006 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006007 *
yinxub1bed742017-04-17 11:45:04 -07006008 * @param subId id of the subscription
6009 * @param request contains the radio access networks with bands/channels to scan
6010 * @param messenger callback messenger for scan results or errors
6011 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006012 * @return the id of the requested scan which can be used to stop the scan.
6013 */
6014 @Override
6015 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006016 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6018 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006019 LocationAccessPolicy.LocationPermissionResult locationResult =
6020 LocationAccessPolicy.checkLocationPermission(mApp,
6021 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6022 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006023 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006024 .setCallingPid(Binder.getCallingPid())
6025 .setCallingUid(Binder.getCallingUid())
6026 .setMethod("requestNetworkScan")
6027 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6028 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006029 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07006030 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6031 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006032 if (e != null) {
6033 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6034 throw e;
6035 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006036 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006037 return TelephonyScanManager.INVALID_SCAN_ID;
6038 }
6039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 }
Hall Liu912dfd32019-04-25 14:02:26 -07006041 int callingUid = Binder.getCallingUid();
6042 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006043 final long identity = Binder.clearCallingIdentity();
6044 try {
6045 return mNetworkScanRequestTracker.startNetworkScan(
6046 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006047 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006048 } finally {
6049 Binder.restoreCallingIdentity(identity);
6050 }
yinxu504e1392017-04-12 16:03:22 -07006051 }
6052
Hall Liub2ac8ef2019-02-28 15:56:23 -08006053 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07006054 NetworkScanRequest request, int subId, String callingPackage) {
6055 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006056 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6057 boolean hasNetworkScanPermission =
6058 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6059 == PERMISSION_GRANTED;
6060
6061 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6062 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6063 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006064 }
6065
6066 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6067 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006068 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6069 return new SecurityException("Specific channels must not be"
6070 + " scanned without location access.");
6071 }
6072 }
6073 }
6074
Hall Liub2ac8ef2019-02-28 15:56:23 -08006075 return null;
6076 }
6077
yinxu504e1392017-04-12 16:03:22 -07006078 /**
6079 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006080 *
6081 * @param subId id of the subscription
6082 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006083 */
6084 @Override
6085 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6087 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088
Hall Liu912dfd32019-04-25 14:02:26 -07006089 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 final long identity = Binder.clearCallingIdentity();
6091 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006092 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 } finally {
6094 Binder.restoreCallingIdentity(identity);
6095 }
yinxu504e1392017-04-12 16:03:22 -07006096 }
6097
6098 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006099 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006100 *
SongFerngWang9e060372020-12-21 16:41:52 +08006101 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006102 */
6103 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006104 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006105 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006106 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006107 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108
6109 final long identity = Binder.clearCallingIdentity();
6110 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006111 if (DBG) log("getAllowedNetworkTypesBitmask");
6112 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6113 int networkTypesBitmask = (result != null ? result[0] : -1);
6114 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6115 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 } finally {
6117 Binder.restoreCallingIdentity(identity);
6118 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006119 }
6120
6121 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006122 * Get the allowed network types for certain reason.
6123 *
6124 * @param subId the id of the subscription.
6125 * @param reason the reason the allowed network type change is taking place
6126 * @return the allowed network types.
6127 */
6128 @Override
6129 public long getAllowedNetworkTypesForReason(int subId,
6130 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006131 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006132 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006133 final long identity = Binder.clearCallingIdentity();
6134 try {
6135 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
6139 }
6140
6141 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006142 * Enable/Disable E-UTRA-NR Dual Connectivity
6143 * @param subId subscription id of the sim card
6144 * @param nrDualConnectivityState expected NR dual connectivity state
6145 * This can be passed following states
6146 * <ol>
6147 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6148 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6149 * <li>Disable NR dual connectivity and force secondary cell to be released
6150 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6151 * </ol>
6152 * @return operation result.
6153 */
6154 @Override
6155 public int setNrDualConnectivityState(int subId,
6156 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6158 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006159 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006160 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6161 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6162 }
6163
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006164 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6165 final long identity = Binder.clearCallingIdentity();
6166 try {
6167 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6168 nrDualConnectivityState, subId,
6169 workSource);
6170 if (DBG) log("enableNRDualConnectivity result: " + result);
6171 return result;
6172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
6175 }
6176
6177 /**
6178 * Is E-UTRA-NR Dual Connectivity enabled
6179 * @return true if dual connectivity is enabled else false
6180 */
6181 @Override
6182 public boolean isNrDualConnectivityEnabled(int subId) {
6183 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006184 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006185 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006186 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006187 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6188 return false;
6189 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006190 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6191 final long identity = Binder.clearCallingIdentity();
6192 try {
6193 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6194 null, subId, workSource);
6195 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6196 return isEnabled;
6197 } finally {
6198 Binder.restoreCallingIdentity(identity);
6199 }
6200 }
6201
6202 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006203 * Set the allowed network types of the device and
6204 * provide the reason triggering the allowed network change.
6205 *
6206 * @param subId the id of the subscription.
6207 * @param reason the reason the allowed network type change is taking place
6208 * @param allowedNetworkTypes the allowed network types.
6209 * @return true on success; false on any failure.
6210 */
6211 @Override
6212 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006213 @TelephonyManager.AllowedNetworkTypesReason int reason,
6214 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6216 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006217 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWangc2d3ccc2021-04-15 19:46:33 +08006218 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6219 return false;
6220 }
6221 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6222 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang9e060372020-12-21 16:41:52 +08006223 return false;
6224 }
6225
SongFerngWang522637d2021-03-02 22:09:29 +08006226 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6227 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6228
6229
6230 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6231 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6232 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006233 }
SongFerngWang522637d2021-03-02 22:09:29 +08006234
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006235 final long identity = Binder.clearCallingIdentity();
6236 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006237 Boolean success = (Boolean) sendRequest(
6238 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6239 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6240
6241 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6242 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006243 } finally {
6244 Binder.restoreCallingIdentity(identity);
6245 }
6246 }
6247
6248 /**
Miaoa84611c2019-03-15 09:21:10 +08006249 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006250 *
Miaoa84611c2019-03-15 09:21:10 +08006251 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006252 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006253 * @hide
6254 */
6255 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006256 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006257 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006259 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 try {
Miaoa84611c2019-03-15 09:21:10 +08006261 if (phone != null) {
6262 return phone.hasMatchedTetherApnSetting();
6263 } else {
6264 return false;
6265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 } finally {
6267 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006268 }
Junda Liu475951f2014-11-07 16:45:03 -08006269 }
6270
6271 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006272 * Enable or disable always reporting signal strength changes from radio.
6273 *
6274 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6275 */
6276 @Override
6277 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6278 enforceModifyPermission();
6279 enforceSystemCaller();
6280
6281 final long identity = Binder.clearCallingIdentity();
6282 final Phone phone = getPhone(subId);
6283 try {
6284 if (phone != null) {
6285 if (DBG) {
6286 log("setAlwaysReportSignalStrength: subId=" + subId
6287 + " isEnable=" + isEnable);
6288 }
6289 phone.setAlwaysReportSignalStrength(isEnable);
6290 } else {
6291 loge("setAlwaysReportSignalStrength: no phone found for subId="
6292 + subId);
6293 }
6294 } finally {
6295 Binder.restoreCallingIdentity(identity);
6296 }
6297 }
6298
6299 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006300 * Get the user enabled state of Mobile Data.
6301 *
6302 * TODO: remove and use isUserDataEnabled.
6303 * This can't be removed now because some vendor codes
6304 * calls through ITelephony directly while they should
6305 * use TelephonyManager.
6306 *
6307 * @return true on enabled
6308 */
6309 @Override
6310 public boolean getDataEnabled(int subId) {
6311 return isUserDataEnabled(subId);
6312 }
6313
6314 /**
6315 * Get whether mobile data is enabled per user setting.
6316 *
6317 * There are other factors deciding whether mobile data is actually enabled, but they are
6318 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006319 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006320 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006321 *
6322 * @return {@code true} if data is enabled else {@code false}
6323 */
6324 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006325 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006326 try {
6327 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6328 null);
6329 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6331 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333
6334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 int phoneId = mSubscriptionController.getPhoneId(subId);
6337 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6338 Phone phone = PhoneFactory.getPhone(phoneId);
6339 if (phone != null) {
6340 boolean retVal = phone.isUserDataEnabled();
6341 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6342 return retVal;
6343 } else {
6344 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6345 return false;
6346 }
6347 } finally {
6348 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006349 }
6350 }
6351
6352 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006353 * Checks if the device is capable of mobile data by considering whether whether the
6354 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6355 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006356 *
Shuo Qian985d1232020-01-08 14:30:06 -08006357 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006358 */
6359 @Override
6360 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006361 try {
6362 try {
6363 mApp.enforceCallingOrSelfPermission(
6364 android.Manifest.permission.ACCESS_NETWORK_STATE,
6365 null);
6366 } catch (Exception e) {
6367 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6368 "isDataEnabled");
6369 }
6370 } catch (Exception e) {
6371 enforceReadPrivilegedPermission("isDataEnabled");
6372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373
6374 final long identity = Binder.clearCallingIdentity();
6375 try {
6376 int phoneId = mSubscriptionController.getPhoneId(subId);
6377 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6378 Phone phone = PhoneFactory.getPhone(phoneId);
6379 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006380 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6382 return retVal;
6383 } else {
6384 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6385 return false;
6386 }
6387 } finally {
6388 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006389 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006390 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006391
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006392 /**
6393 * Check if data is enabled for a specific reason
6394 * @param subId Subscription index
6395 * @param reason the reason the data enable change is taking place
6396 * @return {@code true} if the overall data is enabled; {@code false} if not.
6397 */
6398 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006399 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006400 @TelephonyManager.DataEnabledReason int reason) {
6401 try {
6402 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6403 null);
6404 } catch (Exception e) {
6405 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006406 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006407 }
6408
6409
6410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 int phoneId = mSubscriptionController.getPhoneId(subId);
6413 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006414 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006415 + " reason=" + reason);
6416 }
6417 Phone phone = PhoneFactory.getPhone(phoneId);
6418 if (phone != null) {
6419 boolean retVal;
6420 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6421 retVal = phone.isUserDataEnabled();
6422 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006423 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006424 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006425 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006426 return retVal;
6427 } else {
6428 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006429 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006430 + subId + " retVal=false");
6431 }
6432 return false;
6433 }
6434 } finally {
6435 Binder.restoreCallingIdentity(identity);
6436 }
6437 }
6438
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006439 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006440 Phone phone) {
Sarah Chinca45c312021-04-09 10:37:15 -07006441 if (uid == Process.PHONE_UID) {
6442 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6443 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liuce478d22020-07-13 12:13:03 -07006444 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6445 }
6446
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006447 //load access rules from carrier configs, and check those as well: b/139133814
6448 SubscriptionController subController = SubscriptionController.getInstance();
6449 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6450 || subController == null) return privilegeFromSim;
6451
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006452 PackageManager pkgMgr = phone.getContext().getPackageManager();
6453 String[] packages = pkgMgr.getPackagesForUid(uid);
6454
6455 final long identity = Binder.clearCallingIdentity();
6456 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006457 int subId = phone.getSubId();
6458 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6459 // A test override is in place for the privileges for this subId, so don't try to
6460 // read the subscription privileges.
6461 return privilegeFromSim;
6462 }
6463 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006464 SubscriptionManager subManager = (SubscriptionManager)
6465 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6466 for (String pkg : packages) {
6467 if (subManager.canManageSubscription(subInfo, pkg)) {
6468 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6469 }
6470 }
6471 return privilegeFromSim;
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
6475 }
6476
6477 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6478 String pkgName) {
6479 //load access rules from carrier configs, and check those as well: b/139133814
6480 SubscriptionController subController = SubscriptionController.getInstance();
6481 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6482 || subController == null) return privilegeFromSim;
6483
6484 final long identity = Binder.clearCallingIdentity();
6485 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006486 int subId = phone.getSubId();
6487 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6488 // A test override is in place for the privileges for this subId, so don't try to
6489 // read the subscription privileges.
6490 return privilegeFromSim;
6491 }
6492 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006493 SubscriptionManager subManager = (SubscriptionManager)
6494 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6495 return subManager.canManageSubscription(subInfo, pkgName)
6496 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
6500 }
6501
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006502 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006503 public int getCarrierPrivilegeStatus(int subId) {
6504 final Phone phone = getPhone(subId);
6505 if (phone == null) {
6506 loge("getCarrierPrivilegeStatus: Invalid subId");
6507 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6508 }
6509 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006510 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006511 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006512 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6513 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006514
6515 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6516 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006517 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006518 }
Junda Liu29340342014-07-10 15:23:27 -07006519
6520 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006521 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006522 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006523 final Phone phone = getPhone(subId);
6524 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006525 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006526 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6527 }
6528 UiccProfile profile =
6529 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6530 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006531 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006532 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6533 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006534 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006535 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006536 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006537 }
6538
6539 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006540 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6541 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006542 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006543 }
6544
6545 int phoneId = SubscriptionManager.getPhoneId(subId);
6546 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006547 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006548 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006549 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6550 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006551 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6552 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6553 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006554 }
6555
6556 @Override
6557 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006558 if (TextUtils.isEmpty(pkgName))
6559 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006560 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6561 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6562 UiccCard card = UiccController.getInstance().getUiccCard(i);
6563 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006564 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006565 continue;
6566 }
6567
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006568 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6569 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6570 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006571 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6572 break;
6573 }
6574 }
6575
6576 return result;
Junda Liu29340342014-07-10 15:23:27 -07006577 }
Derek Tan89e89d42014-07-08 17:00:10 -07006578
6579 @Override
Junda Liue64de782015-04-16 17:19:16 -07006580 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6581 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6582 loge("phoneId " + phoneId + " is not valid.");
6583 return null;
6584 }
6585 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006586 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006587 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006588 return null ;
6589 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006590 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006591 }
6592
Amith Yamasani6e118872016-02-19 12:53:51 -08006593 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006594 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006595 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006596 List<String> privilegedPackages = new ArrayList<>();
6597 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006598 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6599 // has UICC in that slot.
6600 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006601 if (card.hasCarrierPrivilegeRules()) {
6602 if (packages == null) {
6603 // Only check packages in user 0 for now
6604 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006605 PackageManager.MATCH_DISABLED_COMPONENTS
6606 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006607 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006608 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006609 }
6610 for (int p = packages.size() - 1; p >= 0; p--) {
6611 PackageInfo pkgInfo = packages.get(p);
6612 if (pkgInfo != null && pkgInfo.packageName != null
6613 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006614 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006615 privilegedPackages.add(pkgInfo.packageName);
6616 }
6617 }
6618 }
6619 }
6620 return privilegedPackages;
6621 }
6622
chen xuf7e9fe82019-05-09 19:31:02 -07006623 @Override
6624 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006625 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6626
6627 final long identity = Binder.clearCallingIdentity();
6628
chen xuf7e9fe82019-05-09 19:31:02 -07006629 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006630 try {
6631 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6632 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6633 }
6634 } finally {
6635 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006636 }
6637 return privilegedPackages;
6638 }
6639
Wink Savilleb564aae2014-10-23 10:18:09 -07006640 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006641 final Phone phone = getPhone(subId);
6642 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006643 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006644 return null;
6645 }
6646 String iccId = card.getIccId();
6647 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006648 return null;
6649 }
6650 return iccId;
6651 }
6652
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006653 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006654 public void setCallComposerStatus(int subId, int status) {
6655 enforceModifyPermission();
6656
6657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 Phone phone = getPhone(subId);
6660 if (phone != null) {
6661 Phone defaultPhone = phone.getImsPhone();
6662 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6663 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6664 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006665 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6666 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006667 }
6668 }
Shuo Qiand8782462020-12-22 19:10:14 -08006669 } catch (ImsException e) {
6670 throw new ServiceSpecificException(e.getCode());
6671 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006672 Binder.restoreCallingIdentity(identity);
6673 }
6674 }
6675
6676 @Override
6677 public int getCallComposerStatus(int subId) {
6678 enforceReadPrivilegedPermission("getCallComposerStatus");
6679
6680 final long identity = Binder.clearCallingIdentity();
6681 try {
6682 Phone phone = getPhone(subId);
6683 if (phone != null) {
6684 Phone defaultPhone = phone.getImsPhone();
6685 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6686 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6687 return imsPhone.getCallComposerStatus();
6688 }
6689 }
6690 } finally {
6691 Binder.restoreCallingIdentity(identity);
6692 }
6693 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6694 }
6695
6696 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006697 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6698 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006699 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006700 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702 final long identity = Binder.clearCallingIdentity();
6703 try {
6704 final String iccId = getIccId(subId);
6705 final Phone phone = getPhone(subId);
6706 if (phone == null) {
6707 return false;
6708 }
6709 final String subscriberId = phone.getSubscriberId();
6710
6711 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006712 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 + subscriberId + " to " + number);
6714 }
6715
6716 if (TextUtils.isEmpty(iccId)) {
6717 return false;
6718 }
6719
6720 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6721
6722 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6723 if (alphaTag == null) {
6724 editor.remove(alphaTagPrefKey);
6725 } else {
6726 editor.putString(alphaTagPrefKey, alphaTag);
6727 }
6728
6729 // Record both the line number and IMSI for this ICCID, since we need to
6730 // track all merged IMSIs based on line number
6731 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6732 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6733 if (number == null) {
6734 editor.remove(numberPrefKey);
6735 editor.remove(subscriberPrefKey);
6736 } else {
6737 editor.putString(numberPrefKey, number);
6738 editor.putString(subscriberPrefKey, subscriberId);
6739 }
6740
6741 editor.commit();
6742 return true;
6743 } finally {
6744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006745 }
Derek Tan7226c842014-07-02 17:42:23 -07006746 }
6747
6748 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006749 public String getLine1NumberForDisplay(int subId, String callingPackage,
6750 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006751 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006752 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006753 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006754 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006755 return null;
6756 }
Derek Tan97ebb422014-09-05 16:55:38 -07006757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 final long identity = Binder.clearCallingIdentity();
6759 try {
6760 String iccId = getIccId(subId);
6761 if (iccId != null) {
6762 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6763 if (DBG_MERGE) {
6764 log("getLine1NumberForDisplay returning "
6765 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6766 }
6767 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6770 return null;
6771 } finally {
6772 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006773 }
Derek Tan7226c842014-07-02 17:42:23 -07006774 }
6775
6776 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006777 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6778 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006780 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006781 return null;
6782 }
Derek Tan97ebb422014-09-05 16:55:38 -07006783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 final long identity = Binder.clearCallingIdentity();
6785 try {
6786 String iccId = getIccId(subId);
6787 if (iccId != null) {
6788 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6789 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6790 }
6791 return null;
6792 } finally {
6793 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006794 }
Derek Tan7226c842014-07-02 17:42:23 -07006795 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006796
6797 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006798 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6799 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006800 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6801 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006803 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006804 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006805 return null;
6806 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006807
Jordan Liub49b04b2019-05-06 14:45:15 -07006808 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6809 // the process, where TelephonyManager was instantiated.
6810 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006811 final long identity = Binder.clearCallingIdentity();
6812 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006813 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814 final TelephonyManager tele = TelephonyManager.from(context);
6815 final SubscriptionManager sub = SubscriptionManager.from(context);
6816
6817 // Figure out what subscribers are currently active
6818 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819
Jordan Liub49b04b2019-05-06 14:45:15 -07006820 // Only consider subs which match the current subId
6821 // This logic can be simplified. See b/131189269 for progress.
6822 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006823 activeSubscriberIds.add(tele.getSubscriberId(subId));
6824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825
6826 // First pass, find a number override for an active subscriber
6827 String mergeNumber = null;
6828 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6829 for (String key : prefs.keySet()) {
6830 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6831 final String subscriberId = (String) prefs.get(key);
6832 if (activeSubscriberIds.contains(subscriberId)) {
6833 final String iccId = key.substring(
6834 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6835 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6836 mergeNumber = (String) prefs.get(numberKey);
6837 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006838 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 + " for active subscriber " + subscriberId);
6840 }
6841 if (!TextUtils.isEmpty(mergeNumber)) {
6842 break;
6843 }
6844 }
6845 }
6846 }
6847
6848 // Shortcut when no active merged subscribers
6849 if (TextUtils.isEmpty(mergeNumber)) {
6850 return null;
6851 }
6852
6853 // Second pass, find all subscribers under that line override
6854 final ArraySet<String> result = new ArraySet<>();
6855 for (String key : prefs.keySet()) {
6856 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6857 final String number = (String) prefs.get(key);
6858 if (mergeNumber.equals(number)) {
6859 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6860 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6861 final String subscriberId = (String) prefs.get(subscriberKey);
6862 if (!TextUtils.isEmpty(subscriberId)) {
6863 result.add(subscriberId);
6864 }
6865 }
6866 }
6867 }
6868
6869 final String[] resultArray = result.toArray(new String[result.size()]);
6870 Arrays.sort(resultArray);
6871 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006872 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6874 }
6875 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006876 } finally {
6877 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006878 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006879 }
6880
6881 @Override
zoey chen38003472019-12-13 17:16:31 +08006882 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6883 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006884
6885 final long identity = Binder.clearCallingIdentity();
6886 try {
6887 final TelephonyManager telephonyManager = mApp.getSystemService(
6888 TelephonyManager.class);
6889 String subscriberId = telephonyManager.getSubscriberId(subId);
6890 if (subscriberId == null) {
6891 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006892 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006893 + subId);
6894 }
6895 return null;
6896 }
6897
6898 final SubscriptionInfo info = SubscriptionController.getInstance()
6899 .getSubscriptionInfo(subId);
6900 final ParcelUuid groupUuid = info.getGroupUuid();
6901 // If it doesn't belong to any group, return just subscriberId of itself.
6902 if (groupUuid == null) {
6903 return new String[]{subscriberId};
6904 }
6905
6906 // Get all subscriberIds from the group.
6907 final List<String> mergedSubscriberIds = new ArrayList<>();
6908 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006909 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006910 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006911 for (SubscriptionInfo subInfo : groupInfos) {
6912 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6913 if (subscriberId != null) {
6914 mergedSubscriberIds.add(subscriberId);
6915 }
6916 }
6917
6918 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6919 } finally {
6920 Binder.restoreCallingIdentity(identity);
6921
6922 }
6923 }
6924
6925 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006926 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006927 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006928 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929
6930 final long identity = Binder.clearCallingIdentity();
6931 try {
6932 final Phone phone = getPhone(subId);
6933 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6934 } finally {
6935 Binder.restoreCallingIdentity(identity);
6936 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006937 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006938
6939 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006940 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006941 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6942 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006943 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6944 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945
6946 final long identity = Binder.clearCallingIdentity();
6947 try {
6948 final Phone phone = getPhone(subId);
6949 if (phone == null) {
6950 return false;
6951 }
6952 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6953 cdmaNonRoamingList);
6954 } finally {
6955 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006956 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006957 }
6958
6959 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006960 @Deprecated
6961 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6962 enforceModifyPermission();
6963
6964 int returnValue = 0;
6965 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006966 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006967 if(result.exception == null) {
6968 if (result.result != null) {
6969 byte[] responseData = (byte[])(result.result);
6970 if(responseData.length > oemResp.length) {
6971 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6972 responseData.length + "bytes. Buffer Size is " +
6973 oemResp.length + "bytes.");
6974 }
6975 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6976 returnValue = responseData.length;
6977 }
6978 } else {
6979 CommandException ex = (CommandException) result.exception;
6980 returnValue = ex.getCommandError().ordinal();
6981 if(returnValue > 0) returnValue *= -1;
6982 }
6983 } catch (RuntimeException e) {
6984 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6985 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6986 if(returnValue > 0) returnValue *= -1;
6987 }
6988
6989 return returnValue;
6990 }
6991
6992 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006993 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006994 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006995 try {
6996 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006997 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07006998 mApp, phone.getSubId(), "getRadioAccessFamily");
6999 } catch (SecurityException e) {
7000 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7001 throw e;
7002 }
chen xub97461a2018-10-26 14:17:57 -07007003 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007004 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007005 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 final long identity = Binder.clearCallingIdentity();
7008 try {
chen xub97461a2018-10-26 14:17:57 -07007009 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007010 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007011 mApp, phone.getSubId(), "getRadioAccessFamily");
7012 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013 } finally {
7014 Binder.restoreCallingIdentity(identity);
7015 }
chen xub97461a2018-10-26 14:17:57 -07007016 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007017 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007018
7019 @Override
7020 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007021 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007022 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023
7024 final long identity = Binder.clearCallingIdentity();
7025 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007026 ImsManager.getInstance(defaultPhone.getContext(),
7027 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028 } finally {
7029 Binder.restoreCallingIdentity(identity);
7030 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007031 }
7032
7033 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007034 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007035 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007036 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7037 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007038 return false;
7039 }
Svet Ganovb320e182015-04-16 12:30:10 -07007040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 final long identity = Binder.clearCallingIdentity();
7042 try {
7043 // Check the user preference and the system-level IMS setting. Even if the user has
7044 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7045 // In the long run, we may instead need to check if there exists a connection service
7046 // which can support video calling.
7047 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007048 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 return imsManager.isVtEnabledByPlatform()
7050 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7051 && imsManager.isVtEnabledByUser();
7052 } finally {
7053 Binder.restoreCallingIdentity(identity);
7054 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007055 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007056
Andrew Leea1239f22015-03-02 17:44:07 -08007057 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007058 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7059 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007061 mApp, subId, callingPackage, callingFeatureId,
7062 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 return false;
7064 }
7065
7066 final long identity = Binder.clearCallingIdentity();
7067 try {
7068 CarrierConfigManager configManager =
7069 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007070 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7072 } finally {
7073 Binder.restoreCallingIdentity(identity);
7074 }
Andrew Leea1239f22015-03-02 17:44:07 -08007075 }
7076
7077 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007078 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007080 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 return false;
7082 }
7083
7084 final long identity = Binder.clearCallingIdentity();
7085 try {
7086 CarrierConfigManager configManager =
7087 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007088 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7090 } finally {
7091 Binder.restoreCallingIdentity(identity);
7092 }
Andrew Leea1239f22015-03-02 17:44:07 -08007093 }
7094
Andrew Lee9431b832015-03-09 18:46:45 -07007095 @Override
7096 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007097 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007098 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007099 }
7100
7101 @Override
7102 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103 final long identity = Binder.clearCallingIdentity();
7104 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007105 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 } finally {
7107 Binder.restoreCallingIdentity(identity);
7108 }
Andrew Lee9431b832015-03-09 18:46:45 -07007109 }
7110
Hall Liuf6668912018-10-31 17:05:23 -07007111 /**
7112 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7113 * support for the feature and device firmware support.
7114 *
7115 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7116 */
7117 @Override
7118 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007120 final Phone phone = getPhone(subscriptionId);
7121 if (phone == null) {
7122 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7123 return false;
7124 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007126 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007127 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7128 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007129 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130 return isCarrierSupported && isDeviceSupported;
7131 } finally {
7132 Binder.restoreCallingIdentity(identity);
7133 }
Hall Liu98187582018-01-22 19:15:32 -08007134 }
7135
Hall Liuf6668912018-10-31 17:05:23 -07007136 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007137 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7138 * RTT setting, will return true if the device and carrier both support RTT.
7139 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007140 */
7141 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142 final long identity = Binder.clearCallingIdentity();
7143 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007144 boolean isRttSupported = isRttSupported(subscriptionId);
7145 boolean isUserRttSettingOn = Settings.Secure.getInt(
7146 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7147 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7148 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7149 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150 } finally {
7151 Binder.restoreCallingIdentity(identity);
7152 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007153 }
7154
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007155 @Deprecated
7156 @Override
7157 public String getDeviceId(String callingPackage) {
7158 return getDeviceIdWithFeature(callingPackage, null);
7159 }
7160
Sanket Padawe7310cc72015-01-14 09:53:20 -08007161 /**
7162 * Returns the unique device ID of phone, for example, the IMEI for
7163 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7164 *
7165 * <p>Requires Permission:
7166 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7167 */
7168 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007169 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007170 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007171 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007172 return null;
7173 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007174 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007175 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007176 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007177 return null;
7178 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179
7180 final long identity = Binder.clearCallingIdentity();
7181 try {
7182 return phone.getDeviceId();
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
7185 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007186 }
7187
Ping Sunc67b7c22016-03-02 19:16:45 +08007188 /**
7189 * {@hide}
7190 * Returns the IMS Registration Status on a particular subid
7191 *
7192 * @param subId
7193 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007194 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007195 Phone phone = getPhone(subId);
7196 if (phone != null) {
7197 return phone.isImsRegistered();
7198 } else {
7199 return false;
7200 }
7201 }
7202
Santos Cordon7a1885b2015-02-03 11:15:19 -08007203 @Override
7204 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205 final long identity = Binder.clearCallingIdentity();
7206 try {
7207 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7208 } finally {
7209 Binder.restoreCallingIdentity(identity);
7210 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007211 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007212
Tyler Gunnf70ed162019-04-03 15:28:53 -07007213 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007214 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007215 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007217 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007218 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7219 }
7220 final long identity = Binder.clearCallingIdentity();
7221 try {
7222 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7223 } finally {
7224 Binder.restoreCallingIdentity(identity);
7225 }
7226 }
7227
7228 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007229 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007230 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7231 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007232 final long identity = Binder.clearCallingIdentity();
7233 try {
7234 Phone phone = getPhone(subscriptionId);
7235 if (phone == null) {
7236 return null;
7237 }
7238 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
7242 }
7243
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007244 /**
7245 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007246 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007247 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007248 final long identity = Binder.clearCallingIdentity();
7249 try {
7250 Phone phone = getPhone(subId);
7251 if (phone != null) {
7252 return phone.isWifiCallingEnabled();
7253 } else {
7254 return false;
7255 }
7256 } finally {
7257 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007258 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007259 }
7260
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007261 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007262 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007263 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007264 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007265 final long identity = Binder.clearCallingIdentity();
7266 try {
7267 Phone phone = getPhone(subId);
7268 if (phone != null) {
7269 return phone.isVideoEnabled();
7270 } else {
7271 return false;
7272 }
7273 } finally {
7274 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007275 }
7276 }
7277
7278 /**
7279 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7280 * defined in {@link ImsRegistrationImplBase}.
7281 */
7282 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 Phone phone = getPhone(subId);
7286 if (phone != null) {
7287 return phone.getImsRegistrationTech();
7288 } else {
7289 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7290 }
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007293 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007294 }
7295
Stuart Scott8eef64f2015-04-08 15:13:54 -07007296 @Override
7297 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007298 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007299 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7300 return;
7301 }
7302
Svet Ganovcc087f82015-05-12 20:35:54 -07007303 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007304
Svet Ganovcc087f82015-05-12 20:35:54 -07007305 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007306 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7307 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007308 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007309 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007310 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007311 Phone phone = getPhone(subId);
SongFerngWang51ee2b12021-05-27 22:44:54 +08007312 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007313 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7314 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007315 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007316 // There has been issues when Sms raw table somehow stores orphan
7317 // fragments. They lead to garbled message when new fragments come
7318 // in and combined with those stale ones. In case this happens again,
7319 // user can reset all network settings which will clean up this table.
7320 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007321 // Clean up IMS settings as well here.
7322 int slotId = getSlotIndex(subId);
7323 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7324 ImsManager.getInstance(mApp, slotId).factoryReset();
7325 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007326
7327 // Erase modem config if erase modem on network setting is enabled.
7328 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7329 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7330 if (configValue != null && Boolean.parseBoolean(configValue)) {
7331 sendEraseModemConfig(getDefaultPhone());
7332 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007333 } finally {
7334 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007335 }
7336 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007337
SongFerngWang51ee2b12021-05-27 22:44:54 +08007338 @VisibleForTesting
7339 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7340 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7341 return;
7342 }
7343 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7344 RILConstants.PREFERRED_NETWORK_MODE);
7345 SubscriptionManager.setSubscriptionProperty(subId,
7346 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7347 "user=" + defaultNetworkType);
7348 phone.loadAllowedNetworksFromSubscriptionDatabase();
7349 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7350 defaultNetworkType, null);
7351 }
7352
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007353 private void cleanUpSmsRawTable(Context context) {
7354 ContentResolver resolver = context.getContentResolver();
7355 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7356 resolver.delete(uri, null, null);
7357 }
7358
Narayan Kamath1c496c22015-04-16 14:40:19 +01007359 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007360 public String getSimLocaleForSubscriber(int subId) {
7361 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7362 final Phone phone = getPhone(subId);
7363 if (phone == null) {
7364 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007365 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 final long identity = Binder.clearCallingIdentity();
7368 try {
chen xu5d3637b2019-01-21 23:31:38 -08007369 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007370 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007371 if (info == null) {
7372 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7373 return null;
7374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 // Try and fetch the locale from the carrier properties or from the SIM language
7376 // preferences (EF-PL and EF-LI)...
7377 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007379 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7380 if (localeFromDefaultSim != null) {
7381 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7382 if (DBG) log("Using locale from subId: " + subId + " locale: "
7383 + localeFromDefaultSim);
7384 return localeFromDefaultSim.toLanguageTag();
7385 } else {
7386 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 }
7388 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 // The SIM language preferences only store a language (e.g. fr = French), not an
7391 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7392 // the SIM and carrier preferences does not include a country we add the country
7393 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007394 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007396 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007397 return mccLocale.toLanguageTag();
7398 }
7399
7400 if (DBG) log("No locale found - returning null");
7401 return null;
7402 } finally {
7403 Binder.restoreCallingIdentity(identity);
7404 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007405 }
7406
7407 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007408 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007409 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007410 }
7411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007412 /**
7413 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7414 */
7415 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007416 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007417 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007418 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007419
Chenjie Yu1ba97252018-01-11 18:16:20 -08007420 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007421 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007422
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007423 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007424 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7425 * representing the state of the modem.
7426 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007427 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7428 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007429 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007430 */
7431 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007432 public void requestModemActivityInfo(ResultReceiver result) {
7433 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007434 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007435
7436 final long identity = Binder.clearCallingIdentity();
7437 try {
sqian1a1be542020-03-05 11:37:28 -08007438 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 } finally {
7440 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007441 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007442 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007443
Siddharth Rayb8114062018-06-17 15:02:38 -07007444 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7445 // less than total activity duration.
7446 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7447 if (info == null) {
7448 return false;
7449 }
7450 int activityDurationMs =
7451 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7452 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007453 int[] txTimeMs = info.getTransmitTimeMillis();
7454 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7455 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007456 }
7457 return (info.isValid()
7458 && (info.getSleepTimeMillis() <= activityDurationMs)
7459 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007460 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007461 && (totalTxTimeMs <= activityDurationMs));
7462 }
7463
Jack Yu85bd38a2015-11-09 11:34:32 -08007464 /**
7465 * {@hide}
7466 * Returns the service state information on specified subscription.
7467 */
7468 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007469 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7470 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007472 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007473 return null;
7474 }
7475
Hall Liuf19c44f2018-11-27 14:38:17 -08007476 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7477 LocationAccessPolicy.checkLocationPermission(mApp,
7478 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7479 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007480 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007481 .setCallingPid(Binder.getCallingPid())
7482 .setCallingUid(Binder.getCallingUid())
7483 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007484 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007485 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007486 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7487 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007488 .build());
7489
7490 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7491 LocationAccessPolicy.checkLocationPermission(mApp,
7492 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7493 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007494 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007495 .setCallingPid(Binder.getCallingPid())
7496 .setCallingUid(Binder.getCallingUid())
7497 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007498 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007499 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007500 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7501 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007502 .build());
7503 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7504 boolean hasFinePermission =
7505 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7506 boolean hasCoarsePermission =
7507 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 final long identity = Binder.clearCallingIdentity();
7510 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007511 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7512 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7513 Rlog.d(LOG_TAG,
7514 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7515 return null;
7516 }
7517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 final Phone phone = getPhone(subId);
7519 if (phone == null) {
7520 return null;
7521 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007522
Hall Liuf19c44f2018-11-27 14:38:17 -08007523 ServiceState ss = phone.getServiceState();
7524
7525 // Scrub out the location info in ServiceState depending on what level of access
7526 // the caller has.
7527 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007528 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7529 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 } finally {
7531 Binder.restoreCallingIdentity(identity);
7532 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007533 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007534
7535 /**
7536 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7537 *
7538 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7539 * voicemail ringtone.
7540 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7541 * PhoneAccount.
7542 */
7543 @Override
7544 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 final long identity = Binder.clearCallingIdentity();
7546 try {
7547 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7548 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007551
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7553 } finally {
7554 Binder.restoreCallingIdentity(identity);
7555 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007556 }
7557
7558 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007559 * Sets the per-account voicemail ringtone.
7560 *
7561 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7562 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7563 *
7564 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7565 * voicemail ringtone.
7566 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7567 * PhoneAccount.
7568 */
7569 @Override
7570 public void setVoicemailRingtoneUri(String callingPackage,
7571 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007572 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007573 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007574 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7575 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7577 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7578 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580
7581 final long identity = Binder.clearCallingIdentity();
7582 try {
7583 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7584 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007585 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007586 }
7587 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7588 } finally {
7589 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007590 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007591 }
7592
7593 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007594 * Returns whether vibration is set for voicemail notification in Phone settings.
7595 *
7596 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7597 * voicemail vibration setting.
7598 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7599 */
7600 @Override
7601 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602 final long identity = Binder.clearCallingIdentity();
7603 try {
7604 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7605 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007606 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007607 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007608
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7610 } finally {
7611 Binder.restoreCallingIdentity(identity);
7612 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007613 }
7614
Youhan Wange64578a2016-05-02 15:32:42 -07007615 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007616 * Sets the per-account voicemail vibration.
7617 *
7618 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7619 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7620 *
7621 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7622 * voicemail vibration setting.
7623 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7624 * specific PhoneAccount.
7625 */
7626 @Override
7627 public void setVoicemailVibrationEnabled(String callingPackage,
7628 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007629 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007630 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007631 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7632 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7634 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7635 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007636 }
7637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007638 final long identity = Binder.clearCallingIdentity();
7639 try {
7640 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7641 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007642 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643 }
7644 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7645 } finally {
7646 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007647 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007648 }
7649
7650 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007651 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7652 *
7653 * @throws SecurityException if the caller does not have the required permission
7654 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007655 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007656 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007657 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007658 }
7659
7660 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007661 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7662 * permission.
7663 *
7664 * @throws SecurityException if the caller does not have the required permission
7665 */
7666 private void enforceSendSmsPermission() {
7667 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7668 }
7669
7670 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007671 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007672 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007673 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007674 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007675 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676 final long identity = Binder.clearCallingIdentity();
7677 try {
7678 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007679 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 if (componentName == null) {
7681 throw new SecurityException(
7682 "Caller not current active visual voicemail package[null]");
7683 }
7684 String vvmPackage = componentName.getPackageName();
7685 if (!callingPackage.equals(vvmPackage)) {
7686 throw new SecurityException("Caller not current active visual voicemail package["
7687 + vvmPackage + "]");
7688 }
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007691 }
7692 }
7693
7694 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007695 * Return the application ID for the app type.
7696 *
7697 * @param subId the subscription ID that this request applies to.
7698 * @param appType the uicc app type.
7699 * @return Application ID for specificied app type, or null if no uicc.
7700 */
7701 @Override
7702 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007703 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007704 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007705
7706 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007707 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 if (phone == null) {
7709 return null;
7710 }
7711 String aid = null;
7712 try {
7713 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7714 .getApplicationByType(appType).getAid();
7715 } catch (Exception e) {
7716 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7717 }
7718 return aid;
7719 } finally {
7720 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007721 }
Youhan Wange64578a2016-05-02 15:32:42 -07007722 }
7723
Youhan Wang4001d252016-05-11 10:29:41 -07007724 /**
7725 * Return the Electronic Serial Number.
7726 *
7727 * @param subId the subscription ID that this request applies to.
7728 * @return ESN or null if error.
7729 */
7730 @Override
7731 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007732 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007733 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734
7735 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007736 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 if (phone == null) {
7738 return null;
7739 }
7740 String esn = null;
7741 try {
7742 esn = phone.getEsn();
7743 } catch (Exception e) {
7744 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7745 }
7746 return esn;
7747 } finally {
7748 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007749 }
Youhan Wang4001d252016-05-11 10:29:41 -07007750 }
7751
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007752 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007753 * Return the Preferred Roaming List Version.
7754 *
7755 * @param subId the subscription ID that this request applies to.
7756 * @return PRLVersion or null if error.
7757 */
7758 @Override
7759 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007760 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007761 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007762
7763 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007764 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765 if (phone == null) {
7766 return null;
7767 }
7768 String cdmaPrlVersion = null;
7769 try {
7770 cdmaPrlVersion = phone.getCdmaPrlVersion();
7771 } catch (Exception e) {
7772 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7773 }
7774 return cdmaPrlVersion;
7775 } finally {
7776 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007777 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007778 }
7779
7780 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007781 * Get snapshot of Telephony histograms
7782 * @return List of Telephony histograms
7783 * @hide
7784 */
7785 @Override
7786 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7788 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789
7790 final long identity = Binder.clearCallingIdentity();
7791 try {
7792 return RIL.getTelephonyRILTimingHistograms();
7793 } finally {
7794 Binder.restoreCallingIdentity(identity);
7795 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007796 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007797
7798 /**
7799 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007800 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7801 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007802 * Require system privileges. In the future we may add this to carrier APIs.
7803 *
Michele Berionne482f8202018-11-27 18:57:59 -08007804 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007805 */
7806 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007807 @TelephonyManager.SetCarrierRestrictionResult
7808 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007809 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007810 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007811
Michele Berionne482f8202018-11-27 18:57:59 -08007812 if (carrierRestrictionRules == null) {
7813 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007814 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 final long identity = Binder.clearCallingIdentity();
7817 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007818 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007819 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820 } finally {
7821 Binder.restoreCallingIdentity(identity);
7822 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007823 }
7824
7825 /**
7826 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007827 * Get the allowed carrier list and the excluded carrier list, including the priority between
7828 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007829 * Require system privileges. In the future we may add this to carrier APIs.
7830 *
Michele Berionne482f8202018-11-27 18:57:59 -08007831 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007832 */
7833 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007834 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007835 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007836 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837
7838 final long identity = Binder.clearCallingIdentity();
7839 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007840 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7841 if (response instanceof CarrierRestrictionRules) {
7842 return (CarrierRestrictionRules) response;
7843 }
7844 // Response is an Exception of some kind,
7845 // which is signalled to the user as a NULL retval
7846 return null;
7847 } catch (Exception e) {
7848 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7849 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 } finally {
7851 Binder.restoreCallingIdentity(identity);
7852 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007853 }
7854
fionaxu59545b42016-05-25 15:53:37 -07007855 /**
fionaxu59545b42016-05-25 15:53:37 -07007856 * Action set from carrier signalling broadcast receivers to enable/disable radio
7857 * @param subId the subscription ID that this action applies to.
7858 * @param enabled control enable or disable radio.
7859 * {@hide}
7860 */
7861 @Override
7862 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7863 enforceModifyPermission();
7864 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865
7866 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007867 if (phone == null) {
7868 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7869 return;
7870 }
7871 try {
7872 phone.carrierActionSetRadioEnabled(enabled);
7873 } catch (Exception e) {
7874 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875 } finally {
7876 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007877 }
7878 }
7879
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007880 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007881 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7882 * network status based on which carrier apps could apply actions accordingly,
7883 * enable/disable default url handler for example.
7884 *
7885 * @param subId the subscription ID that this action applies to.
7886 * @param report control start/stop reporting the default network status.
7887 * {@hide}
7888 */
7889 @Override
7890 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7891 enforceModifyPermission();
7892 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007893
7894 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007895 if (phone == null) {
7896 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7897 return;
7898 }
7899 try {
7900 phone.carrierActionReportDefaultNetworkStatus(report);
7901 } catch (Exception e) {
7902 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903 } finally {
7904 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007905 }
7906 }
7907
7908 /**
fionaxud9622282017-07-17 17:51:30 -07007909 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7910 * @param subId the subscription ID that this action applies to.
7911 * {@hide}
7912 */
7913 @Override
7914 public void carrierActionResetAll(int subId) {
7915 enforceModifyPermission();
7916 final Phone phone = getPhone(subId);
7917 if (phone == null) {
7918 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7919 return;
7920 }
7921 try {
7922 phone.carrierActionResetAll();
7923 } catch (Exception e) {
7924 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7925 }
7926 }
7927
7928 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007929 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7930 * bug report is being generated.
7931 */
7932 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007933 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007934 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7935 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007936 writer.println("Permission Denial: can't dump Phone from pid="
7937 + Binder.getCallingPid()
7938 + ", uid=" + Binder.getCallingUid()
7939 + "without permission "
7940 + android.Manifest.permission.DUMP);
7941 return;
7942 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007943 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007944 }
Jack Yueb89b242016-06-22 13:27:47 -07007945
Brad Ebingerdac2f002018-04-03 15:17:52 -07007946 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007947 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7948 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7949 @NonNull String[] args) {
7950 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7951 this, in.getFileDescriptor(), out.getFileDescriptor(),
7952 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007953 }
7954
Jack Yueb89b242016-06-22 13:27:47 -07007955 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007956 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007957 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007958 * @param reason the reason the data enable change is taking place
7959 * @param enabled True if enabling the data, otherwise disabling.
7960 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007961 */
7962 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007963 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007964 boolean enabled) {
7965 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7966 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7967 try {
7968 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007969 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007970 } catch (SecurityException se) {
7971 enforceModifyPermission();
7972 }
7973 } else {
7974 enforceModifyPermission();
7975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007976
7977 final long identity = Binder.clearCallingIdentity();
7978 try {
7979 Phone phone = getPhone(subId);
7980 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007981 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7982 phone.carrierActionSetMeteredApnsEnabled(enabled);
7983 } else {
7984 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007986 }
7987 } finally {
7988 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007989 }
7990 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007991
7992 /**
7993 * Get Client request stats
7994 * @return List of Client Request Stats
7995 * @hide
7996 */
7997 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007998 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7999 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008001 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008002 return null;
8003 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008004 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008006 final long identity = Binder.clearCallingIdentity();
8007 try {
8008 if (phone != null) {
8009 return phone.getClientRequestStats();
8010 }
8011
8012 return null;
8013 } finally {
8014 Binder.restoreCallingIdentity(identity);
8015 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008016 }
8017
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008018 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008019 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008020 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008021 }
Jack Yueb4124c2017-02-16 15:32:43 -08008022
8023 /**
Grace Chen70990072017-03-24 17:21:30 -07008024 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008025 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008026 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008027 * @param state State of SIM (power down, power up, pass through)
8028 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8029 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8030 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008031 *
8032 **/
8033 @Override
Grace Chen70990072017-03-24 17:21:30 -07008034 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008035 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008036 Phone phone = PhoneFactory.getPhone(slotIndex);
8037
vagdeviaf9a5b92018-08-15 16:01:53 -07008038 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008040 final long identity = Binder.clearCallingIdentity();
8041 try {
8042 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008043 phone.setSimPowerState(state, null, workSource);
8044 }
8045 } finally {
8046 Binder.restoreCallingIdentity(identity);
8047 }
8048 }
8049
8050 /**
8051 * Set SIM card power state.
8052 *
8053 * @param slotIndex SIM slot id.
8054 * @param state State of SIM (power down, power up, pass through)
8055 * @param callback callback to trigger after success or failure
8056 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8057 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8058 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8059 *
8060 **/
8061 @Override
8062 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8063 IIntegerConsumer callback) {
8064 enforceModifyPermission();
8065 Phone phone = PhoneFactory.getPhone(slotIndex);
8066
8067 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8068
8069 final long identity = Binder.clearCallingIdentity();
8070 try {
8071 if (phone != null) {
8072 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8073 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008074 }
8075 } finally {
8076 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008077 }
8078 }
Shuo Qiandd210312017-04-12 22:11:33 +00008079
Tyler Gunn65d45c22017-06-05 11:22:26 -07008080 private boolean isUssdApiAllowed(int subId) {
8081 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008082 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008083 if (configManager == null) {
8084 return false;
8085 }
8086 PersistableBundle pb = configManager.getConfigForSubId(subId);
8087 if (pb == null) {
8088 return false;
8089 }
8090 return pb.getBoolean(
8091 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8092 }
8093
Shuo Qiandd210312017-04-12 22:11:33 +00008094 /**
8095 * Check if phone is in emergency callback mode
8096 * @return true if phone is in emergency callback mode
8097 * @param subId sub id
8098 */
goneil9c5f4872017-12-05 14:07:56 -08008099 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008100 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008101 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008102 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008103
8104 final long identity = Binder.clearCallingIdentity();
8105 try {
8106 if (phone != null) {
8107 return phone.isInEcm();
8108 } else {
8109 return false;
8110 }
8111 } finally {
8112 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008113 }
8114 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008115
8116 /**
8117 * Get the current signal strength information for the given subscription.
8118 * Because this information is not updated when the device is in a low power state
8119 * it should not be relied-upon to be current.
8120 * @param subId Subscription index
8121 * @return the most recent cached signal strength info from the modem
8122 */
8123 @Override
8124 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 final long identity = Binder.clearCallingIdentity();
8126 try {
8127 Phone p = getPhone(subId);
8128 if (p == null) {
8129 return null;
8130 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132 return p.getSignalStrength();
8133 } finally {
8134 Binder.restoreCallingIdentity(identity);
8135 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008136 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008137
Pengquan Meng77b7f132018-08-22 14:49:57 -07008138 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008139 * Get the current modem radio state for the given slot.
8140 * @param slotIndex slot index.
8141 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008142 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008143 * @return the current radio power state from the modem
8144 */
8145 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008146 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008147 Phone phone = PhoneFactory.getPhone(slotIndex);
8148 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8150 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008151 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8152 }
8153
8154 final long identity = Binder.clearCallingIdentity();
8155 try {
8156 return phone.getRadioPowerState();
8157 } finally {
8158 Binder.restoreCallingIdentity(identity);
8159 }
8160 }
8161 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8162 }
8163
8164 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008165 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8166 *
8167 * <p>Requires one of the following permissions:
8168 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8169 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8170 * privileges.
8171 *
8172 * @param subId subscription id
8173 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8174 * {@code false}.
8175 */
8176 @Override
8177 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008178 try {
8179 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8180 null);
8181 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008182 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008183 mApp, subId, "isDataRoamingEnabled");
8184 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008185
Pengquan Menga1bb6272018-09-06 09:59:22 -07008186 boolean isEnabled = false;
8187 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008188 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008189 Phone phone = getPhone(subId);
8190 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008191 } finally {
8192 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008193 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008194 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008195 }
8196
8197
8198 /**
8199 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8200 *
8201 * <p> Requires permission:
8202 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8203 * privileges.
8204 *
8205 * @param subId subscription id
8206 * @param isEnabled {@code true} means enable, {@code false} means disable.
8207 */
8208 @Override
8209 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8211 mApp, subId, "setDataRoamingEnabled");
8212
Pengquan Menga1bb6272018-09-06 09:59:22 -07008213 final long identity = Binder.clearCallingIdentity();
8214 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008215 Phone phone = getPhone(subId);
8216 if (phone != null) {
8217 phone.setDataRoamingEnabled(isEnabled);
8218 }
8219 } finally {
8220 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008221 }
8222 }
8223
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008224 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008225 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008226 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008227 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008228 mApp, subId, "isManualNetworkSelectionAllowed");
8229
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008230 boolean isAllowed = true;
8231 final long identity = Binder.clearCallingIdentity();
8232 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008233 Phone phone = getPhone(subId);
8234 if (phone != null) {
8235 isAllowed = phone.isCspPlmnEnabled();
8236 }
8237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
8240 return isAllowed;
8241 }
8242
8243 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008244 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008245 // Verify that tha callingPackage belongs to the calling UID
8246 mApp.getSystemService(AppOpsManager.class)
8247 .checkPackage(Binder.getCallingUid(), callingPackage);
8248
Jordan Liu1e142fc2019-04-22 15:10:43 -07008249 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008250 try {
8251 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008252 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008253 } catch (SecurityException e) {
8254 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8255 // has carrier privileges on an active UICC
8256 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8257 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008258 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008259 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008260 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008261
8262 final long identity = Binder.clearCallingIdentity();
8263 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008264 UiccController uiccController = UiccController.getInstance();
8265 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008266 if (hasReadPermission) {
8267 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008268 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008269
8270 // Remove private info if the caller doesn't have access
8271 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8272 for (UiccCardInfo cardInfo : cardInfos) {
8273 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8274 // is available
8275 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8276 if (card == null || card.getUiccProfile() == null) {
8277 // assume no access if the card or profile is unavailable
8278 filteredInfos.add(cardInfo.getUnprivileged());
8279 continue;
8280 }
8281 UiccProfile profile = card.getUiccProfile();
8282 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8283 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8284 filteredInfos.add(cardInfo);
8285 } else {
8286 filteredInfos.add(cardInfo.getUnprivileged());
8287 }
8288 }
8289 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008290 } finally {
8291 Binder.restoreCallingIdentity(identity);
8292 }
8293 }
8294
8295 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008296 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008297 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 final long identity = Binder.clearCallingIdentity();
8300 try {
8301 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8302 if (slots == null) {
8303 Rlog.i(LOG_TAG, "slots is null.");
8304 return null;
8305 }
8306
8307 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8308 for (int i = 0; i < slots.length; i++) {
8309 UiccSlot slot = slots[i];
8310 if (slot == null) {
8311 continue;
8312 }
8313
Jordan Liu7be7e652019-05-06 18:55:02 +00008314 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008315 UiccCard card = slot.getUiccCard();
8316 if (card != null) {
8317 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008318 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008319 cardId = slot.getEid();
8320 if (TextUtils.isEmpty(cardId)) {
8321 cardId = slot.getIccId();
8322 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008323 }
8324
Jordan Liu857451f2019-05-09 16:35:35 -07008325 if (cardId != null) {
8326 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8327 // if cardId is an EID, it's all digits so this is fine
8328 cardId = IccUtils.stripTrailingFs(cardId);
8329 }
8330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008331 int cardState = 0;
8332 switch (slot.getCardState()) {
8333 case CARDSTATE_ABSENT:
8334 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8335 break;
8336 case CARDSTATE_PRESENT:
8337 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8338 break;
8339 case CARDSTATE_ERROR:
8340 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8341 break;
8342 case CARDSTATE_RESTRICTED:
8343 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8344 break;
8345 default:
8346 break;
8347
8348 }
8349
8350 infos[i] = new UiccSlotInfo(
8351 slot.isActive(),
8352 slot.isEuicc(),
8353 cardId,
8354 cardState,
8355 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008356 slot.isExtendedApduSupported(),
8357 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008358 }
8359 return infos;
8360 } finally {
8361 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008362 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008363 }
8364
8365 @Override
8366 public boolean switchSlots(int[] physicalSlots) {
8367 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368
8369 final long identity = Binder.clearCallingIdentity();
8370 try {
8371 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8372 } finally {
8373 Binder.restoreCallingIdentity(identity);
8374 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008375 }
Jack Yu4c988042018-02-27 15:30:01 -08008376
8377 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008378 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008379 final long identity = Binder.clearCallingIdentity();
8380 try {
8381 return UiccController.getInstance().getCardIdForDefaultEuicc();
8382 } finally {
8383 Binder.restoreCallingIdentity(identity);
8384 }
8385 }
8386
Pengquan Meng85728fb2018-03-12 16:31:21 -07008387 /**
goneil47ffb6e2018-04-06 15:40:58 -07008388 * A test API to reload the UICC profile.
8389 *
8390 * <p>Requires that the calling app has permission
8391 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8392 * @hide
8393 */
8394 @Override
8395 public void refreshUiccProfile(int subId) {
8396 enforceModifyPermission();
8397
8398 final long identity = Binder.clearCallingIdentity();
8399 try {
8400 Phone phone = getPhone(subId);
8401 if (phone == null) {
8402 return;
8403 }
8404 UiccCard uiccCard = phone.getUiccCard();
8405 if (uiccCard == null) {
8406 return;
8407 }
8408 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8409 if (uiccProfile == null) {
8410 return;
8411 }
8412 uiccProfile.refresh();
8413 } finally {
8414 Binder.restoreCallingIdentity(identity);
8415 }
8416 }
8417
8418 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008419 * Returns false if the mobile data is disabled by default, otherwise return true.
8420 */
8421 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008422 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008423 }
8424
8425 /**
8426 * Returns true if the data roaming is enabled by default, i.e the system property
8427 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8428 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8429 */
8430 private boolean getDefaultDataRoamingEnabled(int subId) {
8431 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008432 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008433 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008434 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8435 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8436 return isDataRoamingEnabled;
8437 }
8438
8439 /**
8440 * Returns the default network type for the given {@code subId}, if the default network type is
8441 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8442 */
8443 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008444 List<Integer> list = TelephonyProperties.default_network();
8445 int phoneId = mSubscriptionController.getPhoneId(subId);
8446 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8447 return list.get(phoneId);
8448 }
8449 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008450 }
fionaxua13278b2018-03-21 00:08:13 -07008451
8452 @Override
8453 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008454 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008455 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008456
8457 final long identity = Binder.clearCallingIdentity();
8458 try {
8459 final Phone phone = getPhone(subId);
8460 if (phone == null) {
8461 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8462 return;
8463 }
chen xueaba88a2019-03-15 13:15:10 -07008464 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8465 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008466 if (carrierPrivilegeRules == null) {
8467 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8468 } else {
8469 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8470 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008471 } finally {
8472 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008473 }
fionaxua13278b2018-03-21 00:08:13 -07008474 }
8475
8476 @Override
8477 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008478 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008479
8480 final long identity = Binder.clearCallingIdentity();
8481 try {
8482 final Phone phone = getPhone(subId);
8483 if (phone == null) {
8484 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8485 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8486 }
8487 return phone.getCarrierIdListVersion();
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008490 }
fionaxua13278b2018-03-21 00:08:13 -07008491 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008492
8493 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008494 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8495 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008497 mApp, subId, callingPackage, callingFeatureId,
8498 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008499 return -1;
8500 }
8501
8502 final long identity = Binder.clearCallingIdentity();
8503 try {
8504 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8505 } finally {
8506 Binder.restoreCallingIdentity(identity);
8507 }
8508 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008509
8510 @Override
8511 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008512 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008513 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008514 mApp, subId, "getCdmaRoamingMode");
8515
8516 final long identity = Binder.clearCallingIdentity();
8517 try {
8518 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8519 } finally {
8520 Binder.restoreCallingIdentity(identity);
8521 }
8522 }
8523
8524 @Override
8525 public boolean setCdmaRoamingMode(int subId, int mode) {
8526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8527 mApp, subId, "setCdmaRoamingMode");
8528
8529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8532 } finally {
8533 Binder.restoreCallingIdentity(identity);
8534 }
8535 }
8536
8537 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008538 public int getCdmaSubscriptionMode(int subId) {
8539 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008540 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008541 mApp, subId, "getCdmaSubscriptionMode");
8542
8543 final long identity = Binder.clearCallingIdentity();
8544 try {
8545 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8546 } finally {
8547 Binder.restoreCallingIdentity(identity);
8548 }
8549 }
8550
8551 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008552 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8554 mApp, subId, "setCdmaSubscriptionMode");
8555
8556 final long identity = Binder.clearCallingIdentity();
8557 try {
8558 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8559 } finally {
8560 Binder.restoreCallingIdentity(identity);
8561 }
8562 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008563
sqianc5eccab2018-10-19 18:46:41 -07008564 @Override
sqian8c685422019-02-22 15:55:18 -08008565 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008566 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008568 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8569 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008570 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8571 }
8572 final long identity = Binder.clearCallingIdentity();
8573 try {
sqian854d44b2018-12-12 16:48:18 -08008574 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8575 for (Phone phone: PhoneFactory.getPhones()) {
8576 if (phone.getEmergencyNumberTracker() != null
8577 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8578 emergencyNumberListInternal.put(
8579 phone.getSubId(),
8580 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8581 }
sqian11b7a0e2018-12-05 18:48:28 -08008582 }
sqian854d44b2018-12-12 16:48:18 -08008583 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008584 } finally {
8585 Binder.restoreCallingIdentity(identity);
8586 }
sqianc5eccab2018-10-19 18:46:41 -07008587 }
8588
8589 @Override
sqian8c685422019-02-22 15:55:18 -08008590 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008591 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008592 if (!exactMatch) {
8593 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008594 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008595 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008596 }
8597 final long identity = Binder.clearCallingIdentity();
8598 try {
sqian854d44b2018-12-12 16:48:18 -08008599 for (Phone phone: PhoneFactory.getPhones()) {
8600 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008601 && phone.getEmergencyNumberTracker()
8602 .isEmergencyNumber(number, exactMatch)) {
8603 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008604 }
sqian11b7a0e2018-12-05 18:48:28 -08008605 }
8606 return false;
8607 } finally {
8608 Binder.restoreCallingIdentity(identity);
8609 }
8610 }
8611
sqianf4ca7ed2019-01-15 18:32:07 -08008612 /**
Shuo Qian479dd9e2021-02-22 18:32:21 -08008613 * Start emergency callback mode for GsmCdmaPhone for testing.
8614 */
8615 @Override
8616 public void startEmergencyCallbackMode() {
8617 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8618 "startEmergencyCallbackMode");
8619 enforceModifyPermission();
8620 final long identity = Binder.clearCallingIdentity();
8621 try {
8622 for (Phone phone : PhoneFactory.getPhones()) {
8623 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8624 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8625 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8626 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8627 gsmCdmaPhone.obtainMessage(
8628 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8629 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8630 }
8631 }
8632 } finally {
8633 Binder.restoreCallingIdentity(identity);
8634 }
8635 }
8636
8637 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008638 * Update emergency number list for test mode.
8639 */
8640 @Override
8641 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8643 "updateEmergencyNumberListTestMode");
8644
8645 final long identity = Binder.clearCallingIdentity();
8646 try {
8647 for (Phone phone: PhoneFactory.getPhones()) {
8648 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8649 if (tracker != null) {
8650 tracker.executeEmergencyNumberTestModeCommand(action, num);
8651 }
8652 }
8653 } finally {
8654 Binder.restoreCallingIdentity(identity);
8655 }
8656 }
8657
8658 /**
8659 * Get the full emergency number list for test mode.
8660 */
8661 @Override
8662 public List<String> getEmergencyNumberListTestMode() {
8663 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8664 "getEmergencyNumberListTestMode");
8665
8666 final long identity = Binder.clearCallingIdentity();
8667 try {
8668 Set<String> emergencyNumbers = new HashSet<>();
8669 for (Phone phone: PhoneFactory.getPhones()) {
8670 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8671 if (tracker != null) {
8672 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8673 emergencyNumbers.add(num.getNumber());
8674 }
8675 }
8676 }
8677 return new ArrayList<>(emergencyNumbers);
8678 } finally {
8679 Binder.restoreCallingIdentity(identity);
8680 }
8681 }
8682
chen xud6b45bd2018-10-30 22:27:10 -07008683 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008684 public int getEmergencyNumberDbVersion(int subId) {
8685 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8686
8687 final long identity = Binder.clearCallingIdentity();
8688 try {
8689 final Phone phone = getPhone(subId);
8690 if (phone == null) {
8691 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8692 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8693 }
8694 return phone.getEmergencyNumberDbVersion();
8695 } finally {
8696 Binder.restoreCallingIdentity(identity);
8697 }
8698 }
8699
8700 @Override
8701 public void notifyOtaEmergencyNumberDbInstalled() {
8702 enforceModifyPermission();
8703
8704 final long identity = Binder.clearCallingIdentity();
8705 try {
8706 for (Phone phone: PhoneFactory.getPhones()) {
8707 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8708 if (tracker != null) {
8709 tracker.updateOtaEmergencyNumberDatabase();
8710 }
8711 }
8712 } finally {
8713 Binder.restoreCallingIdentity(identity);
8714 }
8715 }
8716
8717 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008718 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008719 enforceActiveEmergencySessionPermission();
8720
8721 final long identity = Binder.clearCallingIdentity();
8722 try {
8723 for (Phone phone: PhoneFactory.getPhones()) {
8724 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8725 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008726 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8727 }
8728 }
8729 } finally {
8730 Binder.restoreCallingIdentity(identity);
8731 }
8732 }
8733
8734 @Override
8735 public void resetOtaEmergencyNumberDbFilePath() {
8736 enforceActiveEmergencySessionPermission();
8737
8738 final long identity = Binder.clearCallingIdentity();
8739 try {
8740 for (Phone phone: PhoneFactory.getPhones()) {
8741 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8742 if (tracker != null) {
8743 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008744 }
8745 }
8746 } finally {
8747 Binder.restoreCallingIdentity(identity);
8748 }
8749 }
8750
8751 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008752 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8753 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8754 Phone phone = getPhone(subId);
8755 if (phone == null) {
8756 return null;
8757 }
8758 final long identity = Binder.clearCallingIdentity();
8759 try {
8760 UiccProfile profile = UiccController.getInstance()
8761 .getUiccProfileForPhone(phone.getPhoneId());
8762 if (profile != null) {
8763 return profile.getCertsFromCarrierPrivilegeAccessRules();
8764 }
8765 } finally {
8766 Binder.restoreCallingIdentity(identity);
8767 }
8768 return null;
8769 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008770
8771 /**
8772 * Enable or disable a modem stack.
8773 */
8774 @Override
8775 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8776 enforceModifyPermission();
8777
8778 final long identity = Binder.clearCallingIdentity();
8779 try {
8780 Phone phone = PhoneFactory.getPhone(slotIndex);
8781 if (phone == null) {
8782 return false;
8783 } else {
8784 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8785 }
8786 } finally {
8787 Binder.restoreCallingIdentity(identity);
8788 }
8789 }
Michelecea4cf22018-12-21 15:00:11 -08008790
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008791 /**
8792 * Whether a modem stack is enabled or not.
8793 */
8794 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008795 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8796 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008797 Phone phone = PhoneFactory.getPhone(slotIndex);
8798 if (phone == null) return false;
8799
8800 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008801 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8802 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008803 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8804 }
8805
8806 final long identity = Binder.clearCallingIdentity();
8807 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008808 try {
8809 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8810 } catch (NoSuchElementException ex) {
8811 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8812 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008813 } finally {
8814 Binder.restoreCallingIdentity(identity);
8815 }
8816 }
8817
Michelecea4cf22018-12-21 15:00:11 -08008818 @Override
Michele0ea7d782019-03-19 14:58:42 -07008819 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008820 enforceModifyPermission();
8821
8822 final long identity = Binder.clearCallingIdentity();
8823 try {
8824 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008825 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008826 .commit();
8827 } finally {
8828 Binder.restoreCallingIdentity(identity);
8829 }
8830 }
8831
8832 @Override
Michele0ea7d782019-03-19 14:58:42 -07008833 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008834 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008836 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8837 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008838 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008839 }
Michelecea4cf22018-12-21 15:00:11 -08008840
8841 final long identity = Binder.clearCallingIdentity();
8842 try {
Michele0ea7d782019-03-19 14:58:42 -07008843 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008844 } finally {
8845 Binder.restoreCallingIdentity(identity);
8846 }
8847 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008848
Michele0ea7d782019-03-19 14:58:42 -07008849 @TelephonyManager.IsMultiSimSupportedResult
8850 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008851 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8852 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8853 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008854 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8855 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008856 }
8857 // Check if the hardware supports multisim functionality. If usage of multisim is not
8858 // supported by the modem, indicate that it is restricted.
8859 PhoneCapability staticCapability =
8860 mPhoneConfigurationManager.getStaticPhoneCapability();
8861 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008862 loge("isMultiSimSupportedInternal: no static configuration available");
8863 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008864 }
SongFerngWang2c4309d2021-01-17 21:51:44 +08008865 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008866 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8867 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008868 }
8869 // Check if support of multiple SIMs is restricted by carrier
8870 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008871 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008872 }
8873
Michele0ea7d782019-03-19 14:58:42 -07008874 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008875 }
8876
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008877 /**
8878 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008879 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8880 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8881 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008882 * @param numOfSims number of active sims we want to switch to
8883 */
8884 @Override
8885 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008886 if (numOfSims == 1) {
8887 enforceModifyPermission();
8888 } else {
8889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8890 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8891 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008892 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008893
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008894 try {
Michele30b57b22019-03-01 12:01:14 -08008895 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008896 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008897 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8898 return;
8899 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008900 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8901 } finally {
8902 Binder.restoreCallingIdentity(identity);
8903 }
8904 }
8905
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008906 @Override
8907 public boolean isApplicationOnUicc(int subId, int appType) {
8908 enforceReadPrivilegedPermission("isApplicationOnUicc");
8909 Phone phone = getPhone(subId);
8910 if (phone == null) {
8911 return false;
8912 }
8913 final long identity = Binder.clearCallingIdentity();
8914 try {
8915 UiccCard uiccCard = phone.getUiccCard();
8916 if (uiccCard == null) {
8917 return false;
8918 }
8919 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8920 if (uiccProfile == null) {
8921 return false;
8922 }
8923 if (TelephonyManager.APPTYPE_SIM <= appType
8924 && appType <= TelephonyManager.APPTYPE_ISIM) {
8925 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8926 }
8927 return false;
8928 } finally {
8929 Binder.restoreCallingIdentity(identity);
8930 }
8931 }
8932
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008933 /**
chen xub4baa772019-04-03 10:23:41 -07008934 * Get whether making changes to modem configurations will trigger reboot.
8935 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008936 */
8937 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008938 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8939 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008941 mApp, subId, callingPackage, callingFeatureId,
8942 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008943 return false;
8944 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008945 final long identity = Binder.clearCallingIdentity();
8946 try {
8947 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8948 } finally {
8949 Binder.restoreCallingIdentity(identity);
8950 }
8951 }
8952
Nathan Harold29f5f052019-02-15 13:41:57 -08008953 private void updateModemStateMetrics() {
8954 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8955 // TODO: check the state for each modem if the api is ready.
8956 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8957 }
8958
Pengquan Meng3889a572019-01-23 11:16:29 -08008959 @Override
8960 public int[] getSlotsMapping() {
8961 enforceReadPrivilegedPermission("getSlotsMapping");
8962
8963 final long identity = Binder.clearCallingIdentity();
8964 try {
8965 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8966 // All logical slots should have a mapping to a physical slot.
8967 int[] logicalSlotsMapping = new int[phoneCount];
8968 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8969 for (int i = 0; i < slotInfos.length; i++) {
8970 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8971 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8972 }
8973 }
8974 return logicalSlotsMapping;
8975 } finally {
8976 Binder.restoreCallingIdentity(identity);
8977 }
8978 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008979
8980 /**
8981 * Get the IRadio HAL Version
8982 */
8983 @Override
8984 public int getRadioHalVersion() {
8985 Phone phone = getDefaultPhone();
8986 if (phone == null) return -1;
8987 HalVersion hv = phone.getHalVersion();
8988 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8989 return hv.major * 100 + hv.minor;
8990 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008991
8992 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008993 * Get the current calling package name.
8994 * @return the current calling package name
8995 */
8996 @Override
8997 public String getCurrentPackageName() {
8998 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8999 }
9000
9001 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009002 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9003 * corresponding network requests on a subId.
9004 *
9005 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009006 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009007 * 2) APN is un-metered for this subscription, or
9008 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07009009 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009010 *
9011 * @return whether data is allowed for a apn type.
9012 *
9013 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009014 */
9015 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009016 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009017 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9018 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009019
9020 // Now that all security checks passes, perform the operation as ourselves.
9021 final long identity = Binder.clearCallingIdentity();
9022 try {
9023 Phone phone = getPhone(subId);
9024 if (phone == null) return false;
9025
Jack Yu41407ee2019-05-13 16:54:09 -07009026 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009027 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
9031 }
9032
9033 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009034 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009035 enforceReadPrivilegedPermission("isApnMetered");
9036
9037 // Now that all security checks passes, perform the operation as ourselves.
9038 final long identity = Binder.clearCallingIdentity();
9039 try {
9040 Phone phone = getPhone(subId);
9041 if (phone == null) return true; // By default return true.
9042
Jack Yu41407ee2019-05-13 16:54:09 -07009043 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009044 } finally {
9045 Binder.restoreCallingIdentity(identity);
9046 }
9047 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009048
9049 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009050 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9051 int subscriptionId, IBooleanConsumer resultCallback) {
9052 enforceModifyPermission();
9053 long token = Binder.clearCallingIdentity();
9054 try {
9055 Phone phone = getPhone(subscriptionId);
9056 if (phone == null) {
9057 try {
9058 if (resultCallback != null) {
9059 resultCallback.accept(false);
9060 }
9061 } catch (RemoteException e) {
9062 // ignore
9063 }
9064 return;
9065 }
9066 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9067 Pair.create(specifiers, (x) -> {
9068 try {
9069 if (resultCallback != null) {
9070 resultCallback.accept(x);
9071 }
9072 } catch (RemoteException e) {
9073 // ignore
9074 }
9075 });
9076 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9077 } finally {
9078 Binder.restoreCallingIdentity(token);
9079 }
9080 }
9081
9082 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009083 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9084 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07009085 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08009086 mApp, subId, "getSystemSelectionChannels");
9087 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9088 final long identity = Binder.clearCallingIdentity();
9089 try {
Sarah Chin58691872021-03-13 03:17:40 -08009090 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9091 if (result instanceof IllegalStateException) {
9092 throw (IllegalStateException) result;
9093 }
9094 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chincc055732020-11-18 13:39:35 -08009095 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9096 return specifiers;
9097 } finally {
9098 Binder.restoreCallingIdentity(identity);
9099 }
9100 }
9101
9102 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009103 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009104 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009105 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9106 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9107 if (iccRecords == null) {
9108 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9109 return false;
9110 }
9111 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9112 }
9113
9114 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009115 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9116 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009117 if (callingPackage == null) {
9118 callingPackage = getCurrentPackageName();
9119 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009120 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9121 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009122 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9123 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009124 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9125 }
9126 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9127 Intent intent = new Intent();
9128 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9129 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9130 // Bring up choose default SMS subscription dialog right now
9131 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9132 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9133 mApp.startActivity(intent);
9134 }
chen xud5ca2d52019-05-28 15:20:57 -07009135
9136 @Override
9137 public String getMmsUAProfUrl(int subId) {
9138 //TODO investigate if this API should require proper permission check in R b/133791609
9139 final long identity = Binder.clearCallingIdentity();
9140 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009141 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9142 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9143 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9144 return carrierUAProfUrl;
9145 }
chen xud5ca2d52019-05-28 15:20:57 -07009146 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9147 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9148 } finally {
9149 Binder.restoreCallingIdentity(identity);
9150 }
9151 }
9152
9153 @Override
9154 public String getMmsUserAgent(int subId) {
9155 //TODO investigate if this API should require proper permission check in R b/133791609
9156 final long identity = Binder.clearCallingIdentity();
9157 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009158 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9159 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9160 if (!TextUtils.isEmpty(carrierUserAgent)) {
9161 return carrierUserAgent;
9162 }
chen xud5ca2d52019-05-28 15:20:57 -07009163 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9164 .getString(com.android.internal.R.string.config_mms_user_agent);
9165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
9168 }
Jack Yub07d4972019-05-28 16:12:25 -07009169
9170 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009171 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9172 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9173
9174 final long identity = Binder.clearCallingIdentity();
9175 try {
9176 Phone phone = getPhone(subscriptionId);
9177 if (phone == null) return false;
9178
9179 switch (policy) {
9180 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9181 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9182 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9183 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9184 default:
9185 throw new IllegalArgumentException(policy + " is not a valid policy");
9186 }
9187 } finally {
9188 Binder.restoreCallingIdentity(identity);
9189 }
9190 }
9191
9192 @Override
9193 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9194 boolean enabled) {
9195 enforceModifyPermission();
9196
9197 final long identity = Binder.clearCallingIdentity();
9198 try {
9199 Phone phone = getPhone(subscriptionId);
9200 if (phone == null) return;
9201
9202 switch (policy) {
9203 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9204 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9205 break;
9206 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9207 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9208 break;
9209 default:
9210 throw new IllegalArgumentException(policy + " is not a valid policy");
9211 }
9212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
9215 }
9216
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009217 /**
Hall Liub48cf452020-09-25 11:13:49 -07009218 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009219 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9220 * otherwise.
9221 */
9222 @Override
9223 public void setCepEnabled(boolean isCepEnabled) {
9224 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9225
9226 final long identity = Binder.clearCallingIdentity();
9227 try {
9228 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9229 for (Phone phone : PhoneFactory.getPhones()) {
9230 Phone defaultPhone = phone.getImsPhone();
9231 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9232 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9233 ImsPhoneCallTracker imsPhoneCallTracker =
9234 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9235 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9236 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9237 + imsPhone.getMsisdn());
9238 }
9239 }
9240 } finally {
9241 Binder.restoreCallingIdentity(identity);
9242 }
9243 }
allenwtsu46dcc572020-01-08 18:24:03 +08009244
9245 /**
9246 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9247 *
9248 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9249 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9250 * before being read.
9251 */
9252 @Override
9253 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9254 isCompressed) {
9255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9256 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009257 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9258 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9259 }
9260 if (!isImsAvailableOnDevice()) {
9261 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9262 "IMS not available on device.");
9263 }
9264
9265 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009266 try {
Hui Wang068ab862020-10-31 05:12:53 +00009267 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9268 } finally {
9269 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009270 }
9271 }
zoey chenf95ca592019-12-30 16:11:23 +08009272
9273 @Override
9274 public boolean isIccLockEnabled(int subId) {
9275 enforceReadPrivilegedPermission("isIccLockEnabled");
9276
9277 // Now that all security checks passes, perform the operation as ourselves.
9278 final long identity = Binder.clearCallingIdentity();
9279 try {
9280 Phone phone = getPhone(subId);
9281 if (phone != null && phone.getIccCard() != null) {
9282 return phone.getIccCard().getIccLockEnabled();
9283 } else {
9284 return false;
9285 }
9286 } finally {
9287 Binder.restoreCallingIdentity(identity);
9288 }
9289 }
9290
9291 /**
zoey chene02881a2019-12-30 16:11:23 +08009292 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009293 *
zoey chene02881a2019-12-30 16:11:23 +08009294 * @return an integer representing the status of IccLock enabled or disabled in the following
9295 * three cases:
9296 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9297 * successfully.
9298 * - Positive number and zero for remaining password attempts.
9299 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009300 *
9301 */
9302 @Override
9303 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9304 enforceModifyPermission();
9305
9306 Phone phone = getPhone(subId);
9307 if (phone == null) {
9308 return 0;
9309 }
9310 // Now that all security checks passes, perform the operation as ourselves.
9311 final long identity = Binder.clearCallingIdentity();
9312 try {
9313 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9314 new Pair<Boolean, String>(enabled, password), phone, null);
9315 return attemptsRemaining;
9316
9317 } catch (Exception e) {
9318 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9319 } finally {
9320 Binder.restoreCallingIdentity(identity);
9321 }
9322 return 0;
9323 }
9324
9325 /**
9326 * Change the ICC password used in ICC pin lock.
9327 *
zoey chene02881a2019-12-30 16:11:23 +08009328 * @return an integer representing the status of IccLock changed in the following three cases:
9329 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9330 * - Positive number and zero for remaining password attempts.
9331 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009332 *
9333 */
9334 @Override
9335 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9336 enforceModifyPermission();
9337
9338 Phone phone = getPhone(subId);
9339 if (phone == null) {
9340 return 0;
9341 }
9342 // Now that all security checks passes, perform the operation as ourselves.
9343 final long identity = Binder.clearCallingIdentity();
9344 try {
9345 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9346 new Pair<String, String>(oldPassword, newPassword), phone, null);
9347 return attemptsRemaining;
9348
9349 } catch (Exception e) {
9350 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9351 } finally {
9352 Binder.restoreCallingIdentity(identity);
9353 }
9354 return 0;
9355 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009356
Peter Wangdafb9ac2020-01-15 14:13:38 -08009357 /**
9358 * Request for receiving user activity notification
9359 */
9360 @Override
9361 public void requestUserActivityNotification() {
9362 if (!mNotifyUserActivity.get()
9363 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9364 mNotifyUserActivity.set(true);
9365 }
9366 }
9367
9368 /**
9369 * Called when userActivity is signalled in the power manager.
9370 * This is safe to call from any thread, with any window manager locks held or not.
9371 */
9372 @Override
9373 public void userActivity() {
9374 // ***************************************
9375 // * Inherited from PhoneWindowManager *
9376 // ***************************************
9377 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9378 // WITH ITS LOCKS HELD.
9379 //
9380 // This code must be VERY careful about the locks
9381 // it acquires.
9382 // In fact, the current code acquires way too many,
9383 // and probably has lurking deadlocks.
9384
9385 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9386 throw new SecurityException("Only the OS may call notifyUserActivity()");
9387 }
9388
9389 if (mNotifyUserActivity.getAndSet(false)) {
9390 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9391 USER_ACTIVITY_NOTIFICATION_DELAY);
9392 }
9393 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009394
Malcolm Chen884180b2020-04-13 11:59:40 -07009395 @Override
9396 public boolean canConnectTo5GInDsdsMode() {
9397 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9398 }
Jack Yud10cdd42020-09-28 20:28:01 -07009399
9400 @Override
9401 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9402 String callingFeatureId) {
9403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9404 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9405 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9406 }
9407
9408 Phone phone = getPhone(subId);
9409 if (phone == null) {
9410 throw new RuntimeException("phone is not available");
9411 }
9412 // Now that all security checks passes, perform the operation as ourselves.
9413 final long identity = Binder.clearCallingIdentity();
9414 try {
9415 return phone.getEquivalentHomePlmns();
9416 } finally {
9417 Binder.restoreCallingIdentity(identity);
9418 }
9419 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009420
Hui Wang0866fcc2020-10-12 12:14:23 -07009421 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009422 public boolean isRadioInterfaceCapabilitySupported(
9423 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009424 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009425 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009426 if (radioInterfaceCapabilities == null) {
9427 throw new RuntimeException("radio interface capabilities are not available");
9428 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009429 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009430 }
9431 }
9432
9433 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009434 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9435 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009436 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9437 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9438 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9439 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9440 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009441 if (DBG) {
9442 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9443 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9444 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9445 }
9446
9447 if (!SubscriptionManager.isValidSubscriptionId(subId)
9448 || appType < TelephonyManager.APPTYPE_UNKNOWN
9449 || appType > TelephonyManager.APPTYPE_ISIM
9450 || nafUrl == null || securityProtocol == null || callback == null) {
9451 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9452 if (callback != null) {
9453 try {
9454 callback.onAuthenticationFailure(
9455 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9456 } catch (RemoteException exception) {
9457 log("Fail to notify onAuthenticationFailure due to " + exception);
9458 }
9459 return;
9460 }
9461 }
9462
9463 final long token = Binder.clearCallingIdentity();
9464 try {
9465 getGbaManager(subId).bootstrapAuthenticationRequest(
9466 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9467 forceBootStrapping, callback));
9468 } finally {
9469 Binder.restoreCallingIdentity(token);
9470 }
9471 }
9472
Jack Nudelman24d51a52020-11-24 12:08:04 -08009473 /**
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009474 * Attempts to set the radio power state for all phones for thermal reason.
9475 * This does not guarantee that the
Jack Nudelman24d51a52020-11-24 12:08:04 -08009476 * requested radio power state will actually be set. See {@link
9477 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9478 *
Jack Nudelman24d51a52020-11-24 12:08:04 -08009479 * @param enable {@code true} if trying to turn radio on.
9480 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9481 * false}.
9482 */
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009483 private boolean setRadioPowerForThermal(boolean enable) {
9484 boolean isPhoneAvailable = false;
9485 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9486 Phone phone = PhoneFactory.getPhone(i);
9487 if (phone != null) {
9488 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9489 isPhoneAvailable = true;
9490 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009491 }
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009492
9493 // return true if successfully informed the phone object about the thermal radio power
9494 // request.
9495 return isPhoneAvailable;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009496 }
9497
9498 private int handleDataThrottlingRequest(int subId,
9499 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009500 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9501 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9502 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9503 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9504 throw new IllegalArgumentException("modem does not support data throttling");
9505 }
9506
Jack Nudelman24d51a52020-11-24 12:08:04 -08009507 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9508 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009509 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009510 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9511 }
9512
9513 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9514
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009515 if (isDataThrottlingSupported) {
9516 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009517 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009518 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9519 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9520 } else if (thermalMitigationResult
9521 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman20352592021-05-20 13:57:30 -07009522 log("Modem likely does not support data throttling on secondary carrier. Data " +
9523 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9524 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009525 }
9526 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009527 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009528
9529 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009530 }
9531
Jack Nudelman644b91a2021-03-12 14:09:48 -08009532 private static List<String> getThermalMitigationAllowlist(Context context) {
9533 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9534 for (String pckg : context.getResources()
9535 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9536 sThermalMitigationAllowlistedPackages.add(pckg);
9537 }
9538 }
9539
9540 return sThermalMitigationAllowlistedPackages;
9541 }
9542
Jack Nudelmane634f962021-05-13 10:00:15 -07009543 private boolean isAnyPhoneInEmergencyState() {
9544 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9545 if (tm.isInEmergencyCall()) {
9546 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9547 return true;
9548 }
9549 for (Phone phone : PhoneFactory.getPhones()) {
9550 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9551 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9552 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9553 + phone.isInEcm());
9554 return true;
9555 }
9556 }
9557
9558 return false;
9559 }
9560
Jack Nudelman644b91a2021-03-12 14:09:48 -08009561 /**
9562 * Used by shell commands to add an authorized package name for thermal mitigation.
9563 * @param packageName name of package to be allowlisted
9564 * @param context
9565 */
9566 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9567 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9568 sThermalMitigationAllowlistedPackages.add(packageName);
9569 }
9570
9571 /**
9572 * Used by shell commands to remove an authorized package name for thermal mitigation.
9573 * @param packageName name of package to remove from allowlist
9574 * @param context
9575 */
9576 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9577 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9578 sThermalMitigationAllowlistedPackages.remove(packageName);
9579 }
9580
Jack Nudelman24d51a52020-11-24 12:08:04 -08009581 /**
9582 * Thermal mitigation request to control functionalities at modem.
9583 *
9584 * @param subId the id of the subscription.
9585 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009586 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009587 *
9588 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9589 */
9590 @Override
9591 @ThermalMitigationResult
9592 public int sendThermalMitigationRequest(
9593 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009594 ThermalMitigationRequest thermalMitigationRequest,
9595 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009596 enforceModifyPermission();
9597
Jack Nudelman644b91a2021-03-12 14:09:48 -08009598 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9599 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9600 .contains(callingPackage)) {
9601 throw new SecurityException("Calling package must be configured in the device config. "
9602 + "calling package: " + callingPackage);
9603 }
9604
Jack Nudelman24d51a52020-11-24 12:08:04 -08009605 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9606 final long identity = Binder.clearCallingIdentity();
9607
9608 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9609 try {
9610 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9611 switch (thermalMitigationAction) {
9612 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9613 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009614 handleDataThrottlingRequest(subId,
9615 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009616 break;
9617 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9618 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9619 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9620 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9621 }
9622
9623 // Ensure that radio is on. If not able to power on due to phone being
9624 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009625 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009626 thermalMitigationResult =
9627 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9628 break;
9629 }
9630
9631 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9632 false);
9633 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9634 break;
9635 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9636 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9637 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9638 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9639 }
9640
9641 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9642 if (registry != null) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009643 Phone phone = getPhone(subId);
9644 if (phone == null) {
9645 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009646 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009647 break;
9648 }
9649
Jack Nudelmane634f962021-05-13 10:00:15 -07009650 TelephonyConnectionService service =
9651 registry.getTelephonyConnectionService();
Jack Nudelmana80c0012021-06-17 15:39:58 -07009652 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane634f962021-05-13 10:00:15 -07009653 Log.e(LOG_TAG, "An emergency call is pending");
9654 thermalMitigationResult =
9655 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9656 break;
9657 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009658 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009659 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009660 break;
9661 }
9662 } else {
9663 thermalMitigationResult =
9664 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9665 break;
9666 }
9667
9668 // Turn radio off. If not able to power off due to phone being unavailable,
9669 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009670 if (!setRadioPowerForThermal(false)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009671 thermalMitigationResult =
9672 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9673 break;
9674 }
9675 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009676 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009677 break;
9678 default:
9679 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9680 + "not exist. Requested action: " + thermalMitigationAction);
9681 }
9682 } catch (IllegalArgumentException e) {
9683 throw e;
9684 } catch (Exception e) {
9685 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9686 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690
9691 if (DBG) {
9692 log("thermalMitigationRequest returning with thermalMitigationResult: "
9693 + thermalMitigationResult);
9694 }
9695
9696 return thermalMitigationResult;
9697 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009698
9699 /**
9700 * Set the GbaService Package Name that Telephony will bind to.
9701 *
9702 * @param subId The sim that the GbaService is associated with.
9703 * @param packageName The name of the package to be replaced with.
9704 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9705 */
9706 @Override
9707 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9708 enforceModifyPermission();
9709
9710 final long identity = Binder.clearCallingIdentity();
9711 try {
9712 return getGbaManager(subId).overrideServicePackage(packageName);
9713 } finally {
9714 Binder.restoreCallingIdentity(identity);
9715 }
9716 }
9717
9718 /**
9719 * Return the package name of the currently bound GbaService.
9720 *
9721 * @param subId The sim that the GbaService is associated with.
9722 * @return the package name of the GbaService configuration, null if GBA is not supported.
9723 */
9724 @Override
9725 public String getBoundGbaService(int subId) {
9726 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9727
9728 final long identity = Binder.clearCallingIdentity();
9729 try {
9730 return getGbaManager(subId).getServicePackage();
9731 } finally {
9732 Binder.restoreCallingIdentity(identity);
9733 }
9734 }
9735
9736 /**
9737 * Set the release time for telephony to unbind GbaService.
9738 *
9739 * @param subId The sim that the GbaService is associated with.
9740 * @param interval The release time to unbind GbaService by millisecond.
9741 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9742 */
9743 @Override
9744 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9745 enforceModifyPermission();
9746
9747 final long identity = Binder.clearCallingIdentity();
9748 try {
9749 return getGbaManager(subId).overrideReleaseTime(interval);
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
9752 }
9753 }
9754
9755 /**
9756 * Return the release time for telephony to unbind GbaService.
9757 *
9758 * @param subId The sim that the GbaService is associated with.
9759 * @return The release time to unbind GbaService by millisecond.
9760 */
9761 @Override
9762 public int getGbaReleaseTime(int subId) {
9763 enforceReadPrivilegedPermission("getGbaReleaseTime");
9764
9765 final long identity = Binder.clearCallingIdentity();
9766 try {
9767 return getGbaManager(subId).getReleaseTime();
9768 } finally {
9769 Binder.restoreCallingIdentity(identity);
9770 }
9771 }
9772
9773 private GbaManager getGbaManager(int subId) {
9774 GbaManager instance = GbaManager.getInstance(subId);
9775 if (instance == null) {
9776 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9777 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9778 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9779 }
9780 return instance;
9781 }
Hui Wang068ab862020-10-31 05:12:53 +00009782
9783 /**
9784 * indicate whether the device and the carrier can support
9785 * RCS VoLTE single registration.
9786 */
9787 @Override
9788 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009789 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9790 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9791 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9792 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009793
9794 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9795 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9796 }
9797
9798 final long identity = Binder.clearCallingIdentity();
9799 try {
9800 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9801 if (rpm != null) {
Hui Wang048c10a2021-06-21 18:05:57 +00009802 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
9803 if (isCapable != null) {
9804 return isCapable;
9805 }
Hui Wang068ab862020-10-31 05:12:53 +00009806 }
Hui Wang048c10a2021-06-21 18:05:57 +00009807 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
9808 "service is temporarily unavailable.");
Hui Wang068ab862020-10-31 05:12:53 +00009809 } finally {
9810 Binder.restoreCallingIdentity(identity);
9811 }
9812 }
9813
9814 /**
9815 * Register RCS provisioning callback.
9816 */
9817 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009818 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009819 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009820 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009821 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009822 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9823 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009824
9825 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9826 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9827 }
9828 if (!isImsAvailableOnDevice()) {
9829 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9830 "IMS not available on device.");
9831 }
9832
9833 final long identity = Binder.clearCallingIdentity();
9834 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009835 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009836 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009837 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9838 "Service not available for the subscription.");
9839 }
Hui Wang068ab862020-10-31 05:12:53 +00009840 } finally {
9841 Binder.restoreCallingIdentity(identity);
9842 }
9843 }
9844
9845 /**
9846 * Unregister RCS provisioning callback.
9847 */
9848 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009849 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009850 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009851 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009852 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009853 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9854 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009855
9856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9857 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9858 }
9859 if (!isImsAvailableOnDevice()) {
9860 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9861 "IMS not available on device.");
9862 }
9863
9864 final long identity = Binder.clearCallingIdentity();
9865 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009866 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009867 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009868 } finally {
9869 Binder.restoreCallingIdentity(identity);
9870 }
9871 }
9872
9873 /**
9874 * trigger RCS reconfiguration.
9875 */
9876 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009877 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9878 "triggerRcsReconfiguration",
9879 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009880
9881 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9882 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9883 }
9884 if (!isImsAvailableOnDevice()) {
9885 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9886 "IMS not available on device.");
9887 }
9888
9889 final long identity = Binder.clearCallingIdentity();
9890 try {
9891 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9892 } finally {
9893 Binder.restoreCallingIdentity(identity);
9894 }
9895 }
9896
9897 /**
9898 * Provide the client configuration parameters of the RCS application.
9899 */
9900 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009901 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9902 "setRcsClientConfiguration",
9903 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009904
9905 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9906 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9907 }
9908 if (!isImsAvailableOnDevice()) {
9909 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9910 "IMS not available on device.");
9911 }
9912
9913 final long identity = Binder.clearCallingIdentity();
9914
9915 try {
9916 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9917 if (configBinder == null) {
9918 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9919 } else {
9920 configBinder.setRcsClientConfiguration(rcc);
9921 }
9922 } catch (RemoteException e) {
9923 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9924 } finally {
9925 Binder.restoreCallingIdentity(identity);
9926 }
9927 }
9928
9929 /**
Hui Wang19a21872021-02-19 20:45:36 -08009930 * Enables or disables the test mode for RCS VoLTE single registration.
9931 */
9932 @Override
9933 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9934 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9935 "setRcsSingleRegistrationTestModeEnabled");
9936
9937 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9938 }
9939
9940 /**
9941 * Gets the test mode for RCS VoLTE single registration.
9942 */
9943 @Override
9944 public boolean getRcsSingleRegistrationTestModeEnabled() {
9945 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9946 "getRcsSingleRegistrationTestModeEnabled");
9947
9948 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9949 }
9950
9951 /**
Hui Wang068ab862020-10-31 05:12:53 +00009952 * Overrides the config of RCS VoLTE single registration enabled for the device.
9953 */
9954 @Override
9955 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9956 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9957 "setDeviceSingleRegistrationEnabledOverride");
9958 enforceModifyPermission();
9959
9960 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9961 : Boolean.parseBoolean(enabledStr);
9962 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009963 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009964 }
9965
9966 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009967 * Sends a device to device communication message. Only usable via shell.
9968 * @param message message to send.
9969 * @param value message value.
9970 */
9971 @Override
9972 public void sendDeviceToDeviceMessage(int message, int value) {
9973 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9974 "setCarrierSingleRegistrationEnabledOverride");
9975 enforceModifyPermission();
9976
9977 final long identity = Binder.clearCallingIdentity();
9978 try {
9979 TelephonyConnectionService service =
9980 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9981 if (service == null) {
9982 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9983 return;
9984 }
9985 service.sendTestDeviceToDeviceMessage(message, value);
9986 } finally {
9987 Binder.restoreCallingIdentity(identity);
9988 }
9989 }
9990
9991
9992 /**
Hui Wang068ab862020-10-31 05:12:53 +00009993 * Gets the config of RCS VoLTE single registration enabled for the device.
9994 */
9995 @Override
9996 public boolean getDeviceSingleRegistrationEnabled() {
9997 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9998 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9999 }
10000
10001 /**
10002 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10003 */
10004 @Override
10005 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10006 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10007 "setCarrierSingleRegistrationEnabledOverride");
10008 enforceModifyPermission();
10009
10010 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10011 : Boolean.parseBoolean(enabledStr);
10012 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10013 subId, enabled);
10014 }
10015
10016 /**
10017 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10018 */
10019 @Override
10020 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10021 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10022 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10023 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010024
10025 /**
Hui Wangeadb2562021-02-26 09:33:38 -080010026 * Overrides the ims feature validation result
10027 */
10028 @Override
10029 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10030 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10031 "setImsFeatureValidationOverride");
10032
10033 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10034 : Boolean.parseBoolean(enabledStr);
10035 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10036 subId, enabled);
10037 }
10038
10039 /**
10040 * Gets the ims feature validation override value
10041 */
10042 @Override
10043 public boolean getImsFeatureValidationOverride(int subId) {
10044 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10045 "getImsFeatureValidationOverride");
10046 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10047 }
10048
10049 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010050 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10051 * their mobile plan.
10052 */
10053 @Override
10054 public String getMobileProvisioningUrl() {
10055 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10056 final long identity = Binder.clearCallingIdentity();
10057 try {
10058 return getDefaultPhone().getMobileProvisioningUrl();
10059 } finally {
10060 Binder.restoreCallingIdentity(identity);
10061 }
10062 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010063
James.cf Linbcdf8b32021-01-14 16:44:13 +080010064 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010065 * Get the EAB contact from the EAB database.
10066 */
10067 @Override
10068 public String getContactFromEab(String contact) {
10069 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10070 enforceModifyPermission();
10071 final long identity = Binder.clearCallingIdentity();
10072 try {
10073 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10074 } finally {
10075 Binder.restoreCallingIdentity(identity);
10076 }
10077 }
10078
10079 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010080 * Remove the EAB contacts from the EAB database.
10081 */
10082 @Override
10083 public int removeContactFromEab(int subId, String contacts) {
10084 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10085 enforceModifyPermission();
10086 final long identity = Binder.clearCallingIdentity();
10087 try {
10088 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10089 } finally {
10090 Binder.restoreCallingIdentity(identity);
10091 }
10092 }
10093
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010094 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010095 public boolean getDeviceUceEnabled() {
10096 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10097 final long identity = Binder.clearCallingIdentity();
10098 try {
10099 return mApp.getDeviceUceEnabled();
10100 } finally {
10101 Binder.restoreCallingIdentity(identity);
10102 }
10103 }
10104
10105 @Override
10106 public void setDeviceUceEnabled(boolean isEnabled) {
10107 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10108 final long identity = Binder.clearCallingIdentity();
10109 try {
10110 mApp.setDeviceUceEnabled(isEnabled);
10111 } finally {
10112 Binder.restoreCallingIdentity(identity);
10113 }
10114 }
10115
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010116 /**
10117 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10118 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10119 */
10120 // Used for SHELL command only right now.
10121 @Override
10122 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10123 List<String> featureTags) {
10124 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10125 "addUceRegistrationOverrideShell");
10126 final long identity = Binder.clearCallingIdentity();
10127 try {
10128 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10129 new ArraySet<>(featureTags));
10130 } catch (ImsException e) {
10131 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10132 } finally {
10133 Binder.restoreCallingIdentity(identity);
10134 }
10135 }
10136
10137 /**
10138 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10139 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10140 */
10141 // Used for SHELL command only right now.
10142 @Override
10143 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10144 List<String> featureTags) {
10145 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10146 "removeUceRegistrationOverrideShell");
10147 final long identity = Binder.clearCallingIdentity();
10148 try {
10149 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10150 new ArraySet<>(featureTags));
10151 } catch (ImsException e) {
10152 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10153 } finally {
10154 Binder.restoreCallingIdentity(identity);
10155 }
10156 }
10157
10158 /**
10159 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10160 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10161 */
10162 // Used for SHELL command only right now.
10163 @Override
10164 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10165 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10166 "clearUceRegistrationOverrideShell");
10167 final long identity = Binder.clearCallingIdentity();
10168 try {
10169 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10170 } catch (ImsException e) {
10171 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10172 } finally {
10173 Binder.restoreCallingIdentity(identity);
10174 }
10175 }
10176
10177 /**
10178 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10179 */
10180 // Used for SHELL command only right now.
10181 @Override
10182 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10183 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10184 "getLatestRcsContactUceCapabilityShell");
10185 final long identity = Binder.clearCallingIdentity();
10186 try {
10187 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10188 } catch (ImsException e) {
10189 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10190 } finally {
10191 Binder.restoreCallingIdentity(identity);
10192 }
10193 }
10194
10195 /**
10196 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10197 * device does not have an active PUBLISH.
10198 */
10199 // Used for SHELL command only right now.
10200 @Override
10201 public String getLastUcePidfXmlShell(int subId) {
10202 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10203 final long identity = Binder.clearCallingIdentity();
10204 try {
10205 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10206 } catch (ImsException e) {
10207 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10208 } finally {
10209 Binder.restoreCallingIdentity(identity);
10210 }
10211 }
10212
James.cf Line8713a42021-04-29 16:04:26 +080010213 /**
10214 * Remove UCE requests cannot be sent to the network status.
10215 */
10216 // Used for SHELL command only right now.
10217 @Override
10218 public boolean removeUceRequestDisallowedStatus(int subId) {
10219 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
10222 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10223 } catch (ImsException e) {
10224 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10225 } finally {
10226 Binder.restoreCallingIdentity(identity);
10227 }
10228 }
10229
James.cf Lin18bb9002021-05-25 01:37:38 +080010230 /**
10231 * Remove UCE requests cannot be sent to the network status.
10232 */
10233 // Used for SHELL command only.
10234 @Override
10235 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10237 final long identity = Binder.clearCallingIdentity();
10238 try {
10239 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10240 } catch (ImsException e) {
10241 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10242 } finally {
10243 Binder.restoreCallingIdentity(identity);
10244 }
10245 }
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010246
James.cf Lin4b784aa2021-01-31 03:25:15 +080010247 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010248 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10249 String callingPackage) {
10250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10251 mApp, subId, "setSignalStrengthUpdateRequest");
10252
10253 final int callingUid = Binder.getCallingUid();
10254 // Verify that tha callingPackage belongs to the calling UID
10255 mApp.getSystemService(AppOpsManager.class)
10256 .checkPackage(callingUid, callingPackage);
10257
10258 validateSignalStrengthUpdateRequest(request, callingUid);
10259
10260 final long identity = Binder.clearCallingIdentity();
10261 try {
10262 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10263 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10264
10265 if (result instanceof IllegalStateException) {
10266 throw (IllegalStateException) result;
10267 }
10268 } finally {
10269 Binder.restoreCallingIdentity(identity);
10270 }
10271 }
10272
10273 @Override
10274 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10275 String callingPackage) {
10276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10277 mApp, subId, "clearSignalStrengthUpdateRequest");
10278
10279 final int callingUid = Binder.getCallingUid();
10280 // Verify that tha callingPackage belongs to the calling UID
10281 mApp.getSystemService(AppOpsManager.class)
10282 .checkPackage(callingUid, callingPackage);
10283
10284 final long identity = Binder.clearCallingIdentity();
10285 try {
10286 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10287 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10288
10289 if (result instanceof IllegalStateException) {
10290 throw (IllegalStateException) result;
10291 }
10292 } finally {
10293 Binder.restoreCallingIdentity(identity);
10294 }
10295 }
10296
10297 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10298 int callingUid) {
10299 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10300 // phone/system process do not have further restriction on request
10301 return;
10302 }
10303
10304 // Applications has restrictions on how to use the request:
10305 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10306 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10307 // This is not system caller which has been checked above
10308 throw new IllegalArgumentException(
10309 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10310 }
10311
10312 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10313 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10314 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10315 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10316 || info.isEnabled()) {
10317 throw new IllegalArgumentException(
10318 "Only system can set hide fields in SignalThresholdInfo");
10319 }
10320
10321 // Thresholds length for each RAN need in range. This has been validated in
10322 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10323 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10324 final int[] thresholds = info.getThresholds();
10325 Objects.requireNonNull(thresholds);
10326 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10327 || thresholds.length
10328 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10329 throw new IllegalArgumentException(
10330 "thresholds length is out of range: " + thresholds.length);
10331 }
10332 }
10333 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010334
10335 /**
10336 * Prepare TelephonyManager for an unattended reboot. The reboot is
10337 * required to be done shortly after the API is invoked.
10338 */
10339 @Override
10340 @TelephonyManager.PrepareUnattendedRebootResult
10341 public int prepareForUnattendedReboot() {
Rafael Higuera Silvacd3aef22021-08-30 15:16:50 +000010342 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionned9fbae52020-11-13 02:36:59 +000010343 enforceRebootPermission();
10344
10345 final long identity = Binder.clearCallingIdentity();
10346 try {
Rafael Higuera Silvacd3aef22021-08-30 15:16:50 +000010347 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionned9fbae52020-11-13 02:36:59 +000010348 } finally {
10349 Binder.restoreCallingIdentity(identity);
10350 }
10351 }
SongFerngWang2c4309d2021-01-17 21:51:44 +080010352
10353 /**
10354 * Gets the current phone capability.
10355 *
10356 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10357 * @return the PhoneCapability which describes the data connection capability of modem.
10358 * It's used to evaluate possible phone config change, for example from single
10359 * SIM device to multi-SIM device.
10360 */
10361 @Override
10362 public PhoneCapability getPhoneCapability() {
10363 enforceReadPrivilegedPermission("getPhoneCapability");
10364 final long identity = Binder.clearCallingIdentity();
10365 try {
10366 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10367 } finally {
10368 Binder.restoreCallingIdentity(identity);
10369 }
10370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010371}