blob: 8d946f5987418b2b8bb1e0d8c229b4f1b3f3c7c9 [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 =
1903 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1904 notifyRequester(request);
1905 break;
1906
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 default:
1908 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1909 break;
1910 }
1911 }
Jake Hambye994d462014-02-03 13:10:13 -08001912
Pengquan Menga1bb6272018-09-06 09:59:22 -07001913 private void notifyRequester(MainThreadRequest request) {
1914 synchronized (request) {
1915 request.notifyAll();
1916 }
1917 }
1918
Jake Hambye994d462014-02-03 13:10:13 -08001919 private void handleNullReturnEvent(Message msg, String command) {
1920 AsyncResult ar = (AsyncResult) msg.obj;
1921 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1922 if (ar.exception == null) {
1923 request.result = true;
1924 } else {
1925 request.result = false;
1926 if (ar.exception instanceof CommandException) {
1927 loge(command + ": CommandException: " + ar.exception);
1928 } else {
1929 loge(command + ": Unknown exception");
1930 }
1931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001932 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 }
1935
1936 /**
1937 * Posts the specified command to be executed on the main thread,
1938 * waits for the request to complete, and returns the result.
1939 * @see #sendRequestAsync
1940 */
1941 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001942 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1943 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001944 }
1945
1946 /**
1947 * Posts the specified command to be executed on the main thread,
1948 * waits for the request to complete, and returns the result.
1949 * @see #sendRequestAsync
1950 */
1951 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1952 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001953 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001954 }
1955
1956 /**
1957 * Posts the specified command to be executed on the main thread,
1958 * waits for the request to complete, and returns the result.
1959 * @see #sendRequestAsync
1960 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001961 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001962 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1963 }
1964
1965 /**
1966 * Posts the specified command to be executed on the main thread,
1967 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1968 * if not timeout or null otherwise.
1969 * @see #sendRequestAsync
1970 */
1971 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1972 long timeoutInMs) {
1973 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001974 }
1975
1976 /**
1977 * Posts the specified command to be executed on the main thread,
1978 * waits for the request to complete, and returns the result.
1979 * @see #sendRequestAsync
1980 */
Nathan Harold92bed182018-10-12 18:16:49 -07001981 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001982 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001983 }
1984
1985 /**
1986 * Posts the specified command to be executed on the main thread,
1987 * waits for the request to complete, and returns the result.
1988 * @see #sendRequestAsync
1989 */
1990 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001991 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1992 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001993 }
1994
1995 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001996 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1997 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1998 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001999 * @see #sendRequestAsync
2000 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002001 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2002 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2004 throw new RuntimeException("This method will deadlock if called from the main thread.");
2005 }
2006
Nathan Harold92bed182018-10-12 18:16:49 -07002007 MainThreadRequest request = null;
2008 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2009 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2010 } else if (phone != null) {
2011 request = new MainThreadRequest(argument, phone, workSource);
2012 } else {
2013 request = new MainThreadRequest(argument, subId, workSource);
2014 }
2015
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 Message msg = mMainThreadHandler.obtainMessage(command, request);
2017 msg.sendToTarget();
2018
Rambo Wang0f050d82021-02-12 11:43:36 -08002019
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002021 if (timeoutInMs >= 0) {
2022 // Wait for at least timeoutInMs before returning null request result
2023 long now = SystemClock.elapsedRealtime();
2024 long deadline = now + timeoutInMs;
2025 while (request == null && now < deadline) {
2026 try {
2027 request.wait(deadline - now);
2028 } catch (InterruptedException e) {
2029 // Do nothing, go back and check if request is completed or timeout
2030 } finally {
2031 now = SystemClock.elapsedRealtime();
2032 }
2033 }
2034 } else {
2035 // Wait for the request to complete
2036 while (request.result == null) {
2037 try {
2038 request.wait();
2039 } catch (InterruptedException e) {
2040 // Do nothing, go back and wait until the request is complete
2041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 }
2043 }
2044 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002045 if (request.result == null) {
2046 Log.wtf(LOG_TAG,
2047 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 return request.result;
2050 }
2051
2052 /**
2053 * Asynchronous ("fire and forget") version of sendRequest():
2054 * Posts the specified command to be executed on the main thread, and
2055 * returns immediately.
2056 * @see #sendRequest
2057 */
2058 private void sendRequestAsync(int command) {
2059 mMainThreadHandler.sendEmptyMessage(command);
2060 }
2061
2062 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002063 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002064 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002065 */
2066 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002067 sendRequestAsync(command, argument, null, null);
2068 }
2069
2070 /**
2071 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2072 * @see {@link #sendRequest(int,Object)}
2073 */
2074 private void sendRequestAsync(
2075 int command, Object argument, Phone phone, WorkSource workSource) {
2076 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002077 Message msg = mMainThreadHandler.obtainMessage(command, request);
2078 msg.sendToTarget();
2079 }
2080
2081 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 * Initialize the singleton PhoneInterfaceManager instance.
2083 * This is only done once, at startup, from PhoneApp.onCreate().
2084 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002085 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 synchronized (PhoneInterfaceManager.class) {
2087 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002088 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 } else {
2090 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2091 }
2092 return sInstance;
2093 }
2094 }
2095
2096 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002097 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerc9c432e2021-05-17 20:54:49 +00002100 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002101 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2103 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002104 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002105 mTelephonySharedPreferences =
2106 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002107 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002108 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002109 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002110 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002111
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 publish();
2113 }
2114
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002115 private Phone getDefaultPhone() {
2116 Phone thePhone = getPhone(getDefaultSubscription());
2117 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2118 }
2119
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 private void publish() {
2121 if (DBG) log("publish: " + this);
2122
Peter Wangc035ce42020-01-08 21:00:22 -08002123 TelephonyFrameworkInitializer
2124 .getTelephonyServiceManager()
2125 .getTelephonyServiceRegisterer()
2126 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
Stuart Scott584921c2015-01-15 17:10:34 -08002129 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002130 if (request.phone != null) {
2131 return request.phone;
2132 } else {
2133 return getPhoneFromSubId(request.subId);
2134 }
2135 }
2136
2137 private Phone getPhoneFromSubId(int subId) {
2138 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2139 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002140 }
2141
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002142 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2143 Phone phone = getPhoneFromRequest(request);
2144 return phone == null ? null :
2145 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2146 }
2147
Wink Saville36469e72014-06-11 15:17:00 -07002148 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002149 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002150 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002153 private void sendEraseModemConfig(Phone phone) {
2154 if (phone != null) {
2155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2156 mApp, phone.getSubId(), "eraseModemConfig");
2157 final long identity = Binder.clearCallingIdentity();
2158 try {
2159 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2160 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2161 } finally {
2162 Binder.restoreCallingIdentity(identity);
2163 }
2164 }
2165 }
2166
Peter Wang050bb052020-01-13 23:33:09 -08002167 private boolean isImsAvailableOnDevice() {
2168 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2169 if (pm == null) {
2170 // For some reason package manger is not available.. This will fail internally anyway,
2171 // so do not throw error and allow.
2172 return true;
2173 }
2174 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2175 }
2176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002178 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002179 }
2180
Wink Savilleb564aae2014-10-23 10:18:09 -07002181 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 if (DBG) log("dial: " + number);
2183 // No permission check needed here: This is just a wrapper around the
2184 // ACTION_DIAL intent, which is available to any app since it puts up
2185 // the UI before it does anything.
2186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002187 final long identity = Binder.clearCallingIdentity();
2188 try {
2189 String url = createTelUrl(number);
2190 if (url == null) {
2191 return;
2192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002194 // PENDING: should we just silently fail if phone is offhook or ringing?
2195 PhoneConstants.State state = mCM.getState(subId);
2196 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2197 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2198 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2199 mApp.startActivity(intent);
2200 }
2201 } finally {
2202 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 }
2204 }
2205
2206 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002207 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002208 }
2209
Wink Savilleb564aae2014-10-23 10:18:09 -07002210 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 if (DBG) log("call: " + number);
2212
2213 // This is just a wrapper around the ACTION_CALL intent, but we still
2214 // need to do a permission check since we're calling startActivity()
2215 // from the context of the phone app.
2216 enforceCallPermission();
2217
Jordan Liu1617b712019-07-10 15:06:26 -07002218 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 != AppOpsManager.MODE_ALLOWED) {
2220 return;
2221 }
2222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 String url = createTelUrl(number);
2226 if (url == null) {
2227 return;
2228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230 boolean isValid = false;
2231 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2232 if (slist != null) {
2233 for (SubscriptionInfo subInfoRecord : slist) {
2234 if (subInfoRecord.getSubscriptionId() == subId) {
2235 isValid = true;
2236 break;
2237 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002238 }
Wink Saville08874612014-08-31 19:19:58 -07002239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240 if (!isValid) {
2241 return;
2242 }
Wink Saville08874612014-08-31 19:19:58 -07002243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002244 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2245 intent.putExtra(SUBSCRIPTION_KEY, subId);
2246 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2247 mApp.startActivity(intent);
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
2250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
Wink Savilleb564aae2014-10-23 10:18:09 -07002253 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002254 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002255 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2256 }
2257
Wink Savilleb564aae2014-10-23 10:18:09 -07002258 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002259 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002260 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2261 }
2262
Wink Savilleb564aae2014-10-23 10:18:09 -07002263 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002265
2266 final long identity = Binder.clearCallingIdentity();
2267 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002268 Phone phone = getPhone(subId);
2269 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002270 checkSimPin.start();
2271 return checkSimPin.unlockSim(null, pin);
2272 } finally {
2273 Binder.restoreCallingIdentity(identity);
2274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 }
2276
Wink Savilleb564aae2014-10-23 10:18:09 -07002277 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279
2280 final long identity = Binder.clearCallingIdentity();
2281 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002282 Phone phone = getPhone(subId);
2283 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284 checkSimPuk.start();
2285 return checkSimPuk.unlockSim(puk, pin);
2286 } finally {
2287 Binder.restoreCallingIdentity(identity);
2288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 }
2290
2291 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002292 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 * a synchronous one.
2294 */
2295 private static class UnlockSim extends Thread {
2296
2297 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002298 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299
2300 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002301 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2302 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303
2304 // For replies from SimCard interface
2305 private Handler mHandler;
2306
2307 // For async handler to identify request type
2308 private static final int SUPPLY_PIN_COMPLETE = 100;
2309
Michele Berionned9fbae52020-11-13 02:36:59 +00002310 UnlockSim(int phoneId, IccCard simCard) {
2311 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 mSimCard = simCard;
2313 }
2314
2315 @Override
2316 public void run() {
2317 Looper.prepare();
2318 synchronized (UnlockSim.this) {
2319 mHandler = new Handler() {
2320 @Override
2321 public void handleMessage(Message msg) {
2322 AsyncResult ar = (AsyncResult) msg.obj;
2323 switch (msg.what) {
2324 case SUPPLY_PIN_COMPLETE:
2325 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2326 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002327 mRetryCount = msg.arg1;
2328 if (ar.exception != null) {
2329 if (ar.exception instanceof CommandException &&
2330 ((CommandException)(ar.exception)).getCommandError()
2331 == CommandException.Error.PASSWORD_INCORRECT) {
2332 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002333 } //When UiccCardApp dispose,handle message and return exception
2334 else if (ar.exception instanceof CommandException &&
2335 ((CommandException) (ar.exception)).getCommandError()
2336 == CommandException.Error.ABORTED) {
2337 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002338 } else {
2339 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2340 }
2341 } else {
2342 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 mDone = true;
2345 UnlockSim.this.notifyAll();
2346 }
2347 break;
2348 }
2349 }
2350 };
2351 UnlockSim.this.notifyAll();
2352 }
2353 Looper.loop();
2354 }
2355
2356 /*
2357 * Use PIN or PUK to unlock SIM card
2358 *
2359 * If PUK is null, unlock SIM card with PIN
2360 *
2361 * If PUK is not null, unlock SIM card with PUK and set PIN code
2362 */
Wink Saville9de0f752013-10-22 19:04:03 -07002363 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364
2365 while (mHandler == null) {
2366 try {
2367 wait();
2368 } catch (InterruptedException e) {
2369 Thread.currentThread().interrupt();
2370 }
2371 }
2372 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2373
2374 if (puk == null) {
2375 mSimCard.supplyPin(pin, callback);
2376 } else {
2377 mSimCard.supplyPuk(puk, pin, callback);
2378 }
2379
2380 while (!mDone) {
2381 try {
2382 Log.d(LOG_TAG, "wait for done");
2383 wait();
2384 } catch (InterruptedException e) {
2385 // Restore the interrupted status
2386 Thread.currentThread().interrupt();
2387 }
2388 }
2389 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002390 int[] resultArray = new int[2];
2391 resultArray[0] = mResult;
2392 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002393
2394 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2395 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2396 }
2397
Wink Saville9de0f752013-10-22 19:04:03 -07002398 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 }
2400 }
2401
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002402 /**
2403 * This method has been removed due to privacy and stability concerns.
2404 */
2405 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002407 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2408 return;
Wink Saville36469e72014-06-11 15:17:00 -07002409 }
2410
Nathan Harold1f889d82020-06-04 17:05:26 -07002411 @Override
2412 public void updateServiceLocationWithPackageName(String callingPackage) {
2413 mApp.getSystemService(AppOpsManager.class)
2414 .checkPackage(Binder.getCallingUid(), callingPackage);
2415
Nathan Haroldf096d982020-11-18 17:18:06 -08002416 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002417 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2418 // Callers targeting S have no business invoking this method.
2419 return;
2420 }
2421
2422 LocationAccessPolicy.LocationPermissionResult locationResult =
2423 LocationAccessPolicy.checkLocationPermission(mApp,
2424 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2425 .setCallingPackage(callingPackage)
2426 .setCallingFeatureId(null)
2427 .setCallingPid(Binder.getCallingPid())
2428 .setCallingUid(Binder.getCallingUid())
2429 .setMethod("updateServiceLocation")
2430 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2431 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2432 .build());
2433 // Apps that lack location permission have no business calling this method;
2434 // however, because no permission was declared in the public API, denials must
2435 // all be "soft".
2436 switch (locationResult) {
2437 case DENIED_HARD: /* fall through */
2438 case DENIED_SOFT:
2439 return;
2440 }
2441
2442 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443 final long identity = Binder.clearCallingIdentity();
2444 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002445 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002447 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 }
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 }
2453
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002454 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002455 @Override
2456 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002457 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002458 }
2459
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002460
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002461 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002462 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2463 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2464 callingFeatureId);
2465 }
2466
2467 @Deprecated
2468 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002469 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002470 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2471 }
2472
2473 @Override
2474 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2475 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002477 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002478 return false;
2479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480
2481 final long identity = Binder.clearCallingIdentity();
2482 try {
2483 return isRadioOnForSubscriber(subId);
2484 } finally {
2485 Binder.restoreCallingIdentity(identity);
2486 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002487 }
2488
2489 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 final Phone phone = getPhone(subId);
2493 if (phone != null) {
2494 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2495 } else {
2496 return false;
2497 }
2498 } finally {
2499 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502
2503 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002504 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 }
Wink Saville36469e72014-06-11 15:17:00 -07002506
Wink Savilleb564aae2014-10-23 10:18:09 -07002507 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509
2510 final long identity = Binder.clearCallingIdentity();
2511 try {
2512 final Phone phone = getPhone(subId);
2513 if (phone != null) {
2514 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 }
Wink Saville36469e72014-06-11 15:17:00 -07002519 }
2520
2521 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002522 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002523 }
2524
Wink Savilleb564aae2014-10-23 10:18:09 -07002525 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527
2528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 final Phone phone = getPhone(subId);
2531 if (phone == null) {
2532 return false;
2533 }
2534 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2535 toggleRadioOnOffForSubscriber(subId);
2536 }
2537 return true;
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 }
Wink Saville36469e72014-06-11 15:17:00 -07002542
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002543 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002544 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002545 /*
2546 * If any of the Radios are available, it will need to be
2547 * shutdown. So return true if any Radio is available.
2548 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2552 Phone phone = PhoneFactory.getPhone(i);
2553 if (phone != null && phone.isRadioAvailable()) return true;
2554 }
2555 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2556 return false;
2557 } finally {
2558 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002559 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002560 }
2561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002563 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564 enforceModifyPermission();
2565
2566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2569 logv("Shutting down Phone " + i);
2570 shutdownRadioUsingPhoneId(i);
2571 }
2572 } finally {
2573 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002574 }
2575 }
2576
2577 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002578 Phone phone = PhoneFactory.getPhone(phoneId);
2579 if (phone != null && phone.isRadioAvailable()) {
2580 phone.shutdownRadio();
2581 }
2582 }
2583
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002585 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002586
2587 final long identity = Binder.clearCallingIdentity();
2588 try {
2589 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2590 if (defaultPhone != null) {
2591 defaultPhone.setRadioPower(turnOn);
2592 return true;
2593 } else {
2594 loge("There's no default phone.");
2595 return false;
2596 }
2597 } finally {
2598 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002599 }
Wink Saville36469e72014-06-11 15:17:00 -07002600 }
2601
Wink Savilleb564aae2014-10-23 10:18:09 -07002602 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(subId);
2608 if (phone != null) {
2609 phone.setRadioPower(turnOn);
2610 return true;
2611 } else {
2612 return false;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 }
2618
Wink Saville36469e72014-06-11 15:17:00 -07002619 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002620 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 public boolean enableDataConnectivity() {
2622 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 int subId = mSubscriptionController.getDefaultDataSubId();
2627 final Phone phone = getPhone(subId);
2628 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002629 phone.getDataEnabledSettings().setDataEnabled(
2630 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 return true;
2632 } else {
2633 return false;
2634 }
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 }
2639
Wink Saville36469e72014-06-11 15:17:00 -07002640 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002641 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 public boolean disableDataConnectivity() {
2643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644
2645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 int subId = mSubscriptionController.getDefaultDataSubId();
2648 final Phone phone = getPhone(subId);
2649 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002650 phone.getDataEnabledSettings().setDataEnabled(
2651 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 return true;
2653 } else {
2654 return false;
2655 }
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
2660
Sanket Padawe356d7632015-06-22 14:03:32 -07002661 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002662 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
2666 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002667 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 } else {
2669 return false;
2670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002678 }
2679
pkanwarae03a6b2016-11-06 20:37:09 -08002680 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 enforceCallPermission();
2682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2686 return;
2687 }
2688 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2689 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
2692 }
pkanwar32d516d2016-10-14 19:37:38 -07002693 };
2694
Wink Savilleb564aae2014-10-23 10:18:09 -07002695 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697
2698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2701 return false;
2702 }
2703 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 }
2708
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002710 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002711 }
2712
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002713 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 Phone phone = PhoneFactory.getPhone(slotIndex);
2717 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2718 PhoneConstantConversions.convertCallState(phone.getState());
2719 } finally {
2720 Binder.restoreCallingIdentity(identity);
2721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 }
2723
Sanket Padawe356d7632015-06-22 14:03:32 -07002724 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002725 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002726 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2727 }
2728
2729 @Override
2730 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 final long identity = Binder.clearCallingIdentity();
2732 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002733 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 if (phone != null) {
2735 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2736 } else {
2737 return PhoneConstantConversions.convertDataState(
2738 PhoneConstants.DataState.DISCONNECTED);
2739 }
2740 } finally {
2741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 }
2744
Sanket Padawe356d7632015-06-22 14:03:32 -07002745 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002746 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002747 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2748 }
2749
2750 @Override
2751 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752 final long identity = Binder.clearCallingIdentity();
2753 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002754 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 if (phone != null) {
2756 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2757 } else {
2758 return TelephonyManager.DATA_ACTIVITY_NONE;
2759 }
2760 } finally {
2761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 }
2764
2765 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002766 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002767 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002768 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002769
2770 LocationAccessPolicy.LocationPermissionResult locationResult =
2771 LocationAccessPolicy.checkLocationPermission(mApp,
2772 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2773 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002774 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002775 .setCallingPid(Binder.getCallingPid())
2776 .setCallingUid(Binder.getCallingUid())
2777 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002778 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002779 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2780 .build());
2781 switch (locationResult) {
2782 case DENIED_HARD:
2783 throw new SecurityException("Not allowed to access cell location");
2784 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002785 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2786 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 }
2788
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002789 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790 final long identity = Binder.clearCallingIdentity();
2791 try {
2792 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002793 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002794 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795 } finally {
2796 Binder.restoreCallingIdentity(identity);
2797 }
Svetoslav64fad262015-04-14 14:35:21 -07002798 }
2799
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002800 @Override
Jack Yu01425032020-02-22 19:38:58 -08002801 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002802 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2803 // registered cell info, so return a NULL country instead.
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002806 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2807 // Get default phone in this case.
2808 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2809 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002810 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002812 if (phone == null) return "";
2813 ServiceStateTracker sst = phone.getServiceStateTracker();
2814 if (sst == null) return "";
2815 LocaleTracker lt = sst.getLocaleTracker();
2816 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002817 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002818 } finally {
2819 Binder.restoreCallingIdentity(identity);
2820 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002821 }
2822
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002823 /**
2824 * This method was removed due to potential issues caused by performing partial
2825 * updates of service state, and lack of a credible use case.
2826 *
2827 * This has the ability to break the telephony implementation by disabling notification of
2828 * changes in device connectivity. DO NOT USE THIS!
2829 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002830 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 public void enableLocationUpdates() {
2832 mApp.enforceCallingOrSelfPermission(
2833 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 }
2835
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002836 /**
2837 * This method was removed due to potential issues caused by performing partial
2838 * updates of service state, and lack of a credible use case.
2839 *
2840 * This has the ability to break the telephony implementation by disabling notification of
2841 * changes in device connectivity. DO NOT USE THIS!
2842 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 @Override
2844 public void disableLocationUpdates() {
2845 mApp.enforceCallingOrSelfPermission(
2846 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
2849 @Override
2850 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002851 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2852 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002853 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002854 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2855 throw new SecurityException(
2856 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2857 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002858
Jordan Liu1617b712019-07-10 15:06:26 -07002859 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2861 return null;
2862 }
Svetoslav64fad262015-04-14 14:35:21 -07002863
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002864 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002866 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002867 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868
Nathan Haroldf180aac2018-06-01 18:43:55 -07002869 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2870 for (CellInfo ci : info) {
2871 if (ci instanceof CellInfoGsm) {
2872 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2873 } else if (ci instanceof CellInfoWcdma) {
2874 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002877 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878 }
2879
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002880 private List<CellInfo> getCachedCellInfo() {
2881 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2882 for (Phone phone : PhoneFactory.getPhones()) {
2883 List<CellInfo> info = phone.getAllCellInfo();
2884 if (info != null) cellInfos.addAll(info);
2885 }
2886 return cellInfos;
2887 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888
2889 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002890 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002891 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002892 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002893
2894 LocationAccessPolicy.LocationPermissionResult locationResult =
2895 LocationAccessPolicy.checkLocationPermission(mApp,
2896 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2897 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002898 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002899 .setCallingPid(Binder.getCallingPid())
2900 .setCallingUid(Binder.getCallingUid())
2901 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002902 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002903 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2904 .build());
2905 switch (locationResult) {
2906 case DENIED_HARD:
2907 throw new SecurityException("Not allowed to access cell info");
2908 case DENIED_SOFT:
2909 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 }
2911
Nathan Haroldf096d982020-11-18 17:18:06 -08002912 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002913 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2914 return getCachedCellInfo();
2915 }
2916
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002917 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002918 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2922 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002923 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002924 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925 if (info != null) cellInfos.addAll(info);
2926 }
2927 return cellInfos;
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931 }
2932
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002933 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002934 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2935 String callingFeatureId) {
2936 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2937 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002938 }
2939
2940 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002941 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2942 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002943 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002944 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002945 }
2946
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002947 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2948 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002949 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002950 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002951
2952 LocationAccessPolicy.LocationPermissionResult locationResult =
2953 LocationAccessPolicy.checkLocationPermission(mApp,
2954 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2955 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002956 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002957 .setCallingPid(Binder.getCallingPid())
2958 .setCallingUid(Binder.getCallingUid())
2959 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002960 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2961 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002962 .build());
2963 switch (locationResult) {
2964 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002965 if (TelephonyPermissions
2966 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002967 // Safetynet logging for b/154934934
2968 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2969 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002970 throw new SecurityException("Not allowed to access cell info");
2971 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002972 if (TelephonyPermissions
2973 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002974 // Safetynet logging for b/154934934
2975 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2976 }
Nathan Harold5320c422019-05-09 10:26:08 -07002977 try {
2978 cb.onCellInfo(new ArrayList<CellInfo>());
2979 } catch (RemoteException re) {
2980 // Drop without consequences
2981 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002982 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002983 }
2984
Nathan Harolda939a962019-05-09 10:13:47 -07002985
2986 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002987 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2988
2989 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2990 }
2991
2992 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002994 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002995 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002999 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003003 }
3004
Shishir Agrawala9f32182016-04-12 12:00:16 -07003005 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003006 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003007 Phone phone = PhoneFactory.getPhone(slotIndex);
3008 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003009 return null;
3010 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003011 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003012 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003013 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003014 return null;
3015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 return phone.getImei();
3020 } finally {
3021 Binder.restoreCallingIdentity(identity);
3022 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003023 }
3024
3025 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003026 public String getTypeAllocationCodeForSlot(int slotIndex) {
3027 Phone phone = PhoneFactory.getPhone(slotIndex);
3028 String tac = null;
3029 if (phone != null) {
3030 String imei = phone.getImei();
3031 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3032 }
3033 return tac;
3034 }
3035
3036 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003037 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003038 Phone phone = PhoneFactory.getPhone(slotIndex);
3039 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003040 return null;
3041 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003042
Jeff Davidson913390f2018-02-23 17:11:49 -08003043 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003044 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003045 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003046 return null;
3047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 return phone.getMeid();
3052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
Jack Yu2af8d712017-03-15 17:14:14 -07003055 }
3056
3057 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003058 public String getManufacturerCodeForSlot(int slotIndex) {
3059 Phone phone = PhoneFactory.getPhone(slotIndex);
3060 String manufacturerCode = null;
3061 if (phone != null) {
3062 String meid = phone.getMeid();
3063 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3064 }
3065 return manufacturerCode;
3066 }
3067
3068 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003069 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3070 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003071 Phone phone = PhoneFactory.getPhone(slotIndex);
3072 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003073 return null;
3074 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003075 int subId = phone.getSubId();
3076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003077 mApp, subId, callingPackage, callingFeatureId,
3078 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003079 return null;
3080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 return phone.getDeviceSvn();
3085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003088 }
3089
fionaxu43304da2017-11-27 22:51:16 -08003090 @Override
3091 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092 final long identity = Binder.clearCallingIdentity();
3093 try {
3094 final Phone phone = getPhone(subId);
3095 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
fionaxu43304da2017-11-27 22:51:16 -08003099 }
3100
3101 @Override
3102 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 final Phone phone = getPhone(subId);
3106 return phone == null ? null : phone.getCarrierName();
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
fionaxu43304da2017-11-27 22:51:16 -08003110 }
3111
calvinpanffe225e2018-11-01 19:43:06 +08003112 @Override
chen xu0026ca62019-03-06 15:28:50 -08003113 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 final Phone phone = getPhone(subId);
3117 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003118 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
3124 @Override
chen xu0026ca62019-03-06 15:28:50 -08003125 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003126 final long identity = Binder.clearCallingIdentity();
3127 try {
3128 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003129 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003130 } finally {
3131 Binder.restoreCallingIdentity(identity);
3132 }
3133 }
3134
chen xu651eec72018-11-11 19:03:44 -08003135 @Override
chen xu864e11c2018-12-06 22:10:03 -08003136 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3137 if (!isSubscriptionMccMnc) {
3138 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3139 }
chen xu651eec72018-11-11 19:03:44 -08003140 final Phone phone = PhoneFactory.getPhone(slotIndex);
3141 if (phone == null) {
3142 return TelephonyManager.UNKNOWN_CARRIER_ID;
3143 }
3144 final long identity = Binder.clearCallingIdentity();
3145 try {
3146 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3147 } finally {
3148 Binder.restoreCallingIdentity(identity);
3149 }
3150 }
3151
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003152 //
3153 // Internal helper methods.
3154 //
3155
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003156 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3158 *
3159 * @throws SecurityException if the caller does not have the required permission
3160 */
3161 private void enforceModifyPermission() {
3162 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3163 }
3164
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003165 /**
3166 * Make sure the caller is system.
3167 *
3168 * @throws SecurityException if the caller is not system.
3169 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003170 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003171 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3172 throw new SecurityException("Caller must be system");
3173 }
3174 }
3175
Shuo Qianf2b2df42019-11-13 17:43:31 -08003176 private void enforceActiveEmergencySessionPermission() {
3177 mApp.enforceCallingOrSelfPermission(
3178 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3179 }
3180
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 /**
3182 * Make sure the caller has the CALL_PHONE permission.
3183 *
3184 * @throws SecurityException if the caller does not have the required permission
3185 */
3186 private void enforceCallPermission() {
3187 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3188 }
3189
paulhu423b5f22019-08-23 19:17:33 +08003190 private void enforceSettingsPermission() {
3191 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003192 }
3193
Michele Berionned9fbae52020-11-13 02:36:59 +00003194 private void enforceRebootPermission() {
3195 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3196 }
3197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 private String createTelUrl(String number) {
3199 if (TextUtils.isEmpty(number)) {
3200 return null;
3201 }
3202
Jake Hambye994d462014-02-03 13:10:13 -08003203 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 }
3205
Ihab Awadf9e92732013-12-05 18:02:52 -08003206 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3208 }
3209
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003210 private static void logv(String msg) {
3211 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3212 }
3213
Ihab Awadf9e92732013-12-05 18:02:52 -08003214 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003215 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3216 }
3217
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003218 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003220 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003221 }
3222
Sanket Padawe356d7632015-06-22 14:03:32 -07003223 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003224 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 final Phone phone = PhoneFactory.getPhone(slotIndex);
3228 if (phone == null) {
3229 return PhoneConstants.PHONE_TYPE_NONE;
3230 } else {
3231 return phone.getPhoneType();
3232 }
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 }
3237
3238 /**
3239 * Returns the CDMA ERI icon index to display
3240 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003241 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003242 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3243 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3244 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003245 }
3246
Sanket Padawe356d7632015-06-22 14:03:32 -07003247 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003248 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3249 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003251 mApp, subId, callingPackage, callingFeatureId,
3252 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003253 return -1;
3254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255
3256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 final Phone phone = getPhone(subId);
3259 if (phone != null) {
3260 return phone.getCdmaEriIconIndex();
3261 } else {
3262 return -1;
3263 }
3264 } finally {
3265 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003267 }
3268
3269 /**
3270 * Returns the CDMA ERI icon mode,
3271 * 0 - ON
3272 * 1 - FLASHING
3273 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003274 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003275 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3276 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3277 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003278 }
3279
Sanket Padawe356d7632015-06-22 14:03:32 -07003280 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003281 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3282 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003284 mApp, subId, callingPackage, callingFeatureId,
3285 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003286 return -1;
3287 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288
3289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 final Phone phone = getPhone(subId);
3292 if (phone != null) {
3293 return phone.getCdmaEriIconMode();
3294 } else {
3295 return -1;
3296 }
3297 } finally {
3298 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 }
3301
3302 /**
3303 * Returns the CDMA ERI text,
3304 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003305 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003306 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3307 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3308 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003309 }
3310
Sanket Padawe356d7632015-06-22 14:03:32 -07003311 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003312 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3313 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003315 mApp, subId, callingPackage, callingFeatureId,
3316 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003317 return null;
3318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319
3320 final long identity = Binder.clearCallingIdentity();
3321 try {
3322 final Phone phone = getPhone(subId);
3323 if (phone != null) {
3324 return phone.getCdmaEriText();
3325 } else {
3326 return null;
3327 }
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003331 }
3332
3333 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003334 * Returns the CDMA MDN.
3335 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003336 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003337 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3339 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340
3341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003344 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345 return phone.getLine1Number();
3346 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003347 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348 return null;
3349 }
3350 } finally {
3351 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003352 }
3353 }
3354
3355 /**
3356 * Returns the CDMA MIN.
3357 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003358 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003359 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3361 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362
3363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 final Phone phone = getPhone(subId);
3366 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3367 return phone.getCdmaMin();
3368 } else {
3369 return null;
3370 }
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003373 }
3374 }
3375
Hall Liud892bec2018-11-30 14:51:45 -08003376 @Override
3377 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3378 INumberVerificationCallback callback, String callingPackage) {
3379 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3380 != PERMISSION_GRANTED) {
3381 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3382 }
3383 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3384
3385 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3386 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003387 throw new SecurityException("Calling package must be configured in the device config: "
3388 + "calling package: " + callingPackage
3389 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003390 }
3391
3392 if (range == null) {
3393 throw new NullPointerException("Range must be non-null");
3394 }
3395
3396 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003397 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003398
3399 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3400 }
3401
Junda Liuca05d5d2014-08-14 22:36:34 -07003402 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403 * Returns true if CDMA provisioning needs to run.
3404 */
3405 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003406 final long identity = Binder.clearCallingIdentity();
3407 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003408 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003409 } finally {
3410 Binder.restoreCallingIdentity(identity);
3411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003412 }
3413
3414 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003415 * Sets the voice mail number of a given subId.
3416 */
3417 @Override
3418 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003419 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3420 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3425 new Pair<String, String>(alphaTag, number), new Integer(subId));
3426 return success;
3427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003430 }
3431
Ta-wei Yen87c49842016-05-13 21:19:52 -07003432 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003433 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003435 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3436 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003437 if (!TextUtils.equals(callingPackage, systemDialer)) {
3438 throw new SecurityException("caller must be system dialer");
3439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3444 if (phoneAccountHandle == null) {
3445 return null;
3446 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003447 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448 } finally {
3449 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003450 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003451 }
3452
3453 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003454 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3455 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003458 mApp, subId, callingPackage, callingFeatureId,
3459 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003460 return null;
3461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003463 final long identity = Binder.clearCallingIdentity();
3464 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003465 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003469 }
3470
3471 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003472 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3473 VisualVoicemailSmsFilterSettings settings) {
3474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003475
3476 final long identity = Binder.clearCallingIdentity();
3477 try {
3478 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003479 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480 } finally {
3481 Binder.restoreCallingIdentity(identity);
3482 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003483 }
3484
3485 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003486 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003492 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003496 }
3497
3498 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003499 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3500 String callingPackage, int subId) {
3501 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003502
3503 final long identity = Binder.clearCallingIdentity();
3504 try {
3505 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003506 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507 } finally {
3508 Binder.restoreCallingIdentity(identity);
3509 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003510 }
3511
3512 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003513 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003519 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520 } finally {
3521 Binder.restoreCallingIdentity(identity);
3522 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003523 }
3524
3525 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003526 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3527 String callingAttributionTag, int subId, String number, int port, String text,
3528 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003530 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003531 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003532 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003533 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3534 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003535 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003536
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003537 /**
fionaxu0152e512016-11-14 13:36:14 -08003538 * Sets the voice activation state of a given subId.
3539 */
3540 @Override
3541 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3543 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 final Phone phone = getPhone(subId);
3548 if (phone != null) {
3549 phone.setVoiceActivationState(activationState);
3550 } else {
3551 loge("setVoiceActivationState fails with invalid subId: " + subId);
3552 }
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003555 }
3556 }
3557
3558 /**
3559 * Sets the data activation state of a given subId.
3560 */
3561 @Override
3562 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3564 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 final Phone phone = getPhone(subId);
3569 if (phone != null) {
3570 phone.setDataActivationState(activationState);
3571 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003572 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 }
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003576 }
3577 }
3578
3579 /**
3580 * Returns the voice activation state of a given subId.
3581 */
3582 @Override
3583 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003585
fionaxu0152e512016-11-14 13:36:14 -08003586 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 if (phone != null) {
3590 return phone.getVoiceActivationState();
3591 } else {
3592 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3593 }
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003596 }
3597 }
3598
3599 /**
3600 * Returns the data activation state of a given subId.
3601 */
3602 @Override
3603 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605
fionaxu0152e512016-11-14 13:36:14 -08003606 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 if (phone != null) {
3610 return phone.getDataActivationState();
3611 } else {
3612 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3613 }
3614 } finally {
3615 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003616 }
3617 }
3618
3619 /**
Wink Saville36469e72014-06-11 15:17:00 -07003620 * Returns the unread count of voicemails for a subId
3621 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003622 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003623 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3624 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003626 mApp, subId, callingPackage, callingFeatureId,
3627 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003628 return 0;
3629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630 final long identity = Binder.clearCallingIdentity();
3631 try {
3632 final Phone phone = getPhone(subId);
3633 if (phone != null) {
3634 return phone.getVoiceMessageCount();
3635 } else {
3636 return 0;
3637 }
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003641 }
3642
3643 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003644 * returns true, if the device is in a state where both voice and data
3645 * are supported simultaneously. This can change based on location or network condition.
3646 */
3647 @Override
3648 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 final Phone phone = getPhone(subId);
3652 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003656 }
3657
3658 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003659 * Send the dialer code if called from the current default dialer or the caller has
3660 * carrier privilege.
3661 * @param inputCode The dialer code to send
3662 */
3663 @Override
3664 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003665 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003667 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3668 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003669 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003670 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003671 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003676 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
fionaxu235cc5e2017-03-06 22:25:57 -08003680 }
3681
Pengquan Menga1bb6272018-09-06 09:59:22 -07003682 @Override
3683 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003684 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07003685 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003686 mApp, subId, "getNetworkSelectionMode");
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 if (!isActiveSubscription(subId)) {
3690 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3691 }
3692 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3693 } finally {
3694 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003695 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003696 }
3697
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003699 public boolean isInEmergencySmsMode() {
3700 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 for (Phone phone : PhoneFactory.getPhones()) {
3704 if (phone.isInEmergencySmsMode()) {
3705 return true;
3706 }
3707 }
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
3711 return false;
3712 }
3713
shilu366312e2019-12-17 09:28:10 -08003714 /**
3715 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3716 * @param subId The subscription to use to check the configuration.
3717 * @param c The callback that will be used to send the result.
3718 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003719 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003720 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3721 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003722 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003723 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003724
Brad Ebinger77b832e2019-10-17 17:03:22 -07003725 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3726 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3727 "IMS not available on device.");
3728 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 final long token = Binder.clearCallingIdentity();
3730 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003731 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003732 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003734 } catch (ImsException e) {
3735 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 } finally {
3737 Binder.restoreCallingIdentity(token);
3738 }
3739 }
3740
shilu366312e2019-12-17 09:28:10 -08003741 /**
3742 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3743 * @param subId The subscription to use to check the configuration.
3744 * @param c The callback that will be used to send the result.
3745 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003747 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003748 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003749 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003750 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3751 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3752 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003753 final long token = Binder.clearCallingIdentity();
3754 try {
3755 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3756 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3757 .removeRegistrationCallbackForSubscription(c, subId);
3758 } catch (ImsException e) {
3759 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3760 + "is inactive, ignoring unregister.");
3761 // If the subscription is no longer active, just return, since the callback
3762 // will already have been removed internally.
3763 } finally {
3764 Binder.restoreCallingIdentity(token);
3765 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003766 }
3767
Brad Ebinger774ba362019-10-22 17:36:18 -07003768 /**
3769 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3770 */
3771 @Override
3772 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3773 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3774 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3775 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3776 "IMS not available on device.");
3777 }
3778 final long token = Binder.clearCallingIdentity();
3779 try {
3780 Phone phone = getPhone(subId);
3781 if (phone == null) {
3782 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3783 + subId + "'");
3784 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3785 }
3786 phone.getImsRegistrationState(regState -> {
3787 try {
3788 consumer.accept((regState == null)
3789 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3790 } catch (RemoteException e) {
3791 // Ignore if the remote process is no longer available to call back.
3792 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3793 }
3794 });
3795 } finally {
3796 Binder.restoreCallingIdentity(token);
3797 }
3798 }
3799
3800 /**
3801 * Get the transport type for the IMS service registration state.
3802 */
3803 @Override
3804 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003805 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003806 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003807 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3808 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3809 "IMS not available on device.");
3810 }
3811 final long token = Binder.clearCallingIdentity();
3812 try {
3813 Phone phone = getPhone(subId);
3814 if (phone == null) {
3815 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3816 + subId + "'");
3817 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3818 }
3819 phone.getImsRegistrationTech(regTech -> {
3820 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3821 int regTechConverted = (regTech == null)
3822 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3823 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3824 regTechConverted);
3825 try {
3826 consumer.accept(regTechConverted);
3827 } catch (RemoteException e) {
3828 // Ignore if the remote process is no longer available to call back.
3829 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3830 }
3831 });
3832 } finally {
3833 Binder.restoreCallingIdentity(token);
3834 }
3835 }
3836
shilu366312e2019-12-17 09:28:10 -08003837 /**
3838 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3839 * @param subId The subscription to use to check the configuration.
3840 * @param c The callback that will be used to send the result.
3841 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003842 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003843 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3844 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003845 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003846 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003847 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3848 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3849 "IMS not available on device.");
3850 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3852 final long token = Binder.clearCallingIdentity();
3853 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003854 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003855 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003856 } catch (ImsException e) {
3857 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003858 } finally {
3859 Binder.restoreCallingIdentity(token);
3860 }
3861 }
3862
shilu366312e2019-12-17 09:28:10 -08003863 /**
3864 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3865 * @param subId The subscription to use to check the configuration.
3866 * @param c The callback that will be used to send the result.
3867 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003869 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003870 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003871 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003872 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3873 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3874 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003875
3876 final long token = Binder.clearCallingIdentity();
3877 try {
3878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3879 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003880 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003881 } catch (ImsException e) {
3882 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3883 + "is inactive, ignoring unregister.");
3884 // If the subscription is no longer active, just return, since the callback
3885 // will already have been removed internally.
3886 } finally {
3887 Binder.restoreCallingIdentity(token);
3888 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 }
3890
3891 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003892 public boolean isCapable(int subId, int capability, int regTech) {
3893 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3895 final long token = Binder.clearCallingIdentity();
3896 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003897 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003899 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003900 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3901 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003902 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003903 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3904 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 } finally {
3906 Binder.restoreCallingIdentity(token);
3907 }
3908 }
3909
3910 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003911 public boolean isAvailable(int subId, int capability, int regTech) {
3912 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 final long token = Binder.clearCallingIdentity();
3914 try {
3915 Phone phone = getPhone(subId);
3916 if (phone == null) return false;
3917 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003918 } catch (com.android.ims.ImsException e) {
3919 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3920 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 } finally {
3922 Binder.restoreCallingIdentity(token);
3923 }
3924 }
3925
Brad Ebinger77b832e2019-10-17 17:03:22 -07003926 /**
3927 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3928 * subscription.
3929 * @param subId The subscription to use to check the configuration.
3930 * @param callback The callback that will be used to send the result.
3931 * @param capability The MmTelFeature capability that will be used to send the result.
3932 * @param transportType The transport type of the MmTelFeature capability.
3933 */
3934 @Override
3935 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3936 int transportType) {
3937 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3938 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3939 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3940 "IMS not available on device.");
3941 }
3942 final long token = Binder.clearCallingIdentity();
3943 try {
3944 int slotId = getSlotIndex(subId);
3945 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3946 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3947 + subId + "'");
3948 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3949 }
3950 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3951 transportType, aBoolean -> {
3952 try {
3953 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3954 } catch (RemoteException e) {
3955 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3956 + "running. Ignore");
3957 }
3958 });
3959 } finally {
3960 Binder.restoreCallingIdentity(token);
3961 }
3962 }
3963
shilu366312e2019-12-17 09:28:10 -08003964 /**
3965 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3966 * @param subId The subscription to use to check the configuration.
3967 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 @Override
3969 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003970 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003971 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003972
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3974 final long token = Binder.clearCallingIdentity();
3975 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003976 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003978 } catch (ImsException e) {
3979 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 } finally {
3981 Binder.restoreCallingIdentity(token);
3982 }
3983 }
3984
3985 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003986 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003988 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003992 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003994 } catch (ImsException e) {
3995 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003996 } finally {
3997 Binder.restoreCallingIdentity(identity);
3998 }
3999 }
4000
shilu366312e2019-12-17 09:28:10 -08004001 /**
4002 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4003 * @param subId The subscription to use to check the configuration.
4004 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004006 public boolean isVtSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004007 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004008 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004012 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4013 } catch (ImsException e) {
4014 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 } finally {
4016 Binder.restoreCallingIdentity(identity);
4017 }
4018 }
4019
4020 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004021 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004023 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 final long identity = Binder.clearCallingIdentity();
4025 try {
4026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004027 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004028 } catch (ImsException e) {
4029 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 } finally {
4031 Binder.restoreCallingIdentity(identity);
4032 }
4033 }
4034
shilu366312e2019-12-17 09:28:10 -08004035 /**
4036 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4037 * @param subId The subscription to use to check the configuration.
4038 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 @Override
4040 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004041 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004042 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004046 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004047 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004048 } catch (ImsException e) {
4049 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 } finally {
4051 Binder.restoreCallingIdentity(identity);
4052 }
4053 }
4054
4055 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004056 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004058 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 final long identity = Binder.clearCallingIdentity();
4060 try {
4061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004062 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004063 } catch (ImsException e) {
4064 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004065 } finally {
4066 Binder.restoreCallingIdentity(identity);
4067 }
4068 }
4069
shilu366312e2019-12-17 09:28:10 -08004070 /**
4071 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4072 * @param subId The subscription to use to check the configuration.
4073 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 @Override
4075 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004076 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004077 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004081 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004083 } catch (ImsException e) {
4084 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 } finally {
4086 Binder.restoreCallingIdentity(identity);
4087 }
4088 }
4089
4090 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004091 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004093 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004097 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (ImsException e) {
4100 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
4104 }
4105
4106 @Override
4107 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4109 "setVoWiFiNonPersistent");
4110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004113 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004114 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004115 } catch (ImsException e) {
4116 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
4120 }
4121
shilu366312e2019-12-17 09:28:10 -08004122 /**
4123 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4124 * @param subId The subscription to use to check the configuration.
4125 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 @Override
4127 public int getVoWiFiModeSetting(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004128 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004129 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004135 } catch (ImsException e) {
4136 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
4140 }
4141
4142 @Override
4143 public void setVoWiFiModeSetting(int subId, int mode) {
4144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4145 "setVoWiFiModeSetting");
4146 final long identity = Binder.clearCallingIdentity();
4147 try {
4148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004149 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004151 } catch (ImsException e) {
4152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 } finally {
4154 Binder.restoreCallingIdentity(identity);
4155 }
4156 }
4157
4158 @Override
4159 public int getVoWiFiRoamingModeSetting(int subId) {
4160 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004164 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004166 } catch (ImsException e) {
4167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
4171 }
4172
4173 @Override
4174 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4176 "setVoWiFiRoamingModeSetting");
4177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004180 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004182 } catch (ImsException e) {
4183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
4187 }
4188
4189 @Override
4190 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4192 "setRttCapabilityEnabled");
4193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004196 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4197 } catch (ImsException e) {
4198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 } finally {
4200 Binder.restoreCallingIdentity(identity);
4201 }
4202 }
4203
shilu366312e2019-12-17 09:28:10 -08004204 /**
4205 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4206 * @param subId The subscription to use to check the configuration.
4207 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 @Override
4209 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004210 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004211 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 final long identity = Binder.clearCallingIdentity();
4213 try {
4214 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004215 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004217 } catch (ImsException e) {
4218 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
4222 }
4223
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004224 @Override
4225 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4226 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4227 final long identity = Binder.clearCallingIdentity();
4228 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004229 if (!isImsAvailableOnDevice()) {
4230 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4231 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004232 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004233 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004234 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004235 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004236 } catch (ImsException e) {
4237 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004238 } finally {
4239 Binder.restoreCallingIdentity(identity);
4240 }
4241 }
4242
4243 @Override
4244 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4245 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4246 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004247 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4248 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4249 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004250 try {
4251 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004252 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004253 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004254 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004255 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4256 + "is inactive, ignoring unregister.");
4257 // If the subscription is no longer active, just return, since the callback will already
4258 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
4262 }
4263
allenwtsu99c623b2020-01-03 18:24:23 +08004264
4265 private void checkModifyPhoneStatePermission(int subId, String message) {
4266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4267 message);
4268 }
4269
4270 private boolean isImsProvisioningRequired(int subId, int capability,
4271 boolean isMmtelCapability) {
4272 Phone phone = getPhone(subId);
4273 if (phone == null) {
4274 loge("phone instance null for subid " + subId);
4275 return false;
4276 }
4277 if (isMmtelCapability) {
4278 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4279 return false;
4280 }
4281 } else {
4282 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4283 return false;
4284 }
4285 }
4286 return true;
4287 }
4288
4289 @Override
4290 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4291 boolean isProvisioned) {
4292 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4293
4294 final long identity = Binder.clearCallingIdentity();
4295 try {
4296 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4297 if (!isImsProvisioningRequired(subId, capability, false)) {
4298 return;
4299 }
4300
4301 // this capability requires provisioning, route to the correct API.
4302 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4303 switch (capability) {
4304 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4305 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4306 ims.setEabProvisioned(isProvisioned);
4307 break;
4308 default: {
4309 throw new IllegalArgumentException("Tried to set provisioning for "
4310 + "rcs capability '" + capability + "', which does not require "
4311 + "provisioning.");
4312 }
4313 }
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
4316 }
4317
4318 }
4319
4320
4321 @Override
4322 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4323 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4324 final long identity = Binder.clearCallingIdentity();
4325 try {
4326 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4327 if (!isImsProvisioningRequired(subId, capability, false)) {
4328 return true;
4329 }
4330
4331 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4332 switch (capability) {
4333 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4334 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4335 return ims.isEabProvisionedOnDevice();
4336
4337 default: {
4338 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4339 + "capability '" + capability + "', which does not require "
4340 + "provisioning.");
4341 }
4342 }
4343
4344 } finally {
4345 Binder.restoreCallingIdentity(identity);
4346 }
4347 }
4348
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004349 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004350 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4351 boolean isProvisioned) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004352 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4353 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004354 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4355 }
allenwtsu99c623b2020-01-03 18:24:23 +08004356 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004360 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004361 return;
4362 }
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004363 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4364 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4365 loge("setImsProvisioningStatusForCapability: called for technology that does "
4366 + "not support provisioning - " + tech);
4367 return;
4368 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004369
4370 // this capability requires provisioning, route to the correct API.
4371 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4372 switch (capability) {
4373 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4374 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4375 ims.setVolteProvisioned(isProvisioned);
4376 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4377 ims.setWfcProvisioned(isProvisioned);
4378 }
4379 break;
4380 }
4381 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4382 // There is currently no difference in VT provisioning type.
4383 ims.setVtProvisioned(isProvisioned);
4384 break;
4385 }
4386 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4387 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4388 // change the capability of the feature instead if needed.
4389 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4390 == isProvisioned) {
4391 // No change in provisioning.
4392 return;
4393 }
4394 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4395 try {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004396 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004397 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004398 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4399 + ", Exception" + e.getMessage());
4400 }
4401 break;
4402 }
4403 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004404 throw new IllegalArgumentException("Tried to set provisioning for "
4405 + "MmTel capability '" + capability + "', which does not require "
4406 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004407 }
4408 }
4409
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
4413 }
4414
4415 @Override
4416 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004417 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4418 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004419 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4420 }
4421 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004425 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004426 return true;
4427 }
4428
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004429 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4430 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4431 loge("getImsProvisioningStatusForCapability: called for technology that does "
4432 + "not support provisioning - " + tech);
4433 return true;
4434 }
4435
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004436 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4437 switch (capability) {
4438 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4439 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4440 return ims.isVolteProvisionedOnDevice();
4441 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4442 return ims.isWfcProvisionedOnDevice();
4443 }
4444 // This should never happen, since we are checking tech above to make sure it
4445 // is either LTE or IWLAN.
4446 throw new IllegalArgumentException("Invalid radio technology for voice "
4447 + "capability.");
4448 }
4449 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4450 // There is currently no difference in VT provisioning type.
4451 return ims.isVtProvisionedOnDevice();
4452 }
4453 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4454 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4455 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4456 }
4457 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004458 throw new IllegalArgumentException(
4459 "Tried to get provisioning for MmTel capability '" + capability
4460 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004461 }
4462 }
4463
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
4467 }
4468
4469 @Override
4470 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4471 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4472 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4473 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4474 }
4475 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4476 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4477 return (provisionedBits & capability) > 0;
4478 }
4479
4480 @Override
4481 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4482 boolean isProvisioned) {
4483 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4484 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4485 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4486 }
4487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4488 "setProvisioningStatusForCapability");
4489 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4490 // If the current provisioning status for capability already matches isProvisioned,
4491 // do nothing.
4492 if (((provisionedBits & capability) > 0) == isProvisioned) {
4493 return;
4494 }
4495 if (isProvisioned) {
4496 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4497 } else {
4498 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4499 }
4500 }
4501
4502 /**
4503 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4504 * technology. The bitfield should mirror the bitfield defined by
4505 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4506 */
4507 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4508 String key = getMmTelProvisioningKey(subId, tech);
4509 // Default is no capabilities are provisioned.
4510 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4511 }
4512
4513 /**
4514 * Sets the MmTel capability provisioning bitfield (defined by
4515 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4516 * technology specified.
4517 *
4518 * Note: This is a synchronous command and should not be called on UI thread.
4519 */
4520 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4521 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4522 String key = getMmTelProvisioningKey(subId, tech);
4523 editor.putInt(key, newField);
4524 editor.commit();
4525 }
4526
4527 private static String getMmTelProvisioningKey(int subId, int tech) {
4528 // resulting key is provision_ims_mmtel_{subId}_{tech}
4529 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4530 }
4531
4532 /**
4533 * Query CarrierConfig to see if the specified capability requires provisioning for the
4534 * carrier associated with the subscription id.
4535 */
4536 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4537 int capability) {
4538 CarrierConfigManager configManager = new CarrierConfigManager(context);
4539 PersistableBundle c = configManager.getConfigForSubId(subId);
4540 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004541 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004542 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4543 false);
4544 boolean requireVoiceVtProvisioning = c.getBoolean(
4545 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4546
4547 // First check to make sure that the capability requires provisioning.
4548 switch (capability) {
4549 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4550 // intentional fallthrough
4551 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4552 if (requireVoiceVtProvisioning) {
4553 // Voice and Video requires provisioning
4554 return true;
4555 }
4556 break;
4557 }
4558 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4559 if (requireUtProvisioning) {
4560 // UT requires provisioning
4561 return true;
4562 }
4563 break;
4564 }
4565 }
4566 return false;
4567 }
4568
allenwtsu99c623b2020-01-03 18:24:23 +08004569 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4570 int capability) {
4571 CarrierConfigManager configManager = new CarrierConfigManager(context);
4572 PersistableBundle c = configManager.getConfigForSubId(subId);
4573
4574 boolean requireRcsProvisioning = c.getBoolean(
4575 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4576
4577 // First check to make sure that the capability requires provisioning.
4578 switch (capability) {
4579 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4580 // intentional fallthrough
4581 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4582 if (requireRcsProvisioning) {
4583 // OPTION or PRESENCE requires provisioning
4584 return true;
4585 }
4586 break;
4587 }
4588 }
4589 return false;
4590 }
4591
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004592 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004594 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4595 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4596 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004597 enforceReadPrivilegedPermission("getImsProvisioningInt");
4598 final long identity = Binder.clearCallingIdentity();
4599 try {
4600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004601 int slotId = getSlotIndex(subId);
4602 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4603 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4604 + subId + "' for key:" + key);
4605 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4606 }
calvinpan9cfff472021-02-08 19:59:36 +08004607 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004608 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004609 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4610 + subId + "' for key:" + key);
4611 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004612 } finally {
4613 Binder.restoreCallingIdentity(identity);
4614 }
4615 }
4616
4617 @Override
4618 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004619 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4620 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4621 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004622 enforceReadPrivilegedPermission("getImsProvisioningString");
4623 final long identity = Binder.clearCallingIdentity();
4624 try {
4625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004626 int slotId = getSlotIndex(subId);
4627 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4628 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4629 + subId + "' for key:" + key);
4630 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4631 }
calvinpan9cfff472021-02-08 19:59:36 +08004632 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004633 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004634 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4635 + subId + "' for key:" + key);
4636 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004637 } finally {
4638 Binder.restoreCallingIdentity(identity);
4639 }
4640 }
4641
4642 @Override
4643 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004644 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4645 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4646 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4648 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004649 final long identity = Binder.clearCallingIdentity();
4650 try {
4651 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004652 int slotId = getSlotIndex(subId);
4653 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4654 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4655 + subId + "' for key:" + key);
4656 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4657 }
calvinpan9cfff472021-02-08 19:59:36 +08004658 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4659 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004660 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004661 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
4666 }
4667
4668 @Override
4669 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004670 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4671 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4672 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4674 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004675 final long identity = Binder.clearCallingIdentity();
4676 try {
4677 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004678 int slotId = getSlotIndex(subId);
4679 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4680 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4681 + subId + "' for key:" + key);
4682 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4683 }
calvinpan9cfff472021-02-08 19:59:36 +08004684 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4685 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004686 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004687 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004688 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004689 } finally {
4690 Binder.restoreCallingIdentity(identity);
4691 }
4692 }
4693
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004694 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004695 int slotId = SubscriptionManager.getSlotIndex(subId);
4696 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004697 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4698 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004699 }
4700 return slotId;
4701 }
4702
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004703 private int getSlotIndex(int subId) {
4704 int slotId = SubscriptionManager.getSlotIndex(subId);
4705 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4706 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4707 }
4708 return slotId;
4709 }
4710
Wink Saville36469e72014-06-11 15:17:00 -07004711 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004712 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004713 */
4714 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004715 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4716 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004717 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004718 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004719 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004720 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004721 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004722 mApp, subId, callingPackage, callingFeatureId,
4723 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004724 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4725 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 final Phone phone = getPhone(subId);
4730 if (phone != null) {
4731 return phone.getServiceState().getDataNetworkType();
4732 } else {
4733 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4734 }
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004738 }
4739
4740 /**
4741 * Returns the data network type
4742 */
4743 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004744 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004745 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4746 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004747 }
4748
4749 /**
4750 * Returns the data network type for a subId
4751 */
4752 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004753 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4754 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004756 mApp, subId, callingPackage, callingFeatureId,
4757 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004758 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4759 }
4760
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 final long identity = Binder.clearCallingIdentity();
4762 try {
4763 final Phone phone = getPhone(subId);
4764 if (phone != null) {
4765 return phone.getServiceState().getDataNetworkType();
4766 } else {
4767 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4768 }
4769 } finally {
4770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004772 }
4773
4774 /**
Wink Saville36469e72014-06-11 15:17:00 -07004775 * Returns the Voice network type for a subId
4776 */
4777 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004778 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4779 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004781 mApp, subId, callingPackage, callingFeatureId,
4782 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004783 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4784 }
4785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786 final long identity = Binder.clearCallingIdentity();
4787 try {
4788 final Phone phone = getPhone(subId);
4789 if (phone != null) {
4790 return phone.getServiceState().getVoiceNetworkType();
4791 } else {
4792 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4793 }
4794 } finally {
4795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004797 }
4798
4799 /**
4800 * @return true if a ICC card is present
4801 */
4802 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004803 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004804 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4805 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004806 }
4807
4808 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004809 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004810 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004811 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004812 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813 final long identity = Binder.clearCallingIdentity();
4814 try {
4815 final Phone phone = PhoneFactory.getPhone(slotIndex);
4816 if (phone != null) {
4817 return phone.getIccCard().hasIccCard();
4818 } else {
4819 return false;
4820 }
4821 } finally {
4822 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004824 }
4825
4826 /**
4827 * Return if the current radio is LTE on CDMA. This
4828 * is a tri-state return value as for a period of time
4829 * the mode may be unknown.
4830 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004831 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004832 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004833 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004834 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004835 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004836 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4837 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4838 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004839 }
4840
Sanket Padawe356d7632015-06-22 14:03:32 -07004841 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004842 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4843 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004844 try {
4845 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4846 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004847 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4848 }
4849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 final Phone phone = getPhone(subId);
4853 if (phone == null) {
4854 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4855 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004856 return TelephonyProperties.lte_on_cdma_device()
4857 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858 }
4859 } finally {
4860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004861 }
Wink Saville36469e72014-06-11 15:17:00 -07004862 }
4863
Wink Saville36469e72014-06-11 15:17:00 -07004864 /**
4865 * {@hide}
4866 * Returns Default subId, 0 in the case of single standby.
4867 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004868 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004869 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004870 }
4871
Shishir Agrawala9f32182016-04-12 12:00:16 -07004872 private int getSlotForDefaultSubscription() {
4873 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4874 }
4875
Wink Savilleb564aae2014-10-23 10:18:09 -07004876 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004877 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004878 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004879
Pengquan Menge92a50d2018-09-21 15:54:48 -07004880 private boolean isActiveSubscription(int subId) {
4881 return mSubscriptionController.isActiveSubId(subId);
4882 }
4883
Ihab Awadf2177b72013-11-25 13:33:23 -08004884 /**
4885 * @see android.telephony.TelephonyManager.WifiCallingChoices
4886 */
4887 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004890 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4892 getWhenToMakeWifiCallsDefaultPreference());
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004896 }
4897
4898 /**
4899 * @see android.telephony.TelephonyManager.WifiCallingChoices
4900 */
4901 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 final long identity = Binder.clearCallingIdentity();
4903 try {
4904 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004905 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004910 }
4911
Sailesh Nepald1e68152013-12-12 19:08:02 -08004912 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004913 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004914 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004915 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004916
Jordan Liu4c733742019-02-28 12:03:40 -08004917 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4918 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4919 if (phoneId == -1) {
4920 throw new IllegalArgumentException("Given slot index: " + slotIndex
4921 + " does not correspond to an active phone");
4922 }
4923 return PhoneFactory.getPhone(phoneId);
4924 }
4925
Shishir Agrawal566b7612013-10-28 14:41:00 -07004926 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004927 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4928 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4930 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004932 if (DBG) {
4933 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4934 }
4935 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4936 p2);
4937 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004938
Jordan Liu4c733742019-02-28 12:03:40 -08004939
4940 @Override
4941 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4942 int slotIndex, String callingPackage, String aid, int p2) {
4943 enforceModifyPermission();
4944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4945 if (DBG) {
4946 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4947 }
4948 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4949 callingPackage, aid, p2);
4950 }
4951
4952 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4953 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 final long identity = Binder.clearCallingIdentity();
4955 try {
4956 if (TextUtils.equals(ISDR_AID, aid)) {
4957 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004958 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4959 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 if (bestComponent == null
4961 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4962 loge("The calling package is not allowed to access ISD-R.");
4963 throw new SecurityException(
4964 "The calling package is not allowed to access ISD-R.");
4965 }
Derek Tan740e1672017-06-27 14:56:27 -07004966 }
Derek Tan740e1672017-06-27 14:56:27 -07004967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004969 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4970 null /* workSource */);
4971 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 return response;
4973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004976 }
4977
4978 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004979 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4981 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004982 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4983 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4984 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004985
Jordan Liu4c733742019-02-28 12:03:40 -08004986 @Override
4987 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4988 enforceModifyPermission();
4989 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4990 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4991 channel);
4992 }
4993
4994 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 final long identity = Binder.clearCallingIdentity();
4996 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004997 if (channel < 0) {
4998 return false;
4999 }
Jordan Liu4c733742019-02-28 12:03:40 -08005000 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5001 null /* workSource */);
5002 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 return success;
5004 } finally {
5005 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005006 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005007 }
5008
5009 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005010 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005011 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5013 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005014 if (DBG) {
5015 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5016 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5017 + p3 + " data=" + data);
5018 }
5019 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5020 command, p1, p2, p3, data);
5021 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005022
Jordan Liu4c733742019-02-28 12:03:40 -08005023 @Override
5024 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5025 int command, int p1, int p2, int p3, String data) {
5026 enforceModifyPermission();
5027 if (DBG) {
5028 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5029 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5030 + p3 + " data=" + data);
5031 }
5032 return iccTransmitApduLogicalChannelWithPermission(
5033 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5034 data);
5035 }
5036
5037 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5038 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039 final long identity = Binder.clearCallingIdentity();
5040 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005041 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 return "";
5043 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005046 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5047 null /* workSource */);
5048 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 // Append the returned status code to the end of the response payload.
5051 String s = Integer.toHexString(
5052 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5053 if (response.payload != null) {
5054 s = IccUtils.bytesToHexString(response.payload) + s;
5055 }
5056 return s;
5057 } finally {
5058 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005059 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005060 }
Jake Hambye994d462014-02-03 13:10:13 -08005061
Evan Charltonc66da362014-05-16 14:06:40 -07005062 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005063 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5064 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5066 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005068 if (DBG) {
5069 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5070 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5071 }
5072 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5073 cla, command, p1, p2, p3, data);
5074 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005075
Jordan Liu4c733742019-02-28 12:03:40 -08005076 @Override
5077 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5078 int command, int p1, int p2, int p3, String data) {
5079 enforceModifyPermission();
5080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5081 if (DBG) {
5082 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5083 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5084 + " data=" + data);
5085 }
5086
5087 return iccTransmitApduBasicChannelWithPermission(
5088 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5089 p2, p3, data);
5090 }
5091
5092 // open APDU basic channel assuming the caller has sufficient permissions
5093 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5094 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
5097 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5098 && TextUtils.equals(ISDR_AID, data)) {
5099 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005100 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5101 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 if (bestComponent == null
5103 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5104 loge("The calling package is not allowed to select ISD-R.");
5105 throw new SecurityException(
5106 "The calling package is not allowed to select ISD-R.");
5107 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005108 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005111 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5112 null /* workSource */);
5113 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 // Append the returned status code to the end of the response payload.
5116 String s = Integer.toHexString(
5117 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5118 if (response.payload != null) {
5119 s = IccUtils.bytesToHexString(response.payload) + s;
5120 }
5121 return s;
5122 } finally {
5123 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005124 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005125 }
5126
5127 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005128 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005129 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5131 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 if (DBG) {
5136 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5137 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5138 }
5139
5140 IccIoResult response =
5141 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5142 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5143 subId);
5144
5145 if (DBG) {
5146 log("Exchange SIM_IO [R]" + response);
5147 }
5148
5149 byte[] result = null;
5150 int length = 2;
5151 if (response.payload != null) {
5152 length = 2 + response.payload.length;
5153 result = new byte[length];
5154 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5155 } else {
5156 result = new byte[length];
5157 }
5158
5159 result[length - 1] = (byte) response.sw2;
5160 result[length - 2] = (byte) response.sw1;
5161 return result;
5162 } finally {
5163 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005164 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005165 }
5166
Nathan Haroldb3014052017-01-25 15:57:32 -08005167 /**
5168 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5169 * on a particular subscription
5170 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005171 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5172 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005174 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005175 return null;
5176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177
5178 final long identity = Binder.clearCallingIdentity();
5179 try {
5180 if (appType != TelephonyManager.APPTYPE_USIM
5181 && appType != TelephonyManager.APPTYPE_SIM) {
5182 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5183 return null;
5184 }
5185 Object response = sendRequest(
5186 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5187 if (response instanceof String[]) {
5188 return (String[]) response;
5189 }
yincheng zhaod698b842019-09-06 17:06:54 -07005190 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005192 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 } finally {
5194 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005195 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005196 }
5197
yincheng zhaod698b842019-09-06 17:06:54 -07005198 /**
5199 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5200 * subscription.
5201 *
5202 * @param subId the id of the subscription.
5203 * @param appType the uicc app type, must be USIM or SIM.
5204 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5205 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005206 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005207 * @return number of fplmns that is successfully written to the SIM.
5208 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005209 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5210 String callingFeatureId) {
5211 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5212 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005213 if (DBG) logv("no permissions for setForbiddenplmns");
5214 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5215 }
5216 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5217 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5218 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5219 }
5220 if (fplmns == null) {
5221 throw new IllegalArgumentException("Fplmn List provided is null");
5222 }
5223 for (String fplmn : fplmns) {
5224 if (!CellIdentity.isValidPlmn(fplmn)) {
5225 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5226 }
5227 }
5228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 Object response = sendRequest(
5231 CMD_SET_FORBIDDEN_PLMNS,
5232 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5233 subId);
5234 return (int) response;
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
5238 }
5239
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005240 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005241 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5243 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5248 if (response.payload == null) {
5249 return "";
5250 }
Evan Charltonc66da362014-05-16 14:06:40 -07005251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 // Append the returned status code to the end of the response payload.
5253 String s = Integer.toHexString(
5254 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5255 s = IccUtils.bytesToHexString(response.payload) + s;
5256 return s;
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
Evan Charltonc66da362014-05-16 14:06:40 -07005260 }
5261
Jake Hambye994d462014-02-03 13:10:13 -08005262 /**
5263 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5264 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5265 *
5266 * @param itemID the ID of the item to read
5267 * @return the NV item as a String, or null on error.
5268 */
5269 @Override
5270 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005271 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5273 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274
5275 final long identity = Binder.clearCallingIdentity();
5276 try {
5277 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005278 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5280 return value;
5281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
Jake Hambye994d462014-02-03 13:10:13 -08005284 }
5285
5286 /**
5287 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5288 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5289 *
5290 * @param itemID the ID of the item to read
5291 * @param itemValue the value to write, as a String
5292 * @return true on success; false on any failure
5293 */
5294 @Override
5295 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5298 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299
5300 final long identity = Binder.clearCallingIdentity();
5301 try {
5302 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5303 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005304 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5306 return success;
5307 } finally {
5308 Binder.restoreCallingIdentity(identity);
5309 }
Jake Hambye994d462014-02-03 13:10:13 -08005310 }
5311
5312 /**
5313 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5314 * Used for device configuration by some CDMA operators.
5315 *
5316 * @param preferredRoamingList byte array containing the new PRL
5317 * @return true on success; false on any failure
5318 */
5319 @Override
5320 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5322 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323
5324 final long identity = Binder.clearCallingIdentity();
5325 try {
5326 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5327 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5328 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5329 return success;
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
5332 }
Jake Hambye994d462014-02-03 13:10:13 -08005333 }
5334
5335 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005336 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005337 * Used for device configuration by some CDMA operators.
5338 *
chen xu6dac5ab2018-10-26 17:39:23 -07005339 * @param slotIndex - device slot.
5340 *
Jake Hambye994d462014-02-03 13:10:13 -08005341 * @return true on success; false on any failure
5342 */
5343 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005344 public boolean resetModemConfig(int slotIndex) {
5345 Phone phone = PhoneFactory.getPhone(slotIndex);
5346 if (phone != null) {
5347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5348 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349
chen xu6dac5ab2018-10-26 17:39:23 -07005350 final long identity = Binder.clearCallingIdentity();
5351 try {
5352 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5353 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5354 return success;
5355 } finally {
5356 Binder.restoreCallingIdentity(identity);
5357 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 }
chen xu6dac5ab2018-10-26 17:39:23 -07005359 return false;
5360 }
5361
5362 /**
5363 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5364 *
5365 * @param slotIndex - device slot.
5366 *
5367 * @return true on success; false on any failure
5368 */
5369 @Override
5370 public boolean rebootModem(int slotIndex) {
5371 Phone phone = PhoneFactory.getPhone(slotIndex);
5372 if (phone != null) {
5373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5374 mApp, phone.getSubId(), "rebootModem");
5375
5376 final long identity = Binder.clearCallingIdentity();
5377 try {
5378 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5379 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5380 return success;
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
5383 }
5384 }
5385 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005386 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005387
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005388 public String[] getPcscfAddress(String apnType, String callingPackage,
5389 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005390 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5392 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005393 return new String[0];
5394 }
5395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 final long identity = Binder.clearCallingIdentity();
5397 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005398 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
Wink Saville36469e72014-06-11 15:17:00 -07005402 }
5403
Brad Ebinger51f743a2017-01-23 13:50:20 -08005404 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005405 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5406 * {@link #disableIms(int)}.
5407 * @param slotIndex device slot.
5408 */
5409 public void resetIms(int slotIndex) {
5410 enforceModifyPermission();
5411
5412 final long identity = Binder.clearCallingIdentity();
5413 try {
5414 if (mImsResolver == null) {
5415 // may happen if the does not support IMS.
5416 return;
5417 }
5418 mImsResolver.disableIms(slotIndex);
5419 mImsResolver.enableIms(slotIndex);
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
5423 }
5424
5425 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005426 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5427 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005428 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005429 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431
5432 final long identity = Binder.clearCallingIdentity();
5433 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005434 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005435 // may happen if the device does not support IMS.
5436 return;
5437 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005438 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 } finally {
5440 Binder.restoreCallingIdentity(identity);
5441 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005442 }
5443
5444 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005445 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5446 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005447 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005448 public void disableIms(int slotId) {
5449 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450
5451 final long identity = Binder.clearCallingIdentity();
5452 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005453 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005454 // may happen if the device does not support IMS.
5455 return;
5456 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005457 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 } finally {
5459 Binder.restoreCallingIdentity(identity);
5460 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005461 }
5462
5463 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005464 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5465 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005466 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005467 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005468 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005469 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470
5471 final long identity = Binder.clearCallingIdentity();
5472 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005473 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005474 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5475 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005476 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005477 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 } finally {
5479 Binder.restoreCallingIdentity(identity);
5480 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005481 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005482 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005483 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5484 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005485 @Override
5486 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005487 enforceModifyPermission();
5488
5489 final long identity = Binder.clearCallingIdentity();
5490 try {
5491 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005492 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
5496 }
5497
5498 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005499 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005500 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005501 */
5502 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504
5505 final long identity = Binder.clearCallingIdentity();
5506 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005507 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005508 // may happen if the device does not support IMS.
5509 return null;
5510 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005511 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 } finally {
5513 Binder.restoreCallingIdentity(identity);
5514 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005515 }
5516
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005517 /**
5518 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005519 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005520 */
5521 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5522 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523
5524 final long identity = Binder.clearCallingIdentity();
5525 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005526 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005527 // may happen if the device does not support IMS.
5528 return null;
5529 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005530 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005534 }
5535
Brad Ebinger884c07b2018-02-15 16:17:40 -08005536 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005537 * Sets the ImsService Package Name that Telephony will bind to.
5538 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005539 * @param slotIndex the slot ID that the ImsService should bind for.
5540 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005541 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005542 * @param featureTypes An integer array of feature types associated with a packageName.
5543 * @param packageName The name of the package that the current configuration will be replaced
5544 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005545 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005546 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005547 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5548 int[] featureTypes, String packageName) {
5549 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5550 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5552 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005553 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005554
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555 final long identity = Binder.clearCallingIdentity();
5556 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005557 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005558 // may happen if the device does not support IMS.
5559 return false;
5560 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005561 Map<Integer, String> featureConfig = new HashMap<>();
5562 for (int featureType : featureTypes) {
5563 featureConfig.put(featureType, packageName);
5564 }
5565 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5566 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005570 }
5571
5572 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005573 * Clears any carrier ImsService overrides for the slot index specified that were previously
5574 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5575 *
5576 * This should only be used for testing.
5577 *
5578 * @param slotIndex the slot ID that the ImsService should bind for.
5579 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5580 */
5581 @Override
5582 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5583 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5584 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5585 "clearCarrierImsServiceOverride");
5586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5587 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5588 "clearCarrierImsServiceOverride");
5589
5590 final long identity = Binder.clearCallingIdentity();
5591 try {
5592 if (mImsResolver == null) {
5593 // may happen if the device does not support IMS.
5594 return false;
5595 }
5596 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
5600 }
5601
5602 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005603 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005604 *
5605 * @param slotId The slot that the ImsService is associated with.
5606 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5607 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005608 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005609 * @return the package name of the ImsService configuration.
5610 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005611 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5612 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005613 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005614 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005615 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005616 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5617 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 final long identity = Binder.clearCallingIdentity();
5620 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005621 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005622 // may happen if the device does not support IMS.
5623 return "";
5624 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005625 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005626 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5627 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 } finally {
5629 Binder.restoreCallingIdentity(identity);
5630 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005631 }
5632
Brad Ebinger77b832e2019-10-17 17:03:22 -07005633 /**
5634 * Get the MmTelFeature state associated with the requested subscription id.
5635 * @param subId The subscription that the MmTelFeature is associated with.
5636 * @param callback A callback with an integer containing the
5637 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5638 */
5639 @Override
5640 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5641 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5642 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5643 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5644 "IMS not available on device.");
5645 }
5646 final long token = Binder.clearCallingIdentity();
5647 try {
5648 int slotId = getSlotIndex(subId);
5649 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5650 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5651 + subId + "'");
5652 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5653 }
5654 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5655 try {
5656 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5657 } catch (RemoteException e) {
5658 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5659 + "Ignore");
5660 }
5661 });
5662 } finally {
5663 Binder.restoreCallingIdentity(token);
5664 }
5665 }
5666
Daniel Brightbb5840b2021-01-12 15:48:18 -08005667 /**
5668 * Sets the ims registration state on all valid {@link Phone}s.
5669 */
5670 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005671 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672
5673 final long identity = Binder.clearCallingIdentity();
5674 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005675 // NOTE: Before S, this method only set the default phone.
5676 for (final Phone phone : PhoneFactory.getPhones()) {
5677 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5678 phone.setImsRegistrationState(registered);
5679 }
5680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
Wink Saville36469e72014-06-11 15:17:00 -07005684 }
5685
5686 /**
Stuart Scott54788802015-03-30 13:18:01 -07005687 * Set the network selection mode to automatic.
5688 *
5689 */
5690 @Override
5691 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5693 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
shilufc958392020-01-20 11:36:01 -08005697 if (!isActiveSubscription(subId)) {
5698 return;
5699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005701 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5702 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
Stuart Scott54788802015-03-30 13:18:01 -07005706 }
5707
Jack Yud10cdd42020-09-28 20:28:01 -07005708 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005709 * Ask the radio to connect to the input network and change selection mode to manual.
5710 *
5711 * @param subId the id of the subscription.
5712 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5713 * the operator to attach to.
5714 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5715 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5716 * normal network selection next time.
5717 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005718 */
5719 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005720 public boolean setNetworkSelectionModeManual(
5721 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5723 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005724
5725 if (!isActiveSubscription(subId)) {
5726 return false;
5727 }
5728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 final long identity = Binder.clearCallingIdentity();
5730 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005731 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005733 if (DBG) {
5734 log("setNetworkSelectionModeManual: subId: " + subId
5735 + " operator: " + operatorInfo);
5736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005741 }
shilu84f6e8b2019-12-19 13:58:01 -08005742 /**
5743 * Get the manual network selection
5744 *
5745 * @param subId the id of the subscription.
5746 *
5747 * @return the previously saved user selected PLMN
5748 */
5749 @Override
5750 public String getManualNetworkSelectionPlmn(int subId) {
5751 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005752 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005753 mApp, subId, "getManualNetworkSelectionPlmn");
5754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 if (!isActiveSubscription(subId)) {
5758 return "";
5759 }
5760
5761 final Phone phone = getPhone(subId);
5762 if (phone == null) {
5763 return "";
5764 }
5765 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5766 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5767 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
5771 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005772
5773 /**
5774 * Scans for available networks.
5775 */
5776 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005777 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5778 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5780 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005781 LocationAccessPolicy.LocationPermissionResult locationResult =
5782 LocationAccessPolicy.checkLocationPermission(mApp,
5783 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5784 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005785 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005786 .setCallingPid(Binder.getCallingPid())
5787 .setCallingUid(Binder.getCallingUid())
5788 .setMethod("getCellNetworkScanResults")
5789 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07005790 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5791 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005792 .build());
5793 switch (locationResult) {
5794 case DENIED_HARD:
5795 throw new SecurityException("Not allowed to access scan results -- location");
5796 case DENIED_SOFT:
5797 return null;
5798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799
Pengquan Menga1bb6272018-09-06 09:59:22 -07005800 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801 try {
5802 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005803 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 } finally {
5806 Binder.restoreCallingIdentity(identity);
5807 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005808 }
5809
5810 /**
sqian80370722020-01-29 15:02:51 -08005811 * Get the call forwarding info, given the call forwarding reason.
5812 */
5813 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005814 public void getCallForwarding(int subId, int callForwardingReason,
5815 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005816 enforceReadPrivilegedPermission("getCallForwarding");
5817 long identity = Binder.clearCallingIdentity();
5818 try {
5819 if (DBG) {
5820 log("getCallForwarding: subId " + subId
5821 + " callForwardingReason" + callForwardingReason);
5822 }
Hall Liua1acea22020-09-18 19:04:59 -07005823
5824 Phone phone = getPhone(subId);
5825 if (phone == null) {
5826 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005827 callback.onError(
5828 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005829 } catch (RemoteException e) {
5830 // ignore
5831 }
5832 return;
5833 }
5834
5835 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5836 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5837 @Override
5838 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5839 try {
5840 callback.onCallForwardingInfoAvailable(info);
5841 } catch (RemoteException e) {
5842 // ignore
5843 }
5844 }
5845
5846 @Override
5847 public void onError(int error) {
5848 try {
5849 callback.onError(error);
5850 } catch (RemoteException e) {
5851 // ignore
5852 }
5853 }
5854 });
5855 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005856 } finally {
5857 Binder.restoreCallingIdentity(identity);
5858 }
5859 }
5860
5861 /**
5862 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5863 * reason, the number to forward, and the timeout before the forwarding is attempted.
5864 */
5865 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005866 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5867 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005868 enforceModifyPermission();
5869 long identity = Binder.clearCallingIdentity();
5870 try {
5871 if (DBG) {
5872 log("setCallForwarding: subId " + subId
5873 + " callForwardingInfo" + callForwardingInfo);
5874 }
Hall Liua1acea22020-09-18 19:04:59 -07005875
5876 Phone phone = getPhone(subId);
5877 if (phone == null) {
5878 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005879 callback.accept(
5880 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005881 } catch (RemoteException e) {
5882 // ignore
5883 }
5884 return;
5885 }
5886
5887 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5888 FunctionalUtils.ignoreRemoteException(callback::accept));
5889
5890 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
5894 }
5895
5896 /**
Hall Liua1acea22020-09-18 19:04:59 -07005897 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005898 */
5899 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005900 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWangc63cf522021-03-31 22:08:45 +08005901 enforceReadPrivilegedPermission("getCallWaitingStatus");
sqian80370722020-01-29 15:02:51 -08005902 long identity = Binder.clearCallingIdentity();
5903 try {
Hall Liua1acea22020-09-18 19:04:59 -07005904 Phone phone = getPhone(subId);
5905 if (phone == null) {
5906 try {
5907 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5908 } catch (RemoteException e) {
5909 // ignore
5910 }
5911 return;
5912 }
SongFerngWangc63cf522021-03-31 22:08:45 +08005913 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5914 PersistableBundle c = configManager.getConfigForSubId(subId);
5915 boolean requireUssd = c.getBoolean(
5916 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005917
sqian80370722020-01-29 15:02:51 -08005918 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWangc63cf522021-03-31 22:08:45 +08005919 if (requireUssd) {
5920 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5921 getSubscriptionCarrierId(subId));
5922 String newUssdCommand = "";
5923 try {
5924 newUssdCommand = carrierXmlParser.getFeature(
5925 CarrierXmlParser.FEATURE_CALL_WAITING)
5926 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
5927 } catch (NullPointerException e) {
5928 loge("Failed to generate USSD number" + e);
5929 }
5930 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5931 mMainThreadHandler, callback, carrierXmlParser,
5932 CarrierXmlParser.SsEntry.SSAction.QUERY);
5933 final String ussdCommand = newUssdCommand;
5934 Executors.newSingleThreadExecutor().execute(() -> {
5935 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5936 });
5937 } else {
5938 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
5939 callback::accept);
5940 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
5941 }
sqian80370722020-01-29 15:02:51 -08005942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
5945 }
5946
5947 /**
Hall Liua1acea22020-09-18 19:04:59 -07005948 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005949 */
5950 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005951 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005952 enforceModifyPermission();
5953 long identity = Binder.clearCallingIdentity();
5954 try {
Hall Liua1acea22020-09-18 19:04:59 -07005955 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5956
5957 Phone phone = getPhone(subId);
5958 if (phone == null) {
5959 try {
5960 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5961 } catch (RemoteException e) {
5962 // ignore
5963 }
5964 return;
5965 }
5966
SongFerngWangc63cf522021-03-31 22:08:45 +08005967 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5968 PersistableBundle c = configManager.getConfigForSubId(subId);
5969 boolean requireUssd = c.getBoolean(
5970 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005971
SongFerngWangc63cf522021-03-31 22:08:45 +08005972 if (DBG) log("getCallWaitingStatus: subId " + subId);
5973 if (requireUssd) {
5974 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5975 getSubscriptionCarrierId(subId));
5976 CarrierXmlParser.SsEntry.SSAction ssAction =
5977 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
5978 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
5979 String newUssdCommand = "";
5980 try {
5981 newUssdCommand = carrierXmlParser.getFeature(
5982 CarrierXmlParser.FEATURE_CALL_WAITING)
5983 .makeCommand(ssAction, null);
5984 } catch (NullPointerException e) {
5985 loge("Failed to generate USSD number" + e);
5986 }
5987 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5988 mMainThreadHandler, callback, carrierXmlParser, ssAction);
5989 final String ussdCommand = newUssdCommand;
5990 Executors.newSingleThreadExecutor().execute(() -> {
5991 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5992 });
5993 } else {
5994 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5995 FunctionalUtils.ignoreRemoteException(callback::accept));
5996
5997 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
5998 }
sqian80370722020-01-29 15:02:51 -08005999 } finally {
6000 Binder.restoreCallingIdentity(identity);
6001 }
6002 }
6003
6004 /**
yinxub1bed742017-04-17 11:45:04 -07006005 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006006 *
yinxub1bed742017-04-17 11:45:04 -07006007 * @param subId id of the subscription
6008 * @param request contains the radio access networks with bands/channels to scan
6009 * @param messenger callback messenger for scan results or errors
6010 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006011 * @return the id of the requested scan which can be used to stop the scan.
6012 */
6013 @Override
6014 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006015 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6017 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006018 LocationAccessPolicy.LocationPermissionResult locationResult =
6019 LocationAccessPolicy.checkLocationPermission(mApp,
6020 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6021 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006022 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006023 .setCallingPid(Binder.getCallingPid())
6024 .setCallingUid(Binder.getCallingUid())
6025 .setMethod("requestNetworkScan")
6026 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6027 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006028 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07006029 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6030 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006031 if (e != null) {
6032 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6033 throw e;
6034 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006035 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006036 return TelephonyScanManager.INVALID_SCAN_ID;
6037 }
6038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 }
Hall Liu912dfd32019-04-25 14:02:26 -07006040 int callingUid = Binder.getCallingUid();
6041 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006042 final long identity = Binder.clearCallingIdentity();
6043 try {
6044 return mNetworkScanRequestTracker.startNetworkScan(
6045 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006046 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006047 } finally {
6048 Binder.restoreCallingIdentity(identity);
6049 }
yinxu504e1392017-04-12 16:03:22 -07006050 }
6051
Hall Liub2ac8ef2019-02-28 15:56:23 -08006052 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07006053 NetworkScanRequest request, int subId, String callingPackage) {
6054 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006055 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6056 boolean hasNetworkScanPermission =
6057 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6058 == PERMISSION_GRANTED;
6059
6060 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6061 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6062 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006063 }
6064
6065 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6066 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006067 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6068 return new SecurityException("Specific channels must not be"
6069 + " scanned without location access.");
6070 }
6071 }
6072 }
6073
Hall Liub2ac8ef2019-02-28 15:56:23 -08006074 return null;
6075 }
6076
yinxu504e1392017-04-12 16:03:22 -07006077 /**
6078 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006079 *
6080 * @param subId id of the subscription
6081 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006082 */
6083 @Override
6084 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6086 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087
Hall Liu912dfd32019-04-25 14:02:26 -07006088 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 final long identity = Binder.clearCallingIdentity();
6090 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006091 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 } finally {
6093 Binder.restoreCallingIdentity(identity);
6094 }
yinxu504e1392017-04-12 16:03:22 -07006095 }
6096
6097 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006098 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006099 *
SongFerngWang9e060372020-12-21 16:41:52 +08006100 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006101 */
6102 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006103 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006104 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006105 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006106 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107
6108 final long identity = Binder.clearCallingIdentity();
6109 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006110 if (DBG) log("getAllowedNetworkTypesBitmask");
6111 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6112 int networkTypesBitmask = (result != null ? result[0] : -1);
6113 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6114 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006118 }
6119
6120 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006121 * Get the allowed network types for certain reason.
6122 *
6123 * @param subId the id of the subscription.
6124 * @param reason the reason the allowed network type change is taking place
6125 * @return the allowed network types.
6126 */
6127 @Override
6128 public long getAllowedNetworkTypesForReason(int subId,
6129 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006130 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006131 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006132 final long identity = Binder.clearCallingIdentity();
6133 try {
6134 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
6138 }
6139
6140 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006141 * Enable/Disable E-UTRA-NR Dual Connectivity
6142 * @param subId subscription id of the sim card
6143 * @param nrDualConnectivityState expected NR dual connectivity state
6144 * This can be passed following states
6145 * <ol>
6146 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6147 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6148 * <li>Disable NR dual connectivity and force secondary cell to be released
6149 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6150 * </ol>
6151 * @return operation result.
6152 */
6153 @Override
6154 public int setNrDualConnectivityState(int subId,
6155 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6157 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006158 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006159 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6160 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6161 }
6162
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006163 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6164 final long identity = Binder.clearCallingIdentity();
6165 try {
6166 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6167 nrDualConnectivityState, subId,
6168 workSource);
6169 if (DBG) log("enableNRDualConnectivity result: " + result);
6170 return result;
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
6174 }
6175
6176 /**
6177 * Is E-UTRA-NR Dual Connectivity enabled
6178 * @return true if dual connectivity is enabled else false
6179 */
6180 @Override
6181 public boolean isNrDualConnectivityEnabled(int subId) {
6182 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006183 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006184 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006185 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006186 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6187 return false;
6188 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006189 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6190 final long identity = Binder.clearCallingIdentity();
6191 try {
6192 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6193 null, subId, workSource);
6194 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6195 return isEnabled;
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
6199 }
6200
6201 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006202 * Set the allowed network types of the device and
6203 * provide the reason triggering the allowed network change.
6204 *
6205 * @param subId the id of the subscription.
6206 * @param reason the reason the allowed network type change is taking place
6207 * @param allowedNetworkTypes the allowed network types.
6208 * @return true on success; false on any failure.
6209 */
6210 @Override
6211 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006212 @TelephonyManager.AllowedNetworkTypesReason int reason,
6213 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6215 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006216 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6217 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6218 return false;
6219 }
6220
SongFerngWang522637d2021-03-02 22:09:29 +08006221 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6222 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6223
6224
6225 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6226 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6227 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006228 }
SongFerngWang522637d2021-03-02 22:09:29 +08006229
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006230 final long identity = Binder.clearCallingIdentity();
6231 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006232 Boolean success = (Boolean) sendRequest(
6233 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6234 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6235
6236 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6237 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006238 } finally {
6239 Binder.restoreCallingIdentity(identity);
6240 }
6241 }
6242
6243 /**
Miaoa84611c2019-03-15 09:21:10 +08006244 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006245 *
Miaoa84611c2019-03-15 09:21:10 +08006246 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006247 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006248 * @hide
6249 */
6250 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006251 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006252 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006254 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255 try {
Miaoa84611c2019-03-15 09:21:10 +08006256 if (phone != null) {
6257 return phone.hasMatchedTetherApnSetting();
6258 } else {
6259 return false;
6260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261 } finally {
6262 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006263 }
Junda Liu475951f2014-11-07 16:45:03 -08006264 }
6265
6266 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006267 * Enable or disable always reporting signal strength changes from radio.
6268 *
6269 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6270 */
6271 @Override
6272 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6273 enforceModifyPermission();
6274 enforceSystemCaller();
6275
6276 final long identity = Binder.clearCallingIdentity();
6277 final Phone phone = getPhone(subId);
6278 try {
6279 if (phone != null) {
6280 if (DBG) {
6281 log("setAlwaysReportSignalStrength: subId=" + subId
6282 + " isEnable=" + isEnable);
6283 }
6284 phone.setAlwaysReportSignalStrength(isEnable);
6285 } else {
6286 loge("setAlwaysReportSignalStrength: no phone found for subId="
6287 + subId);
6288 }
6289 } finally {
6290 Binder.restoreCallingIdentity(identity);
6291 }
6292 }
6293
6294 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006295 * Get the user enabled state of Mobile Data.
6296 *
6297 * TODO: remove and use isUserDataEnabled.
6298 * This can't be removed now because some vendor codes
6299 * calls through ITelephony directly while they should
6300 * use TelephonyManager.
6301 *
6302 * @return true on enabled
6303 */
6304 @Override
6305 public boolean getDataEnabled(int subId) {
6306 return isUserDataEnabled(subId);
6307 }
6308
6309 /**
6310 * Get whether mobile data is enabled per user setting.
6311 *
6312 * There are other factors deciding whether mobile data is actually enabled, but they are
6313 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006314 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006315 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006316 *
6317 * @return {@code true} if data is enabled else {@code false}
6318 */
6319 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006320 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006321 try {
6322 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6323 null);
6324 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6326 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006327 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006328
6329 final long identity = Binder.clearCallingIdentity();
6330 try {
6331 int phoneId = mSubscriptionController.getPhoneId(subId);
6332 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6333 Phone phone = PhoneFactory.getPhone(phoneId);
6334 if (phone != null) {
6335 boolean retVal = phone.isUserDataEnabled();
6336 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6337 return retVal;
6338 } else {
6339 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6340 return false;
6341 }
6342 } finally {
6343 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006344 }
6345 }
6346
6347 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006348 * Checks if the device is capable of mobile data by considering whether whether the
6349 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6350 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006351 *
Shuo Qian985d1232020-01-08 14:30:06 -08006352 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006353 */
6354 @Override
6355 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006356 try {
6357 try {
6358 mApp.enforceCallingOrSelfPermission(
6359 android.Manifest.permission.ACCESS_NETWORK_STATE,
6360 null);
6361 } catch (Exception e) {
6362 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6363 "isDataEnabled");
6364 }
6365 } catch (Exception e) {
6366 enforceReadPrivilegedPermission("isDataEnabled");
6367 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368
6369 final long identity = Binder.clearCallingIdentity();
6370 try {
6371 int phoneId = mSubscriptionController.getPhoneId(subId);
6372 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6373 Phone phone = PhoneFactory.getPhone(phoneId);
6374 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006375 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6377 return retVal;
6378 } else {
6379 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6380 return false;
6381 }
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006384 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006385 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006386
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006387 /**
6388 * Check if data is enabled for a specific reason
6389 * @param subId Subscription index
6390 * @param reason the reason the data enable change is taking place
6391 * @return {@code true} if the overall data is enabled; {@code false} if not.
6392 */
6393 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006394 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006395 @TelephonyManager.DataEnabledReason int reason) {
6396 try {
6397 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6398 null);
6399 } catch (Exception e) {
6400 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006401 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006402 }
6403
6404
6405 final long identity = Binder.clearCallingIdentity();
6406 try {
6407 int phoneId = mSubscriptionController.getPhoneId(subId);
6408 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006409 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006410 + " reason=" + reason);
6411 }
6412 Phone phone = PhoneFactory.getPhone(phoneId);
6413 if (phone != null) {
6414 boolean retVal;
6415 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6416 retVal = phone.isUserDataEnabled();
6417 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006418 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006419 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006420 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006421 return retVal;
6422 } else {
6423 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006424 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006425 + subId + " retVal=false");
6426 }
6427 return false;
6428 }
6429 } finally {
6430 Binder.restoreCallingIdentity(identity);
6431 }
6432 }
6433
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006434 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006435 Phone phone) {
Sarah Chinca45c312021-04-09 10:37:15 -07006436 if (uid == Process.PHONE_UID) {
6437 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6438 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liuce478d22020-07-13 12:13:03 -07006439 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6440 }
6441
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006442 //load access rules from carrier configs, and check those as well: b/139133814
6443 SubscriptionController subController = SubscriptionController.getInstance();
6444 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6445 || subController == null) return privilegeFromSim;
6446
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006447 PackageManager pkgMgr = phone.getContext().getPackageManager();
6448 String[] packages = pkgMgr.getPackagesForUid(uid);
6449
6450 final long identity = Binder.clearCallingIdentity();
6451 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006452 int subId = phone.getSubId();
6453 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6454 // A test override is in place for the privileges for this subId, so don't try to
6455 // read the subscription privileges.
6456 return privilegeFromSim;
6457 }
6458 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006459 SubscriptionManager subManager = (SubscriptionManager)
6460 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6461 for (String pkg : packages) {
6462 if (subManager.canManageSubscription(subInfo, pkg)) {
6463 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6464 }
6465 }
6466 return privilegeFromSim;
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
6469 }
6470 }
6471
6472 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6473 String pkgName) {
6474 //load access rules from carrier configs, and check those as well: b/139133814
6475 SubscriptionController subController = SubscriptionController.getInstance();
6476 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6477 || subController == null) return privilegeFromSim;
6478
6479 final long identity = Binder.clearCallingIdentity();
6480 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006481 int subId = phone.getSubId();
6482 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6483 // A test override is in place for the privileges for this subId, so don't try to
6484 // read the subscription privileges.
6485 return privilegeFromSim;
6486 }
6487 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006488 SubscriptionManager subManager = (SubscriptionManager)
6489 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6490 return subManager.canManageSubscription(subInfo, pkgName)
6491 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6492 } finally {
6493 Binder.restoreCallingIdentity(identity);
6494 }
6495 }
6496
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006497 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006498 public int getCarrierPrivilegeStatus(int subId) {
6499 final Phone phone = getPhone(subId);
6500 if (phone == null) {
6501 loge("getCarrierPrivilegeStatus: Invalid subId");
6502 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6503 }
6504 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006505 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006506 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006507 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6508 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006509
6510 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6511 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006512 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006513 }
Junda Liu29340342014-07-10 15:23:27 -07006514
6515 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006516 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006517 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006518 final Phone phone = getPhone(subId);
6519 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006520 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006521 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6522 }
6523 UiccProfile profile =
6524 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6525 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006526 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006527 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6528 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006529 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006530 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006531 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006532 }
6533
6534 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006535 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6536 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006537 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006538 }
6539
6540 int phoneId = SubscriptionManager.getPhoneId(subId);
6541 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006542 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006543 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006544 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6545 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006546 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6547 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6548 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006549 }
6550
6551 @Override
6552 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006553 if (TextUtils.isEmpty(pkgName))
6554 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006555 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6556 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6557 UiccCard card = UiccController.getInstance().getUiccCard(i);
6558 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006559 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006560 continue;
6561 }
6562
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006563 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6564 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6565 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006566 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6567 break;
6568 }
6569 }
6570
6571 return result;
Junda Liu29340342014-07-10 15:23:27 -07006572 }
Derek Tan89e89d42014-07-08 17:00:10 -07006573
6574 @Override
Junda Liue64de782015-04-16 17:19:16 -07006575 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6576 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6577 loge("phoneId " + phoneId + " is not valid.");
6578 return null;
6579 }
6580 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006581 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006582 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006583 return null ;
6584 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006585 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006586 }
6587
Amith Yamasani6e118872016-02-19 12:53:51 -08006588 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006589 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006590 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006591 List<String> privilegedPackages = new ArrayList<>();
6592 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006593 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6594 // has UICC in that slot.
6595 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006596 if (card.hasCarrierPrivilegeRules()) {
6597 if (packages == null) {
6598 // Only check packages in user 0 for now
6599 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006600 PackageManager.MATCH_DISABLED_COMPONENTS
6601 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006602 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006603 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006604 }
6605 for (int p = packages.size() - 1; p >= 0; p--) {
6606 PackageInfo pkgInfo = packages.get(p);
6607 if (pkgInfo != null && pkgInfo.packageName != null
6608 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006609 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006610 privilegedPackages.add(pkgInfo.packageName);
6611 }
6612 }
6613 }
6614 }
6615 return privilegedPackages;
6616 }
6617
chen xuf7e9fe82019-05-09 19:31:02 -07006618 @Override
6619 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006620 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6621
6622 final long identity = Binder.clearCallingIdentity();
6623
chen xuf7e9fe82019-05-09 19:31:02 -07006624 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006625 try {
6626 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6627 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6628 }
6629 } finally {
6630 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006631 }
6632 return privilegedPackages;
6633 }
6634
Wink Savilleb564aae2014-10-23 10:18:09 -07006635 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006636 final Phone phone = getPhone(subId);
6637 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006638 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006639 return null;
6640 }
6641 String iccId = card.getIccId();
6642 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006643 return null;
6644 }
6645 return iccId;
6646 }
6647
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006648 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006649 public void setCallComposerStatus(int subId, int status) {
6650 enforceModifyPermission();
6651
6652 final long identity = Binder.clearCallingIdentity();
6653 try {
6654 Phone phone = getPhone(subId);
6655 if (phone != null) {
6656 Phone defaultPhone = phone.getImsPhone();
6657 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6658 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6659 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006660 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6661 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006662 }
6663 }
Shuo Qiand8782462020-12-22 19:10:14 -08006664 } catch (ImsException e) {
6665 throw new ServiceSpecificException(e.getCode());
6666 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006667 Binder.restoreCallingIdentity(identity);
6668 }
6669 }
6670
6671 @Override
6672 public int getCallComposerStatus(int subId) {
6673 enforceReadPrivilegedPermission("getCallComposerStatus");
6674
6675 final long identity = Binder.clearCallingIdentity();
6676 try {
6677 Phone phone = getPhone(subId);
6678 if (phone != null) {
6679 Phone defaultPhone = phone.getImsPhone();
6680 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6681 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6682 return imsPhone.getCallComposerStatus();
6683 }
6684 }
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
6688 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6689 }
6690
6691 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006692 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6693 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006694 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006695 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 final long identity = Binder.clearCallingIdentity();
6698 try {
6699 final String iccId = getIccId(subId);
6700 final Phone phone = getPhone(subId);
6701 if (phone == null) {
6702 return false;
6703 }
6704 final String subscriberId = phone.getSubscriberId();
6705
6706 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006707 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 + subscriberId + " to " + number);
6709 }
6710
6711 if (TextUtils.isEmpty(iccId)) {
6712 return false;
6713 }
6714
6715 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6716
6717 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6718 if (alphaTag == null) {
6719 editor.remove(alphaTagPrefKey);
6720 } else {
6721 editor.putString(alphaTagPrefKey, alphaTag);
6722 }
6723
6724 // Record both the line number and IMSI for this ICCID, since we need to
6725 // track all merged IMSIs based on line number
6726 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6727 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6728 if (number == null) {
6729 editor.remove(numberPrefKey);
6730 editor.remove(subscriberPrefKey);
6731 } else {
6732 editor.putString(numberPrefKey, number);
6733 editor.putString(subscriberPrefKey, subscriberId);
6734 }
6735
6736 editor.commit();
6737 return true;
6738 } finally {
6739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006740 }
Derek Tan7226c842014-07-02 17:42:23 -07006741 }
6742
6743 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006744 public String getLine1NumberForDisplay(int subId, String callingPackage,
6745 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006746 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006748 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006749 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006750 return null;
6751 }
Derek Tan97ebb422014-09-05 16:55:38 -07006752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753 final long identity = Binder.clearCallingIdentity();
6754 try {
6755 String iccId = getIccId(subId);
6756 if (iccId != null) {
6757 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6758 if (DBG_MERGE) {
6759 log("getLine1NumberForDisplay returning "
6760 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6761 }
6762 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006763 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006764 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6765 return null;
6766 } finally {
6767 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006768 }
Derek Tan7226c842014-07-02 17:42:23 -07006769 }
6770
6771 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006772 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6773 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006775 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006776 return null;
6777 }
Derek Tan97ebb422014-09-05 16:55:38 -07006778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006779 final long identity = Binder.clearCallingIdentity();
6780 try {
6781 String iccId = getIccId(subId);
6782 if (iccId != null) {
6783 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6784 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6785 }
6786 return null;
6787 } finally {
6788 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006789 }
Derek Tan7226c842014-07-02 17:42:23 -07006790 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006791
6792 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006793 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6794 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006795 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6796 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006797 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006798 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006799 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006800 return null;
6801 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006802
Jordan Liub49b04b2019-05-06 14:45:15 -07006803 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6804 // the process, where TelephonyManager was instantiated.
6805 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006806 final long identity = Binder.clearCallingIdentity();
6807 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006808 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 final TelephonyManager tele = TelephonyManager.from(context);
6810 final SubscriptionManager sub = SubscriptionManager.from(context);
6811
6812 // Figure out what subscribers are currently active
6813 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814
Jordan Liub49b04b2019-05-06 14:45:15 -07006815 // Only consider subs which match the current subId
6816 // This logic can be simplified. See b/131189269 for progress.
6817 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006818 activeSubscriberIds.add(tele.getSubscriberId(subId));
6819 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820
6821 // First pass, find a number override for an active subscriber
6822 String mergeNumber = null;
6823 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6824 for (String key : prefs.keySet()) {
6825 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6826 final String subscriberId = (String) prefs.get(key);
6827 if (activeSubscriberIds.contains(subscriberId)) {
6828 final String iccId = key.substring(
6829 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6830 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6831 mergeNumber = (String) prefs.get(numberKey);
6832 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006833 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006834 + " for active subscriber " + subscriberId);
6835 }
6836 if (!TextUtils.isEmpty(mergeNumber)) {
6837 break;
6838 }
6839 }
6840 }
6841 }
6842
6843 // Shortcut when no active merged subscribers
6844 if (TextUtils.isEmpty(mergeNumber)) {
6845 return null;
6846 }
6847
6848 // Second pass, find all subscribers under that line override
6849 final ArraySet<String> result = new ArraySet<>();
6850 for (String key : prefs.keySet()) {
6851 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6852 final String number = (String) prefs.get(key);
6853 if (mergeNumber.equals(number)) {
6854 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6855 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6856 final String subscriberId = (String) prefs.get(subscriberKey);
6857 if (!TextUtils.isEmpty(subscriberId)) {
6858 result.add(subscriberId);
6859 }
6860 }
6861 }
6862 }
6863
6864 final String[] resultArray = result.toArray(new String[result.size()]);
6865 Arrays.sort(resultArray);
6866 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006867 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6869 }
6870 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006871 } finally {
6872 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006873 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006874 }
6875
6876 @Override
zoey chen38003472019-12-13 17:16:31 +08006877 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6878 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006879
6880 final long identity = Binder.clearCallingIdentity();
6881 try {
6882 final TelephonyManager telephonyManager = mApp.getSystemService(
6883 TelephonyManager.class);
6884 String subscriberId = telephonyManager.getSubscriberId(subId);
6885 if (subscriberId == null) {
6886 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006887 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006888 + subId);
6889 }
6890 return null;
6891 }
6892
6893 final SubscriptionInfo info = SubscriptionController.getInstance()
6894 .getSubscriptionInfo(subId);
6895 final ParcelUuid groupUuid = info.getGroupUuid();
6896 // If it doesn't belong to any group, return just subscriberId of itself.
6897 if (groupUuid == null) {
6898 return new String[]{subscriberId};
6899 }
6900
6901 // Get all subscriberIds from the group.
6902 final List<String> mergedSubscriberIds = new ArrayList<>();
6903 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006904 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006905 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006906 for (SubscriptionInfo subInfo : groupInfos) {
6907 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6908 if (subscriberId != null) {
6909 mergedSubscriberIds.add(subscriberId);
6910 }
6911 }
6912
6913 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6914 } finally {
6915 Binder.restoreCallingIdentity(identity);
6916
6917 }
6918 }
6919
6920 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006921 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006922 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006923 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006924
6925 final long identity = Binder.clearCallingIdentity();
6926 try {
6927 final Phone phone = getPhone(subId);
6928 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6929 } finally {
6930 Binder.restoreCallingIdentity(identity);
6931 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006932 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006933
6934 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006935 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006936 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6937 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006938 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6939 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006940
6941 final long identity = Binder.clearCallingIdentity();
6942 try {
6943 final Phone phone = getPhone(subId);
6944 if (phone == null) {
6945 return false;
6946 }
6947 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6948 cdmaNonRoamingList);
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006951 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006952 }
6953
6954 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006955 @Deprecated
6956 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6957 enforceModifyPermission();
6958
6959 int returnValue = 0;
6960 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006961 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006962 if(result.exception == null) {
6963 if (result.result != null) {
6964 byte[] responseData = (byte[])(result.result);
6965 if(responseData.length > oemResp.length) {
6966 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6967 responseData.length + "bytes. Buffer Size is " +
6968 oemResp.length + "bytes.");
6969 }
6970 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6971 returnValue = responseData.length;
6972 }
6973 } else {
6974 CommandException ex = (CommandException) result.exception;
6975 returnValue = ex.getCommandError().ordinal();
6976 if(returnValue > 0) returnValue *= -1;
6977 }
6978 } catch (RuntimeException e) {
6979 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6980 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6981 if(returnValue > 0) returnValue *= -1;
6982 }
6983
6984 return returnValue;
6985 }
6986
6987 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006988 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006989 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006990 try {
6991 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006992 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07006993 mApp, phone.getSubId(), "getRadioAccessFamily");
6994 } catch (SecurityException e) {
6995 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6996 throw e;
6997 }
chen xub97461a2018-10-26 14:17:57 -07006998 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006999 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007000 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 final long identity = Binder.clearCallingIdentity();
7003 try {
chen xub97461a2018-10-26 14:17:57 -07007004 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007005 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007006 mApp, phone.getSubId(), "getRadioAccessFamily");
7007 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
chen xub97461a2018-10-26 14:17:57 -07007011 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007012 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007013
7014 @Override
7015 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007016 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007017 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018
7019 final long identity = Binder.clearCallingIdentity();
7020 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007021 ImsManager.getInstance(defaultPhone.getContext(),
7022 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 } finally {
7024 Binder.restoreCallingIdentity(identity);
7025 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007026 }
7027
7028 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007029 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007030 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007031 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7032 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007033 return false;
7034 }
Svet Ganovb320e182015-04-16 12:30:10 -07007035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 final long identity = Binder.clearCallingIdentity();
7037 try {
7038 // Check the user preference and the system-level IMS setting. Even if the user has
7039 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7040 // In the long run, we may instead need to check if there exists a connection service
7041 // which can support video calling.
7042 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007043 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044 return imsManager.isVtEnabledByPlatform()
7045 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7046 && imsManager.isVtEnabledByUser();
7047 } finally {
7048 Binder.restoreCallingIdentity(identity);
7049 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007050 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007051
Andrew Leea1239f22015-03-02 17:44:07 -08007052 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007053 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7054 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007056 mApp, subId, callingPackage, callingFeatureId,
7057 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 return false;
7059 }
7060
7061 final long identity = Binder.clearCallingIdentity();
7062 try {
7063 CarrierConfigManager configManager =
7064 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007065 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7067 } finally {
7068 Binder.restoreCallingIdentity(identity);
7069 }
Andrew Leea1239f22015-03-02 17:44:07 -08007070 }
7071
7072 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007073 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007075 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007076 return false;
7077 }
7078
7079 final long identity = Binder.clearCallingIdentity();
7080 try {
7081 CarrierConfigManager configManager =
7082 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007083 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7085 } finally {
7086 Binder.restoreCallingIdentity(identity);
7087 }
Andrew Leea1239f22015-03-02 17:44:07 -08007088 }
7089
Andrew Lee9431b832015-03-09 18:46:45 -07007090 @Override
7091 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007092 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007093 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007094 }
7095
7096 @Override
7097 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098 final long identity = Binder.clearCallingIdentity();
7099 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007100 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101 } finally {
7102 Binder.restoreCallingIdentity(identity);
7103 }
Andrew Lee9431b832015-03-09 18:46:45 -07007104 }
7105
Hall Liuf6668912018-10-31 17:05:23 -07007106 /**
7107 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7108 * support for the feature and device firmware support.
7109 *
7110 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7111 */
7112 @Override
7113 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007115 final Phone phone = getPhone(subscriptionId);
7116 if (phone == null) {
7117 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7118 return false;
7119 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007120 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007121 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7123 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007124 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007125 return isCarrierSupported && isDeviceSupported;
7126 } finally {
7127 Binder.restoreCallingIdentity(identity);
7128 }
Hall Liu98187582018-01-22 19:15:32 -08007129 }
7130
Hall Liuf6668912018-10-31 17:05:23 -07007131 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007132 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7133 * RTT setting, will return true if the device and carrier both support RTT.
7134 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007135 */
7136 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 final long identity = Binder.clearCallingIdentity();
7138 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007139 boolean isRttSupported = isRttSupported(subscriptionId);
7140 boolean isUserRttSettingOn = Settings.Secure.getInt(
7141 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7142 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7143 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7144 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 } finally {
7146 Binder.restoreCallingIdentity(identity);
7147 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007148 }
7149
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007150 @Deprecated
7151 @Override
7152 public String getDeviceId(String callingPackage) {
7153 return getDeviceIdWithFeature(callingPackage, null);
7154 }
7155
Sanket Padawe7310cc72015-01-14 09:53:20 -08007156 /**
7157 * Returns the unique device ID of phone, for example, the IMEI for
7158 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7159 *
7160 * <p>Requires Permission:
7161 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7162 */
7163 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007164 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007165 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007166 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007167 return null;
7168 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007169 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007170 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007171 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007172 return null;
7173 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174
7175 final long identity = Binder.clearCallingIdentity();
7176 try {
7177 return phone.getDeviceId();
7178 } finally {
7179 Binder.restoreCallingIdentity(identity);
7180 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007181 }
7182
Ping Sunc67b7c22016-03-02 19:16:45 +08007183 /**
7184 * {@hide}
7185 * Returns the IMS Registration Status on a particular subid
7186 *
7187 * @param subId
7188 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007189 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007190 Phone phone = getPhone(subId);
7191 if (phone != null) {
7192 return phone.isImsRegistered();
7193 } else {
7194 return false;
7195 }
7196 }
7197
Santos Cordon7a1885b2015-02-03 11:15:19 -08007198 @Override
7199 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 final long identity = Binder.clearCallingIdentity();
7201 try {
7202 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7203 } finally {
7204 Binder.restoreCallingIdentity(identity);
7205 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007206 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007207
Tyler Gunnf70ed162019-04-03 15:28:53 -07007208 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007209 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007210 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007211 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007212 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007213 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7214 }
7215 final long identity = Binder.clearCallingIdentity();
7216 try {
7217 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
7220 }
7221 }
7222
7223 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007224 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007225 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7226 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007227 final long identity = Binder.clearCallingIdentity();
7228 try {
7229 Phone phone = getPhone(subscriptionId);
7230 if (phone == null) {
7231 return null;
7232 }
7233 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7234 } finally {
7235 Binder.restoreCallingIdentity(identity);
7236 }
7237 }
7238
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007239 /**
7240 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007241 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007242 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 final long identity = Binder.clearCallingIdentity();
7244 try {
7245 Phone phone = getPhone(subId);
7246 if (phone != null) {
7247 return phone.isWifiCallingEnabled();
7248 } else {
7249 return false;
7250 }
7251 } finally {
7252 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007253 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007254 }
7255
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007256 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007257 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007258 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007259 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 Phone phone = getPhone(subId);
7263 if (phone != null) {
7264 return phone.isVideoEnabled();
7265 } else {
7266 return false;
7267 }
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007270 }
7271 }
7272
7273 /**
7274 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7275 * defined in {@link ImsRegistrationImplBase}.
7276 */
7277 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 Phone phone = getPhone(subId);
7281 if (phone != null) {
7282 return phone.getImsRegistrationTech();
7283 } else {
7284 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7285 }
7286 } finally {
7287 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007288 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007289 }
7290
Stuart Scott8eef64f2015-04-08 15:13:54 -07007291 @Override
7292 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007293 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007294 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7295 return;
7296 }
7297
Svet Ganovcc087f82015-05-12 20:35:54 -07007298 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007299
Svet Ganovcc087f82015-05-12 20:35:54 -07007300 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007301 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7302 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007303 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007304 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007305 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007306 Phone phone = getPhone(subId);
SongFerngWang51ee2b12021-05-27 22:44:54 +08007307 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007308 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7309 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007310 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007311 // There has been issues when Sms raw table somehow stores orphan
7312 // fragments. They lead to garbled message when new fragments come
7313 // in and combined with those stale ones. In case this happens again,
7314 // user can reset all network settings which will clean up this table.
7315 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007316 // Clean up IMS settings as well here.
7317 int slotId = getSlotIndex(subId);
7318 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7319 ImsManager.getInstance(mApp, slotId).factoryReset();
7320 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007321
7322 // Erase modem config if erase modem on network setting is enabled.
7323 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7324 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7325 if (configValue != null && Boolean.parseBoolean(configValue)) {
7326 sendEraseModemConfig(getDefaultPhone());
7327 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007328 } finally {
7329 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007330 }
7331 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007332
SongFerngWang51ee2b12021-05-27 22:44:54 +08007333 @VisibleForTesting
7334 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7335 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7336 return;
7337 }
7338 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7339 RILConstants.PREFERRED_NETWORK_MODE);
7340 SubscriptionManager.setSubscriptionProperty(subId,
7341 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7342 "user=" + defaultNetworkType);
7343 phone.loadAllowedNetworksFromSubscriptionDatabase();
7344 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7345 defaultNetworkType, null);
7346 }
7347
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007348 private void cleanUpSmsRawTable(Context context) {
7349 ContentResolver resolver = context.getContentResolver();
7350 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7351 resolver.delete(uri, null, null);
7352 }
7353
Narayan Kamath1c496c22015-04-16 14:40:19 +01007354 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007355 public String getSimLocaleForSubscriber(int subId) {
7356 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7357 final Phone phone = getPhone(subId);
7358 if (phone == null) {
7359 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007360 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007361 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007362 final long identity = Binder.clearCallingIdentity();
7363 try {
chen xu5d3637b2019-01-21 23:31:38 -08007364 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007365 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007366 if (info == null) {
7367 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7368 return null;
7369 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370 // Try and fetch the locale from the carrier properties or from the SIM language
7371 // preferences (EF-PL and EF-LI)...
7372 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007374 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7375 if (localeFromDefaultSim != null) {
7376 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7377 if (DBG) log("Using locale from subId: " + subId + " locale: "
7378 + localeFromDefaultSim);
7379 return localeFromDefaultSim.toLanguageTag();
7380 } else {
7381 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 }
7383 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 // The SIM language preferences only store a language (e.g. fr = French), not an
7386 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7387 // the SIM and carrier preferences does not include a country we add the country
7388 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007389 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007391 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 return mccLocale.toLanguageTag();
7393 }
7394
7395 if (DBG) log("No locale found - returning null");
7396 return null;
7397 } finally {
7398 Binder.restoreCallingIdentity(identity);
7399 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007400 }
7401
7402 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007403 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007404 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007405 }
7406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 /**
7408 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7409 */
7410 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007411 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007412 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007413 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007414
Chenjie Yu1ba97252018-01-11 18:16:20 -08007415 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007416 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007417
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007418 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007419 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7420 * representing the state of the modem.
7421 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007422 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7423 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007424 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007425 */
7426 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007427 public void requestModemActivityInfo(ResultReceiver result) {
7428 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007429 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430
7431 final long identity = Binder.clearCallingIdentity();
7432 try {
sqian1a1be542020-03-05 11:37:28 -08007433 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 } finally {
7435 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007436 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007437 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007438
Siddharth Rayb8114062018-06-17 15:02:38 -07007439 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7440 // less than total activity duration.
7441 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7442 if (info == null) {
7443 return false;
7444 }
7445 int activityDurationMs =
7446 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7447 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007448 int[] txTimeMs = info.getTransmitTimeMillis();
7449 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7450 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007451 }
7452 return (info.isValid()
7453 && (info.getSleepTimeMillis() <= activityDurationMs)
7454 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007455 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007456 && (totalTxTimeMs <= activityDurationMs));
7457 }
7458
Jack Yu85bd38a2015-11-09 11:34:32 -08007459 /**
7460 * {@hide}
7461 * Returns the service state information on specified subscription.
7462 */
7463 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007464 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7465 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007467 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007468 return null;
7469 }
7470
Hall Liuf19c44f2018-11-27 14:38:17 -08007471 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7472 LocationAccessPolicy.checkLocationPermission(mApp,
7473 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7474 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007475 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007476 .setCallingPid(Binder.getCallingPid())
7477 .setCallingUid(Binder.getCallingUid())
7478 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007479 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007480 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007481 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7482 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007483 .build());
7484
7485 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7486 LocationAccessPolicy.checkLocationPermission(mApp,
7487 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7488 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007489 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007490 .setCallingPid(Binder.getCallingPid())
7491 .setCallingUid(Binder.getCallingUid())
7492 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007493 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007494 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007495 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7496 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007497 .build());
7498 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7499 boolean hasFinePermission =
7500 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7501 boolean hasCoarsePermission =
7502 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 final long identity = Binder.clearCallingIdentity();
7505 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007506 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7507 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7508 Rlog.d(LOG_TAG,
7509 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7510 return null;
7511 }
7512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 final Phone phone = getPhone(subId);
7514 if (phone == null) {
7515 return null;
7516 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007517
Hall Liuf19c44f2018-11-27 14:38:17 -08007518 ServiceState ss = phone.getServiceState();
7519
7520 // Scrub out the location info in ServiceState depending on what level of access
7521 // the caller has.
7522 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007523 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7524 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007528 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007529
7530 /**
7531 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7532 *
7533 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7534 * voicemail ringtone.
7535 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7536 * PhoneAccount.
7537 */
7538 @Override
7539 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 final long identity = Binder.clearCallingIdentity();
7541 try {
7542 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7543 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007544 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7548 } finally {
7549 Binder.restoreCallingIdentity(identity);
7550 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007551 }
7552
7553 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007554 * Sets the per-account voicemail ringtone.
7555 *
7556 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7557 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7558 *
7559 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7560 * voicemail ringtone.
7561 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7562 * PhoneAccount.
7563 */
7564 @Override
7565 public void setVoicemailRingtoneUri(String callingPackage,
7566 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007567 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007568 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007569 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7570 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7572 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7573 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007574 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007575
7576 final long identity = Binder.clearCallingIdentity();
7577 try {
7578 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7579 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007580 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581 }
7582 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7583 } finally {
7584 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007585 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007586 }
7587
7588 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007589 * Returns whether vibration is set for voicemail notification in Phone settings.
7590 *
7591 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7592 * voicemail vibration setting.
7593 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7594 */
7595 @Override
7596 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 final long identity = Binder.clearCallingIdentity();
7598 try {
7599 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7600 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007601 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
7607 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007608 }
7609
Youhan Wange64578a2016-05-02 15:32:42 -07007610 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007611 * Sets the per-account voicemail vibration.
7612 *
7613 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7614 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7615 *
7616 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7617 * voicemail vibration setting.
7618 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7619 * specific PhoneAccount.
7620 */
7621 @Override
7622 public void setVoicemailVibrationEnabled(String callingPackage,
7623 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007624 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007625 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007626 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7627 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7629 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7630 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007631 }
7632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007633 final long identity = Binder.clearCallingIdentity();
7634 try {
7635 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7636 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007637 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007638 }
7639 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7640 } finally {
7641 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007642 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007643 }
7644
7645 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007646 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7647 *
7648 * @throws SecurityException if the caller does not have the required permission
7649 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007650 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007651 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007652 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007653 }
7654
7655 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007656 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7657 * permission.
7658 *
7659 * @throws SecurityException if the caller does not have the required permission
7660 */
7661 private void enforceSendSmsPermission() {
7662 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7663 }
7664
7665 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007666 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007667 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007668 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007669 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007670 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671 final long identity = Binder.clearCallingIdentity();
7672 try {
7673 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007674 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 if (componentName == null) {
7676 throw new SecurityException(
7677 "Caller not current active visual voicemail package[null]");
7678 }
7679 String vvmPackage = componentName.getPackageName();
7680 if (!callingPackage.equals(vvmPackage)) {
7681 throw new SecurityException("Caller not current active visual voicemail package["
7682 + vvmPackage + "]");
7683 }
7684 } finally {
7685 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007686 }
7687 }
7688
7689 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007690 * Return the application ID for the app type.
7691 *
7692 * @param subId the subscription ID that this request applies to.
7693 * @param appType the uicc app type.
7694 * @return Application ID for specificied app type, or null if no uicc.
7695 */
7696 @Override
7697 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007698 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007699 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700
7701 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007702 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703 if (phone == null) {
7704 return null;
7705 }
7706 String aid = null;
7707 try {
7708 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7709 .getApplicationByType(appType).getAid();
7710 } catch (Exception e) {
7711 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7712 }
7713 return aid;
7714 } finally {
7715 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007716 }
Youhan Wange64578a2016-05-02 15:32:42 -07007717 }
7718
Youhan Wang4001d252016-05-11 10:29:41 -07007719 /**
7720 * Return the Electronic Serial Number.
7721 *
7722 * @param subId the subscription ID that this request applies to.
7723 * @return ESN or null if error.
7724 */
7725 @Override
7726 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007727 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007728 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729
7730 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007731 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 if (phone == null) {
7733 return null;
7734 }
7735 String esn = null;
7736 try {
7737 esn = phone.getEsn();
7738 } catch (Exception e) {
7739 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7740 }
7741 return esn;
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007744 }
Youhan Wang4001d252016-05-11 10:29:41 -07007745 }
7746
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007747 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007748 * Return the Preferred Roaming List Version.
7749 *
7750 * @param subId the subscription ID that this request applies to.
7751 * @return PRLVersion or null if error.
7752 */
7753 @Override
7754 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007755 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007756 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757
7758 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007759 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 if (phone == null) {
7761 return null;
7762 }
7763 String cdmaPrlVersion = null;
7764 try {
7765 cdmaPrlVersion = phone.getCdmaPrlVersion();
7766 } catch (Exception e) {
7767 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7768 }
7769 return cdmaPrlVersion;
7770 } finally {
7771 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007772 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007773 }
7774
7775 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007776 * Get snapshot of Telephony histograms
7777 * @return List of Telephony histograms
7778 * @hide
7779 */
7780 @Override
7781 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7783 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784
7785 final long identity = Binder.clearCallingIdentity();
7786 try {
7787 return RIL.getTelephonyRILTimingHistograms();
7788 } finally {
7789 Binder.restoreCallingIdentity(identity);
7790 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007791 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007792
7793 /**
7794 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007795 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7796 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007797 * Require system privileges. In the future we may add this to carrier APIs.
7798 *
Michele Berionne482f8202018-11-27 18:57:59 -08007799 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007800 */
7801 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007802 @TelephonyManager.SetCarrierRestrictionResult
7803 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007804 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007805 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007806
Michele Berionne482f8202018-11-27 18:57:59 -08007807 if (carrierRestrictionRules == null) {
7808 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007809 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007811 final long identity = Binder.clearCallingIdentity();
7812 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007813 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007814 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 } finally {
7816 Binder.restoreCallingIdentity(identity);
7817 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007818 }
7819
7820 /**
7821 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007822 * Get the allowed carrier list and the excluded carrier list, including the priority between
7823 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007824 * Require system privileges. In the future we may add this to carrier APIs.
7825 *
Michele Berionne482f8202018-11-27 18:57:59 -08007826 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007827 */
7828 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007829 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007830 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007831 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007832
7833 final long identity = Binder.clearCallingIdentity();
7834 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007835 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7836 if (response instanceof CarrierRestrictionRules) {
7837 return (CarrierRestrictionRules) response;
7838 }
7839 // Response is an Exception of some kind,
7840 // which is signalled to the user as a NULL retval
7841 return null;
7842 } catch (Exception e) {
7843 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7844 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 } finally {
7846 Binder.restoreCallingIdentity(identity);
7847 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007848 }
7849
fionaxu59545b42016-05-25 15:53:37 -07007850 /**
fionaxu59545b42016-05-25 15:53:37 -07007851 * Action set from carrier signalling broadcast receivers to enable/disable radio
7852 * @param subId the subscription ID that this action applies to.
7853 * @param enabled control enable or disable radio.
7854 * {@hide}
7855 */
7856 @Override
7857 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7858 enforceModifyPermission();
7859 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860
7861 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007862 if (phone == null) {
7863 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7864 return;
7865 }
7866 try {
7867 phone.carrierActionSetRadioEnabled(enabled);
7868 } catch (Exception e) {
7869 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 } finally {
7871 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007872 }
7873 }
7874
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007875 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007876 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7877 * network status based on which carrier apps could apply actions accordingly,
7878 * enable/disable default url handler for example.
7879 *
7880 * @param subId the subscription ID that this action applies to.
7881 * @param report control start/stop reporting the default network status.
7882 * {@hide}
7883 */
7884 @Override
7885 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7886 enforceModifyPermission();
7887 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888
7889 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007890 if (phone == null) {
7891 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7892 return;
7893 }
7894 try {
7895 phone.carrierActionReportDefaultNetworkStatus(report);
7896 } catch (Exception e) {
7897 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 } finally {
7899 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007900 }
7901 }
7902
7903 /**
fionaxud9622282017-07-17 17:51:30 -07007904 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7905 * @param subId the subscription ID that this action applies to.
7906 * {@hide}
7907 */
7908 @Override
7909 public void carrierActionResetAll(int subId) {
7910 enforceModifyPermission();
7911 final Phone phone = getPhone(subId);
7912 if (phone == null) {
7913 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7914 return;
7915 }
7916 try {
7917 phone.carrierActionResetAll();
7918 } catch (Exception e) {
7919 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7920 }
7921 }
7922
7923 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007924 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7925 * bug report is being generated.
7926 */
7927 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007928 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007929 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7930 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007931 writer.println("Permission Denial: can't dump Phone from pid="
7932 + Binder.getCallingPid()
7933 + ", uid=" + Binder.getCallingUid()
7934 + "without permission "
7935 + android.Manifest.permission.DUMP);
7936 return;
7937 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007938 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007939 }
Jack Yueb89b242016-06-22 13:27:47 -07007940
Brad Ebingerdac2f002018-04-03 15:17:52 -07007941 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007942 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7943 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7944 @NonNull String[] args) {
7945 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7946 this, in.getFileDescriptor(), out.getFileDescriptor(),
7947 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007948 }
7949
Jack Yueb89b242016-06-22 13:27:47 -07007950 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007951 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007952 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007953 * @param reason the reason the data enable change is taking place
7954 * @param enabled True if enabling the data, otherwise disabling.
7955 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007956 */
7957 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007958 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007959 boolean enabled) {
7960 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7961 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7962 try {
7963 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007964 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007965 } catch (SecurityException se) {
7966 enforceModifyPermission();
7967 }
7968 } else {
7969 enforceModifyPermission();
7970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007971
7972 final long identity = Binder.clearCallingIdentity();
7973 try {
7974 Phone phone = getPhone(subId);
7975 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007976 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7977 phone.carrierActionSetMeteredApnsEnabled(enabled);
7978 } else {
7979 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007981 }
7982 } finally {
7983 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007984 }
7985 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007986
7987 /**
7988 * Get Client request stats
7989 * @return List of Client Request Stats
7990 * @hide
7991 */
7992 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007993 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7994 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007996 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007997 return null;
7998 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007999 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 final long identity = Binder.clearCallingIdentity();
8002 try {
8003 if (phone != null) {
8004 return phone.getClientRequestStats();
8005 }
8006
8007 return null;
8008 } finally {
8009 Binder.restoreCallingIdentity(identity);
8010 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008011 }
8012
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008013 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008014 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008015 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008016 }
Jack Yueb4124c2017-02-16 15:32:43 -08008017
8018 /**
Grace Chen70990072017-03-24 17:21:30 -07008019 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008020 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008021 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008022 * @param state State of SIM (power down, power up, pass through)
8023 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8024 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8025 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008026 *
8027 **/
8028 @Override
Grace Chen70990072017-03-24 17:21:30 -07008029 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008030 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008031 Phone phone = PhoneFactory.getPhone(slotIndex);
8032
vagdeviaf9a5b92018-08-15 16:01:53 -07008033 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 final long identity = Binder.clearCallingIdentity();
8036 try {
8037 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008038 phone.setSimPowerState(state, null, workSource);
8039 }
8040 } finally {
8041 Binder.restoreCallingIdentity(identity);
8042 }
8043 }
8044
8045 /**
8046 * Set SIM card power state.
8047 *
8048 * @param slotIndex SIM slot id.
8049 * @param state State of SIM (power down, power up, pass through)
8050 * @param callback callback to trigger after success or failure
8051 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8052 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8053 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8054 *
8055 **/
8056 @Override
8057 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8058 IIntegerConsumer callback) {
8059 enforceModifyPermission();
8060 Phone phone = PhoneFactory.getPhone(slotIndex);
8061
8062 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8063
8064 final long identity = Binder.clearCallingIdentity();
8065 try {
8066 if (phone != null) {
8067 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8068 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008069 }
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008072 }
8073 }
Shuo Qiandd210312017-04-12 22:11:33 +00008074
Tyler Gunn65d45c22017-06-05 11:22:26 -07008075 private boolean isUssdApiAllowed(int subId) {
8076 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008077 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008078 if (configManager == null) {
8079 return false;
8080 }
8081 PersistableBundle pb = configManager.getConfigForSubId(subId);
8082 if (pb == null) {
8083 return false;
8084 }
8085 return pb.getBoolean(
8086 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8087 }
8088
Shuo Qiandd210312017-04-12 22:11:33 +00008089 /**
8090 * Check if phone is in emergency callback mode
8091 * @return true if phone is in emergency callback mode
8092 * @param subId sub id
8093 */
goneil9c5f4872017-12-05 14:07:56 -08008094 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008095 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008096 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008097 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098
8099 final long identity = Binder.clearCallingIdentity();
8100 try {
8101 if (phone != null) {
8102 return phone.isInEcm();
8103 } else {
8104 return false;
8105 }
8106 } finally {
8107 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008108 }
8109 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008110
8111 /**
8112 * Get the current signal strength information for the given subscription.
8113 * Because this information is not updated when the device is in a low power state
8114 * it should not be relied-upon to be current.
8115 * @param subId Subscription index
8116 * @return the most recent cached signal strength info from the modem
8117 */
8118 @Override
8119 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008120 final long identity = Binder.clearCallingIdentity();
8121 try {
8122 Phone p = getPhone(subId);
8123 if (p == null) {
8124 return null;
8125 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 return p.getSignalStrength();
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008131 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008132
Pengquan Meng77b7f132018-08-22 14:49:57 -07008133 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008134 * Get the current modem radio state for the given slot.
8135 * @param slotIndex slot index.
8136 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008137 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008138 * @return the current radio power state from the modem
8139 */
8140 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008141 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008142 Phone phone = PhoneFactory.getPhone(slotIndex);
8143 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8145 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008146 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8147 }
8148
8149 final long identity = Binder.clearCallingIdentity();
8150 try {
8151 return phone.getRadioPowerState();
8152 } finally {
8153 Binder.restoreCallingIdentity(identity);
8154 }
8155 }
8156 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8157 }
8158
8159 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008160 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8161 *
8162 * <p>Requires one of the following permissions:
8163 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8164 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8165 * privileges.
8166 *
8167 * @param subId subscription id
8168 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8169 * {@code false}.
8170 */
8171 @Override
8172 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008173 try {
8174 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8175 null);
8176 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008177 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008178 mApp, subId, "isDataRoamingEnabled");
8179 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008180
Pengquan Menga1bb6272018-09-06 09:59:22 -07008181 boolean isEnabled = false;
8182 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008183 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008184 Phone phone = getPhone(subId);
8185 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008186 } finally {
8187 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008188 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008189 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008190 }
8191
8192
8193 /**
8194 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8195 *
8196 * <p> Requires permission:
8197 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8198 * privileges.
8199 *
8200 * @param subId subscription id
8201 * @param isEnabled {@code true} means enable, {@code false} means disable.
8202 */
8203 @Override
8204 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8206 mApp, subId, "setDataRoamingEnabled");
8207
Pengquan Menga1bb6272018-09-06 09:59:22 -07008208 final long identity = Binder.clearCallingIdentity();
8209 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008210 Phone phone = getPhone(subId);
8211 if (phone != null) {
8212 phone.setDataRoamingEnabled(isEnabled);
8213 }
8214 } finally {
8215 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008216 }
8217 }
8218
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008219 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008220 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008221 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008222 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008223 mApp, subId, "isManualNetworkSelectionAllowed");
8224
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008225 boolean isAllowed = true;
8226 final long identity = Binder.clearCallingIdentity();
8227 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008228 Phone phone = getPhone(subId);
8229 if (phone != null) {
8230 isAllowed = phone.isCspPlmnEnabled();
8231 }
8232 } finally {
8233 Binder.restoreCallingIdentity(identity);
8234 }
8235 return isAllowed;
8236 }
8237
8238 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008239 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008240 // Verify that tha callingPackage belongs to the calling UID
8241 mApp.getSystemService(AppOpsManager.class)
8242 .checkPackage(Binder.getCallingUid(), callingPackage);
8243
Jordan Liu1e142fc2019-04-22 15:10:43 -07008244 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008245 try {
8246 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008247 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008248 } catch (SecurityException e) {
8249 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8250 // has carrier privileges on an active UICC
8251 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8252 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008253 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008254 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008255 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008256
8257 final long identity = Binder.clearCallingIdentity();
8258 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008259 UiccController uiccController = UiccController.getInstance();
8260 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008261 if (hasReadPermission) {
8262 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008263 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008264
8265 // Remove private info if the caller doesn't have access
8266 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8267 for (UiccCardInfo cardInfo : cardInfos) {
8268 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8269 // is available
8270 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8271 if (card == null || card.getUiccProfile() == null) {
8272 // assume no access if the card or profile is unavailable
8273 filteredInfos.add(cardInfo.getUnprivileged());
8274 continue;
8275 }
8276 UiccProfile profile = card.getUiccProfile();
8277 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8278 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8279 filteredInfos.add(cardInfo);
8280 } else {
8281 filteredInfos.add(cardInfo.getUnprivileged());
8282 }
8283 }
8284 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008285 } finally {
8286 Binder.restoreCallingIdentity(identity);
8287 }
8288 }
8289
8290 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008291 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008292 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294 final long identity = Binder.clearCallingIdentity();
8295 try {
8296 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8297 if (slots == null) {
8298 Rlog.i(LOG_TAG, "slots is null.");
8299 return null;
8300 }
8301
8302 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8303 for (int i = 0; i < slots.length; i++) {
8304 UiccSlot slot = slots[i];
8305 if (slot == null) {
8306 continue;
8307 }
8308
Jordan Liu7be7e652019-05-06 18:55:02 +00008309 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008310 UiccCard card = slot.getUiccCard();
8311 if (card != null) {
8312 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008313 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008314 cardId = slot.getEid();
8315 if (TextUtils.isEmpty(cardId)) {
8316 cardId = slot.getIccId();
8317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008318 }
8319
Jordan Liu857451f2019-05-09 16:35:35 -07008320 if (cardId != null) {
8321 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8322 // if cardId is an EID, it's all digits so this is fine
8323 cardId = IccUtils.stripTrailingFs(cardId);
8324 }
8325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008326 int cardState = 0;
8327 switch (slot.getCardState()) {
8328 case CARDSTATE_ABSENT:
8329 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8330 break;
8331 case CARDSTATE_PRESENT:
8332 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8333 break;
8334 case CARDSTATE_ERROR:
8335 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8336 break;
8337 case CARDSTATE_RESTRICTED:
8338 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8339 break;
8340 default:
8341 break;
8342
8343 }
8344
8345 infos[i] = new UiccSlotInfo(
8346 slot.isActive(),
8347 slot.isEuicc(),
8348 cardId,
8349 cardState,
8350 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008351 slot.isExtendedApduSupported(),
8352 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008353 }
8354 return infos;
8355 } finally {
8356 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008357 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008358 }
8359
8360 @Override
8361 public boolean switchSlots(int[] physicalSlots) {
8362 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363
8364 final long identity = Binder.clearCallingIdentity();
8365 try {
8366 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8367 } finally {
8368 Binder.restoreCallingIdentity(identity);
8369 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008370 }
Jack Yu4c988042018-02-27 15:30:01 -08008371
8372 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008373 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008374 final long identity = Binder.clearCallingIdentity();
8375 try {
8376 return UiccController.getInstance().getCardIdForDefaultEuicc();
8377 } finally {
8378 Binder.restoreCallingIdentity(identity);
8379 }
8380 }
8381
Pengquan Meng85728fb2018-03-12 16:31:21 -07008382 /**
goneil47ffb6e2018-04-06 15:40:58 -07008383 * A test API to reload the UICC profile.
8384 *
8385 * <p>Requires that the calling app has permission
8386 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8387 * @hide
8388 */
8389 @Override
8390 public void refreshUiccProfile(int subId) {
8391 enforceModifyPermission();
8392
8393 final long identity = Binder.clearCallingIdentity();
8394 try {
8395 Phone phone = getPhone(subId);
8396 if (phone == null) {
8397 return;
8398 }
8399 UiccCard uiccCard = phone.getUiccCard();
8400 if (uiccCard == null) {
8401 return;
8402 }
8403 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8404 if (uiccProfile == null) {
8405 return;
8406 }
8407 uiccProfile.refresh();
8408 } finally {
8409 Binder.restoreCallingIdentity(identity);
8410 }
8411 }
8412
8413 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008414 * Returns false if the mobile data is disabled by default, otherwise return true.
8415 */
8416 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008417 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008418 }
8419
8420 /**
8421 * Returns true if the data roaming is enabled by default, i.e the system property
8422 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8423 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8424 */
8425 private boolean getDefaultDataRoamingEnabled(int subId) {
8426 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008427 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008428 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008429 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8430 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8431 return isDataRoamingEnabled;
8432 }
8433
8434 /**
8435 * Returns the default network type for the given {@code subId}, if the default network type is
8436 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8437 */
8438 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008439 List<Integer> list = TelephonyProperties.default_network();
8440 int phoneId = mSubscriptionController.getPhoneId(subId);
8441 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8442 return list.get(phoneId);
8443 }
8444 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008445 }
fionaxua13278b2018-03-21 00:08:13 -07008446
8447 @Override
8448 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008449 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008450 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008451
8452 final long identity = Binder.clearCallingIdentity();
8453 try {
8454 final Phone phone = getPhone(subId);
8455 if (phone == null) {
8456 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8457 return;
8458 }
chen xueaba88a2019-03-15 13:15:10 -07008459 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8460 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008461 if (carrierPrivilegeRules == null) {
8462 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8463 } else {
8464 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466 } finally {
8467 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008468 }
fionaxua13278b2018-03-21 00:08:13 -07008469 }
8470
8471 @Override
8472 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008473 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008474
8475 final long identity = Binder.clearCallingIdentity();
8476 try {
8477 final Phone phone = getPhone(subId);
8478 if (phone == null) {
8479 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8480 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8481 }
8482 return phone.getCarrierIdListVersion();
8483 } finally {
8484 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008485 }
fionaxua13278b2018-03-21 00:08:13 -07008486 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008487
8488 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008489 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8490 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008491 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008492 mApp, subId, callingPackage, callingFeatureId,
8493 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008494 return -1;
8495 }
8496
8497 final long identity = Binder.clearCallingIdentity();
8498 try {
8499 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8500 } finally {
8501 Binder.restoreCallingIdentity(identity);
8502 }
8503 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008504
8505 @Override
8506 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008507 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008508 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008509 mApp, subId, "getCdmaRoamingMode");
8510
8511 final long identity = Binder.clearCallingIdentity();
8512 try {
8513 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8514 } finally {
8515 Binder.restoreCallingIdentity(identity);
8516 }
8517 }
8518
8519 @Override
8520 public boolean setCdmaRoamingMode(int subId, int mode) {
8521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8522 mApp, subId, "setCdmaRoamingMode");
8523
8524 final long identity = Binder.clearCallingIdentity();
8525 try {
8526 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8527 } finally {
8528 Binder.restoreCallingIdentity(identity);
8529 }
8530 }
8531
8532 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008533 public int getCdmaSubscriptionMode(int subId) {
8534 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008535 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008536 mApp, subId, "getCdmaSubscriptionMode");
8537
8538 final long identity = Binder.clearCallingIdentity();
8539 try {
8540 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8541 } finally {
8542 Binder.restoreCallingIdentity(identity);
8543 }
8544 }
8545
8546 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008547 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8549 mApp, subId, "setCdmaSubscriptionMode");
8550
8551 final long identity = Binder.clearCallingIdentity();
8552 try {
8553 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8554 } finally {
8555 Binder.restoreCallingIdentity(identity);
8556 }
8557 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008558
sqianc5eccab2018-10-19 18:46:41 -07008559 @Override
sqian8c685422019-02-22 15:55:18 -08008560 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008561 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008562 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008563 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8564 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008565 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8566 }
8567 final long identity = Binder.clearCallingIdentity();
8568 try {
sqian854d44b2018-12-12 16:48:18 -08008569 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8570 for (Phone phone: PhoneFactory.getPhones()) {
8571 if (phone.getEmergencyNumberTracker() != null
8572 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8573 emergencyNumberListInternal.put(
8574 phone.getSubId(),
8575 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8576 }
sqian11b7a0e2018-12-05 18:48:28 -08008577 }
sqian854d44b2018-12-12 16:48:18 -08008578 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008579 } finally {
8580 Binder.restoreCallingIdentity(identity);
8581 }
sqianc5eccab2018-10-19 18:46:41 -07008582 }
8583
8584 @Override
sqian8c685422019-02-22 15:55:18 -08008585 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008586 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008587 if (!exactMatch) {
8588 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008589 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008590 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008591 }
8592 final long identity = Binder.clearCallingIdentity();
8593 try {
sqian854d44b2018-12-12 16:48:18 -08008594 for (Phone phone: PhoneFactory.getPhones()) {
8595 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008596 && phone.getEmergencyNumberTracker()
8597 .isEmergencyNumber(number, exactMatch)) {
8598 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008599 }
sqian11b7a0e2018-12-05 18:48:28 -08008600 }
8601 return false;
8602 } finally {
8603 Binder.restoreCallingIdentity(identity);
8604 }
8605 }
8606
sqianf4ca7ed2019-01-15 18:32:07 -08008607 /**
Shuo Qian479dd9e2021-02-22 18:32:21 -08008608 * Start emergency callback mode for GsmCdmaPhone for testing.
8609 */
8610 @Override
8611 public void startEmergencyCallbackMode() {
8612 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8613 "startEmergencyCallbackMode");
8614 enforceModifyPermission();
8615 final long identity = Binder.clearCallingIdentity();
8616 try {
8617 for (Phone phone : PhoneFactory.getPhones()) {
8618 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8619 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8620 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8621 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8622 gsmCdmaPhone.obtainMessage(
8623 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8624 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8625 }
8626 }
8627 } finally {
8628 Binder.restoreCallingIdentity(identity);
8629 }
8630 }
8631
8632 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008633 * Update emergency number list for test mode.
8634 */
8635 @Override
8636 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8637 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8638 "updateEmergencyNumberListTestMode");
8639
8640 final long identity = Binder.clearCallingIdentity();
8641 try {
8642 for (Phone phone: PhoneFactory.getPhones()) {
8643 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8644 if (tracker != null) {
8645 tracker.executeEmergencyNumberTestModeCommand(action, num);
8646 }
8647 }
8648 } finally {
8649 Binder.restoreCallingIdentity(identity);
8650 }
8651 }
8652
8653 /**
8654 * Get the full emergency number list for test mode.
8655 */
8656 @Override
8657 public List<String> getEmergencyNumberListTestMode() {
8658 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8659 "getEmergencyNumberListTestMode");
8660
8661 final long identity = Binder.clearCallingIdentity();
8662 try {
8663 Set<String> emergencyNumbers = new HashSet<>();
8664 for (Phone phone: PhoneFactory.getPhones()) {
8665 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8666 if (tracker != null) {
8667 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8668 emergencyNumbers.add(num.getNumber());
8669 }
8670 }
8671 }
8672 return new ArrayList<>(emergencyNumbers);
8673 } finally {
8674 Binder.restoreCallingIdentity(identity);
8675 }
8676 }
8677
chen xud6b45bd2018-10-30 22:27:10 -07008678 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008679 public int getEmergencyNumberDbVersion(int subId) {
8680 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8681
8682 final long identity = Binder.clearCallingIdentity();
8683 try {
8684 final Phone phone = getPhone(subId);
8685 if (phone == null) {
8686 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8687 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8688 }
8689 return phone.getEmergencyNumberDbVersion();
8690 } finally {
8691 Binder.restoreCallingIdentity(identity);
8692 }
8693 }
8694
8695 @Override
8696 public void notifyOtaEmergencyNumberDbInstalled() {
8697 enforceModifyPermission();
8698
8699 final long identity = Binder.clearCallingIdentity();
8700 try {
8701 for (Phone phone: PhoneFactory.getPhones()) {
8702 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8703 if (tracker != null) {
8704 tracker.updateOtaEmergencyNumberDatabase();
8705 }
8706 }
8707 } finally {
8708 Binder.restoreCallingIdentity(identity);
8709 }
8710 }
8711
8712 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008713 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008714 enforceActiveEmergencySessionPermission();
8715
8716 final long identity = Binder.clearCallingIdentity();
8717 try {
8718 for (Phone phone: PhoneFactory.getPhones()) {
8719 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8720 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008721 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8722 }
8723 }
8724 } finally {
8725 Binder.restoreCallingIdentity(identity);
8726 }
8727 }
8728
8729 @Override
8730 public void resetOtaEmergencyNumberDbFilePath() {
8731 enforceActiveEmergencySessionPermission();
8732
8733 final long identity = Binder.clearCallingIdentity();
8734 try {
8735 for (Phone phone: PhoneFactory.getPhones()) {
8736 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8737 if (tracker != null) {
8738 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008739 }
8740 }
8741 } finally {
8742 Binder.restoreCallingIdentity(identity);
8743 }
8744 }
8745
8746 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008747 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8748 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8749 Phone phone = getPhone(subId);
8750 if (phone == null) {
8751 return null;
8752 }
8753 final long identity = Binder.clearCallingIdentity();
8754 try {
8755 UiccProfile profile = UiccController.getInstance()
8756 .getUiccProfileForPhone(phone.getPhoneId());
8757 if (profile != null) {
8758 return profile.getCertsFromCarrierPrivilegeAccessRules();
8759 }
8760 } finally {
8761 Binder.restoreCallingIdentity(identity);
8762 }
8763 return null;
8764 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008765
8766 /**
8767 * Enable or disable a modem stack.
8768 */
8769 @Override
8770 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8771 enforceModifyPermission();
8772
8773 final long identity = Binder.clearCallingIdentity();
8774 try {
8775 Phone phone = PhoneFactory.getPhone(slotIndex);
8776 if (phone == null) {
8777 return false;
8778 } else {
8779 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8780 }
8781 } finally {
8782 Binder.restoreCallingIdentity(identity);
8783 }
8784 }
Michelecea4cf22018-12-21 15:00:11 -08008785
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008786 /**
8787 * Whether a modem stack is enabled or not.
8788 */
8789 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008790 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8791 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008792 Phone phone = PhoneFactory.getPhone(slotIndex);
8793 if (phone == null) return false;
8794
8795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008796 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8797 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008798 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8799 }
8800
8801 final long identity = Binder.clearCallingIdentity();
8802 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008803 try {
8804 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8805 } catch (NoSuchElementException ex) {
8806 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8807 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008808 } finally {
8809 Binder.restoreCallingIdentity(identity);
8810 }
8811 }
8812
Michelecea4cf22018-12-21 15:00:11 -08008813 @Override
Michele0ea7d782019-03-19 14:58:42 -07008814 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008815 enforceModifyPermission();
8816
8817 final long identity = Binder.clearCallingIdentity();
8818 try {
8819 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008820 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008821 .commit();
8822 } finally {
8823 Binder.restoreCallingIdentity(identity);
8824 }
8825 }
8826
8827 @Override
Michele0ea7d782019-03-19 14:58:42 -07008828 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008829 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008831 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8832 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008833 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008834 }
Michelecea4cf22018-12-21 15:00:11 -08008835
8836 final long identity = Binder.clearCallingIdentity();
8837 try {
Michele0ea7d782019-03-19 14:58:42 -07008838 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008839 } finally {
8840 Binder.restoreCallingIdentity(identity);
8841 }
8842 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008843
Michele0ea7d782019-03-19 14:58:42 -07008844 @TelephonyManager.IsMultiSimSupportedResult
8845 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008846 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8847 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8848 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008849 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8850 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008851 }
8852 // Check if the hardware supports multisim functionality. If usage of multisim is not
8853 // supported by the modem, indicate that it is restricted.
8854 PhoneCapability staticCapability =
8855 mPhoneConfigurationManager.getStaticPhoneCapability();
8856 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008857 loge("isMultiSimSupportedInternal: no static configuration available");
8858 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008859 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008860 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008861 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8862 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008863 }
8864 // Check if support of multiple SIMs is restricted by carrier
8865 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008866 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008867 }
8868
Michele0ea7d782019-03-19 14:58:42 -07008869 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008870 }
8871
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008872 /**
8873 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008874 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8875 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8876 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008877 * @param numOfSims number of active sims we want to switch to
8878 */
8879 @Override
8880 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008881 if (numOfSims == 1) {
8882 enforceModifyPermission();
8883 } else {
8884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8885 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8886 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008887 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008888
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008889 try {
Michele30b57b22019-03-01 12:01:14 -08008890 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008891 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008892 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8893 return;
8894 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008895 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8896 } finally {
8897 Binder.restoreCallingIdentity(identity);
8898 }
8899 }
8900
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008901 @Override
8902 public boolean isApplicationOnUicc(int subId, int appType) {
8903 enforceReadPrivilegedPermission("isApplicationOnUicc");
8904 Phone phone = getPhone(subId);
8905 if (phone == null) {
8906 return false;
8907 }
8908 final long identity = Binder.clearCallingIdentity();
8909 try {
8910 UiccCard uiccCard = phone.getUiccCard();
8911 if (uiccCard == null) {
8912 return false;
8913 }
8914 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8915 if (uiccProfile == null) {
8916 return false;
8917 }
8918 if (TelephonyManager.APPTYPE_SIM <= appType
8919 && appType <= TelephonyManager.APPTYPE_ISIM) {
8920 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8921 }
8922 return false;
8923 } finally {
8924 Binder.restoreCallingIdentity(identity);
8925 }
8926 }
8927
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008928 /**
chen xub4baa772019-04-03 10:23:41 -07008929 * Get whether making changes to modem configurations will trigger reboot.
8930 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008931 */
8932 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008933 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8934 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008936 mApp, subId, callingPackage, callingFeatureId,
8937 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008938 return false;
8939 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008940 final long identity = Binder.clearCallingIdentity();
8941 try {
8942 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8943 } finally {
8944 Binder.restoreCallingIdentity(identity);
8945 }
8946 }
8947
Nathan Harold29f5f052019-02-15 13:41:57 -08008948 private void updateModemStateMetrics() {
8949 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8950 // TODO: check the state for each modem if the api is ready.
8951 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8952 }
8953
Pengquan Meng3889a572019-01-23 11:16:29 -08008954 @Override
8955 public int[] getSlotsMapping() {
8956 enforceReadPrivilegedPermission("getSlotsMapping");
8957
8958 final long identity = Binder.clearCallingIdentity();
8959 try {
8960 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8961 // All logical slots should have a mapping to a physical slot.
8962 int[] logicalSlotsMapping = new int[phoneCount];
8963 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8964 for (int i = 0; i < slotInfos.length; i++) {
8965 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8966 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8967 }
8968 }
8969 return logicalSlotsMapping;
8970 } finally {
8971 Binder.restoreCallingIdentity(identity);
8972 }
8973 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008974
8975 /**
8976 * Get the IRadio HAL Version
8977 */
8978 @Override
8979 public int getRadioHalVersion() {
8980 Phone phone = getDefaultPhone();
8981 if (phone == null) return -1;
8982 HalVersion hv = phone.getHalVersion();
8983 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8984 return hv.major * 100 + hv.minor;
8985 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008986
8987 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008988 * Get the current calling package name.
8989 * @return the current calling package name
8990 */
8991 @Override
8992 public String getCurrentPackageName() {
8993 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8994 }
8995
8996 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008997 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8998 * corresponding network requests on a subId.
8999 *
9000 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009001 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009002 * 2) APN is un-metered for this subscription, or
9003 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07009004 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009005 *
9006 * @return whether data is allowed for a apn type.
9007 *
9008 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009009 */
9010 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009011 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009012 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9013 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009014
9015 // Now that all security checks passes, perform the operation as ourselves.
9016 final long identity = Binder.clearCallingIdentity();
9017 try {
9018 Phone phone = getPhone(subId);
9019 if (phone == null) return false;
9020
Jack Yu41407ee2019-05-13 16:54:09 -07009021 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009022 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9023 } finally {
9024 Binder.restoreCallingIdentity(identity);
9025 }
9026 }
9027
9028 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009029 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009030 enforceReadPrivilegedPermission("isApnMetered");
9031
9032 // Now that all security checks passes, perform the operation as ourselves.
9033 final long identity = Binder.clearCallingIdentity();
9034 try {
9035 Phone phone = getPhone(subId);
9036 if (phone == null) return true; // By default return true.
9037
Jack Yu41407ee2019-05-13 16:54:09 -07009038 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009039 } finally {
9040 Binder.restoreCallingIdentity(identity);
9041 }
9042 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009043
9044 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009045 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9046 int subscriptionId, IBooleanConsumer resultCallback) {
9047 enforceModifyPermission();
9048 long token = Binder.clearCallingIdentity();
9049 try {
9050 Phone phone = getPhone(subscriptionId);
9051 if (phone == null) {
9052 try {
9053 if (resultCallback != null) {
9054 resultCallback.accept(false);
9055 }
9056 } catch (RemoteException e) {
9057 // ignore
9058 }
9059 return;
9060 }
9061 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9062 Pair.create(specifiers, (x) -> {
9063 try {
9064 if (resultCallback != null) {
9065 resultCallback.accept(x);
9066 }
9067 } catch (RemoteException e) {
9068 // ignore
9069 }
9070 });
9071 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9072 } finally {
9073 Binder.restoreCallingIdentity(token);
9074 }
9075 }
9076
9077 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009078 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9079 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07009080 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08009081 mApp, subId, "getSystemSelectionChannels");
9082 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9083 final long identity = Binder.clearCallingIdentity();
9084 try {
Sarah Chin58691872021-03-13 03:17:40 -08009085 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9086 if (result instanceof IllegalStateException) {
9087 throw (IllegalStateException) result;
9088 }
9089 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chincc055732020-11-18 13:39:35 -08009090 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9091 return specifiers;
9092 } finally {
9093 Binder.restoreCallingIdentity(identity);
9094 }
9095 }
9096
9097 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009098 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009099 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009100 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9101 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9102 if (iccRecords == null) {
9103 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9104 return false;
9105 }
9106 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9107 }
9108
9109 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009110 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9111 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009112 if (callingPackage == null) {
9113 callingPackage = getCurrentPackageName();
9114 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009115 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9116 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009117 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9118 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009119 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9120 }
9121 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9122 Intent intent = new Intent();
9123 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9124 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9125 // Bring up choose default SMS subscription dialog right now
9126 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9127 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9128 mApp.startActivity(intent);
9129 }
chen xud5ca2d52019-05-28 15:20:57 -07009130
9131 @Override
9132 public String getMmsUAProfUrl(int subId) {
9133 //TODO investigate if this API should require proper permission check in R b/133791609
9134 final long identity = Binder.clearCallingIdentity();
9135 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009136 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9137 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9138 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9139 return carrierUAProfUrl;
9140 }
chen xud5ca2d52019-05-28 15:20:57 -07009141 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9142 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9143 } finally {
9144 Binder.restoreCallingIdentity(identity);
9145 }
9146 }
9147
9148 @Override
9149 public String getMmsUserAgent(int subId) {
9150 //TODO investigate if this API should require proper permission check in R b/133791609
9151 final long identity = Binder.clearCallingIdentity();
9152 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009153 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9154 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9155 if (!TextUtils.isEmpty(carrierUserAgent)) {
9156 return carrierUserAgent;
9157 }
chen xud5ca2d52019-05-28 15:20:57 -07009158 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9159 .getString(com.android.internal.R.string.config_mms_user_agent);
9160 } finally {
9161 Binder.restoreCallingIdentity(identity);
9162 }
9163 }
Jack Yub07d4972019-05-28 16:12:25 -07009164
9165 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009166 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9167 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9168
9169 final long identity = Binder.clearCallingIdentity();
9170 try {
9171 Phone phone = getPhone(subscriptionId);
9172 if (phone == null) return false;
9173
9174 switch (policy) {
9175 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9176 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9177 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9178 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9179 default:
9180 throw new IllegalArgumentException(policy + " is not a valid policy");
9181 }
9182 } finally {
9183 Binder.restoreCallingIdentity(identity);
9184 }
9185 }
9186
9187 @Override
9188 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9189 boolean enabled) {
9190 enforceModifyPermission();
9191
9192 final long identity = Binder.clearCallingIdentity();
9193 try {
9194 Phone phone = getPhone(subscriptionId);
9195 if (phone == null) return;
9196
9197 switch (policy) {
9198 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9199 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9200 break;
9201 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9202 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9203 break;
9204 default:
9205 throw new IllegalArgumentException(policy + " is not a valid policy");
9206 }
9207 } finally {
9208 Binder.restoreCallingIdentity(identity);
9209 }
9210 }
9211
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009212 /**
Hall Liub48cf452020-09-25 11:13:49 -07009213 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009214 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9215 * otherwise.
9216 */
9217 @Override
9218 public void setCepEnabled(boolean isCepEnabled) {
9219 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9220
9221 final long identity = Binder.clearCallingIdentity();
9222 try {
9223 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9224 for (Phone phone : PhoneFactory.getPhones()) {
9225 Phone defaultPhone = phone.getImsPhone();
9226 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9227 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9228 ImsPhoneCallTracker imsPhoneCallTracker =
9229 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9230 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9231 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9232 + imsPhone.getMsisdn());
9233 }
9234 }
9235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 }
allenwtsu46dcc572020-01-08 18:24:03 +08009239
9240 /**
9241 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9242 *
9243 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9244 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9245 * before being read.
9246 */
9247 @Override
9248 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9249 isCompressed) {
9250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9251 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009252 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9253 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9254 }
9255 if (!isImsAvailableOnDevice()) {
9256 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9257 "IMS not available on device.");
9258 }
9259
9260 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009261 try {
Hui Wang068ab862020-10-31 05:12:53 +00009262 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9263 } finally {
9264 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009265 }
9266 }
zoey chenf95ca592019-12-30 16:11:23 +08009267
9268 @Override
9269 public boolean isIccLockEnabled(int subId) {
9270 enforceReadPrivilegedPermission("isIccLockEnabled");
9271
9272 // Now that all security checks passes, perform the operation as ourselves.
9273 final long identity = Binder.clearCallingIdentity();
9274 try {
9275 Phone phone = getPhone(subId);
9276 if (phone != null && phone.getIccCard() != null) {
9277 return phone.getIccCard().getIccLockEnabled();
9278 } else {
9279 return false;
9280 }
9281 } finally {
9282 Binder.restoreCallingIdentity(identity);
9283 }
9284 }
9285
9286 /**
zoey chene02881a2019-12-30 16:11:23 +08009287 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009288 *
zoey chene02881a2019-12-30 16:11:23 +08009289 * @return an integer representing the status of IccLock enabled or disabled in the following
9290 * three cases:
9291 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9292 * successfully.
9293 * - Positive number and zero for remaining password attempts.
9294 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009295 *
9296 */
9297 @Override
9298 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9299 enforceModifyPermission();
9300
9301 Phone phone = getPhone(subId);
9302 if (phone == null) {
9303 return 0;
9304 }
9305 // Now that all security checks passes, perform the operation as ourselves.
9306 final long identity = Binder.clearCallingIdentity();
9307 try {
9308 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9309 new Pair<Boolean, String>(enabled, password), phone, null);
9310 return attemptsRemaining;
9311
9312 } catch (Exception e) {
9313 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9314 } finally {
9315 Binder.restoreCallingIdentity(identity);
9316 }
9317 return 0;
9318 }
9319
9320 /**
9321 * Change the ICC password used in ICC pin lock.
9322 *
zoey chene02881a2019-12-30 16:11:23 +08009323 * @return an integer representing the status of IccLock changed in the following three cases:
9324 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9325 * - Positive number and zero for remaining password attempts.
9326 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009327 *
9328 */
9329 @Override
9330 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9331 enforceModifyPermission();
9332
9333 Phone phone = getPhone(subId);
9334 if (phone == null) {
9335 return 0;
9336 }
9337 // Now that all security checks passes, perform the operation as ourselves.
9338 final long identity = Binder.clearCallingIdentity();
9339 try {
9340 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9341 new Pair<String, String>(oldPassword, newPassword), phone, null);
9342 return attemptsRemaining;
9343
9344 } catch (Exception e) {
9345 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9346 } finally {
9347 Binder.restoreCallingIdentity(identity);
9348 }
9349 return 0;
9350 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009351
Peter Wangdafb9ac2020-01-15 14:13:38 -08009352 /**
9353 * Request for receiving user activity notification
9354 */
9355 @Override
9356 public void requestUserActivityNotification() {
9357 if (!mNotifyUserActivity.get()
9358 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9359 mNotifyUserActivity.set(true);
9360 }
9361 }
9362
9363 /**
9364 * Called when userActivity is signalled in the power manager.
9365 * This is safe to call from any thread, with any window manager locks held or not.
9366 */
9367 @Override
9368 public void userActivity() {
9369 // ***************************************
9370 // * Inherited from PhoneWindowManager *
9371 // ***************************************
9372 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9373 // WITH ITS LOCKS HELD.
9374 //
9375 // This code must be VERY careful about the locks
9376 // it acquires.
9377 // In fact, the current code acquires way too many,
9378 // and probably has lurking deadlocks.
9379
9380 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9381 throw new SecurityException("Only the OS may call notifyUserActivity()");
9382 }
9383
9384 if (mNotifyUserActivity.getAndSet(false)) {
9385 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9386 USER_ACTIVITY_NOTIFICATION_DELAY);
9387 }
9388 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009389
Malcolm Chen884180b2020-04-13 11:59:40 -07009390 @Override
9391 public boolean canConnectTo5GInDsdsMode() {
9392 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9393 }
Jack Yud10cdd42020-09-28 20:28:01 -07009394
9395 @Override
9396 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9397 String callingFeatureId) {
9398 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9399 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9400 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9401 }
9402
9403 Phone phone = getPhone(subId);
9404 if (phone == null) {
9405 throw new RuntimeException("phone is not available");
9406 }
9407 // Now that all security checks passes, perform the operation as ourselves.
9408 final long identity = Binder.clearCallingIdentity();
9409 try {
9410 return phone.getEquivalentHomePlmns();
9411 } finally {
9412 Binder.restoreCallingIdentity(identity);
9413 }
9414 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009415
Hui Wang0866fcc2020-10-12 12:14:23 -07009416 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009417 public boolean isRadioInterfaceCapabilitySupported(
9418 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009419 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009420 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009421 if (radioInterfaceCapabilities == null) {
9422 throw new RuntimeException("radio interface capabilities are not available");
9423 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009424 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009425 }
9426 }
9427
9428 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009429 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9430 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009431 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9432 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9433 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9434 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9435 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009436 if (DBG) {
9437 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9438 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9439 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9440 }
9441
9442 if (!SubscriptionManager.isValidSubscriptionId(subId)
9443 || appType < TelephonyManager.APPTYPE_UNKNOWN
9444 || appType > TelephonyManager.APPTYPE_ISIM
9445 || nafUrl == null || securityProtocol == null || callback == null) {
9446 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9447 if (callback != null) {
9448 try {
9449 callback.onAuthenticationFailure(
9450 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9451 } catch (RemoteException exception) {
9452 log("Fail to notify onAuthenticationFailure due to " + exception);
9453 }
9454 return;
9455 }
9456 }
9457
9458 final long token = Binder.clearCallingIdentity();
9459 try {
9460 getGbaManager(subId).bootstrapAuthenticationRequest(
9461 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9462 forceBootStrapping, callback));
9463 } finally {
9464 Binder.restoreCallingIdentity(token);
9465 }
9466 }
9467
Jack Nudelman24d51a52020-11-24 12:08:04 -08009468 /**
9469 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9470 * requested radio power state will actually be set. See {@link
9471 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9472 *
9473 * @param subId the subscription ID of the phone requesting to set the radio power state.
9474 * @param enable {@code true} if trying to turn radio on.
9475 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9476 * false}.
9477 */
9478 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9479 Phone phone = getPhone(subId);
9480 if (phone != null) {
9481 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9482 return true;
9483 }
9484 return false;
9485 }
9486
9487 private int handleDataThrottlingRequest(int subId,
9488 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009489 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9490 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9491 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9492 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9493 throw new IllegalArgumentException("modem does not support data throttling");
9494 }
9495
Jack Nudelman24d51a52020-11-24 12:08:04 -08009496 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9497 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9498 if (!setRadioPowerForThermal(subId, true)) {
9499 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9500 }
9501
9502 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9503
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009504 if (isDataThrottlingSupported) {
9505 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009506 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009507 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9508 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9509 } else if (thermalMitigationResult
9510 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman20352592021-05-20 13:57:30 -07009511 log("Modem likely does not support data throttling on secondary carrier. Data " +
9512 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9513 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009514 }
9515 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009516 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009517
9518 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009519 }
9520
Jack Nudelman644b91a2021-03-12 14:09:48 -08009521 private static List<String> getThermalMitigationAllowlist(Context context) {
9522 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9523 for (String pckg : context.getResources()
9524 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9525 sThermalMitigationAllowlistedPackages.add(pckg);
9526 }
9527 }
9528
9529 return sThermalMitigationAllowlistedPackages;
9530 }
9531
Jack Nudelmane634f962021-05-13 10:00:15 -07009532 private boolean isAnyPhoneInEmergencyState() {
9533 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9534 if (tm.isInEmergencyCall()) {
9535 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9536 return true;
9537 }
9538 for (Phone phone : PhoneFactory.getPhones()) {
9539 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9540 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9541 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9542 + phone.isInEcm());
9543 return true;
9544 }
9545 }
9546
9547 return false;
9548 }
9549
Jack Nudelman644b91a2021-03-12 14:09:48 -08009550 /**
9551 * Used by shell commands to add an authorized package name for thermal mitigation.
9552 * @param packageName name of package to be allowlisted
9553 * @param context
9554 */
9555 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9556 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9557 sThermalMitigationAllowlistedPackages.add(packageName);
9558 }
9559
9560 /**
9561 * Used by shell commands to remove an authorized package name for thermal mitigation.
9562 * @param packageName name of package to remove from allowlist
9563 * @param context
9564 */
9565 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9566 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9567 sThermalMitigationAllowlistedPackages.remove(packageName);
9568 }
9569
Jack Nudelman24d51a52020-11-24 12:08:04 -08009570 /**
9571 * Thermal mitigation request to control functionalities at modem.
9572 *
9573 * @param subId the id of the subscription.
9574 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009575 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009576 *
9577 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9578 */
9579 @Override
9580 @ThermalMitigationResult
9581 public int sendThermalMitigationRequest(
9582 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009583 ThermalMitigationRequest thermalMitigationRequest,
9584 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009585 enforceModifyPermission();
9586
Jack Nudelman644b91a2021-03-12 14:09:48 -08009587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9588 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9589 .contains(callingPackage)) {
9590 throw new SecurityException("Calling package must be configured in the device config. "
9591 + "calling package: " + callingPackage);
9592 }
9593
Jack Nudelman24d51a52020-11-24 12:08:04 -08009594 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9595 final long identity = Binder.clearCallingIdentity();
9596
9597 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9598 try {
9599 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9600 switch (thermalMitigationAction) {
9601 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9602 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009603 handleDataThrottlingRequest(subId,
9604 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009605 break;
9606 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9607 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9608 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9609 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9610 }
9611
9612 // Ensure that radio is on. If not able to power on due to phone being
9613 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9614 if (!setRadioPowerForThermal(subId, true)) {
9615 thermalMitigationResult =
9616 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9617 break;
9618 }
9619
9620 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9621 false);
9622 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9623 break;
9624 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9625 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9626 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9627 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9628 }
9629
9630 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9631 if (registry != null) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009632 Phone phone = getPhone(subId);
9633 if (phone == null) {
9634 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009635 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009636 break;
9637 }
9638
Jack Nudelmane634f962021-05-13 10:00:15 -07009639 TelephonyConnectionService service =
9640 registry.getTelephonyConnectionService();
9641 if (service == null) {
9642 Log.e(LOG_TAG, "TelephonyConnectionService is null");
9643 thermalMitigationResult =
9644 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9645 break;
9646
9647 } else if (service.isEmergencyCallPending()) {
9648 Log.e(LOG_TAG, "An emergency call is pending");
9649 thermalMitigationResult =
9650 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9651 break;
9652 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009653 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009654 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009655 break;
9656 }
9657 } else {
9658 thermalMitigationResult =
9659 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9660 break;
9661 }
9662
9663 // Turn radio off. If not able to power off due to phone being unavailable,
9664 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9665 if (!setRadioPowerForThermal(subId, false)) {
9666 thermalMitigationResult =
9667 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9668 break;
9669 }
9670 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009671 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009672 break;
9673 default:
9674 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9675 + "not exist. Requested action: " + thermalMitigationAction);
9676 }
9677 } catch (IllegalArgumentException e) {
9678 throw e;
9679 } catch (Exception e) {
9680 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9681 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9682 } finally {
9683 Binder.restoreCallingIdentity(identity);
9684 }
9685
9686 if (DBG) {
9687 log("thermalMitigationRequest returning with thermalMitigationResult: "
9688 + thermalMitigationResult);
9689 }
9690
9691 return thermalMitigationResult;
9692 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009693
9694 /**
9695 * Set the GbaService Package Name that Telephony will bind to.
9696 *
9697 * @param subId The sim that the GbaService is associated with.
9698 * @param packageName The name of the package to be replaced with.
9699 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9700 */
9701 @Override
9702 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9703 enforceModifyPermission();
9704
9705 final long identity = Binder.clearCallingIdentity();
9706 try {
9707 return getGbaManager(subId).overrideServicePackage(packageName);
9708 } finally {
9709 Binder.restoreCallingIdentity(identity);
9710 }
9711 }
9712
9713 /**
9714 * Return the package name of the currently bound GbaService.
9715 *
9716 * @param subId The sim that the GbaService is associated with.
9717 * @return the package name of the GbaService configuration, null if GBA is not supported.
9718 */
9719 @Override
9720 public String getBoundGbaService(int subId) {
9721 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9722
9723 final long identity = Binder.clearCallingIdentity();
9724 try {
9725 return getGbaManager(subId).getServicePackage();
9726 } finally {
9727 Binder.restoreCallingIdentity(identity);
9728 }
9729 }
9730
9731 /**
9732 * Set the release time for telephony to unbind GbaService.
9733 *
9734 * @param subId The sim that the GbaService is associated with.
9735 * @param interval The release time to unbind GbaService by millisecond.
9736 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9737 */
9738 @Override
9739 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9740 enforceModifyPermission();
9741
9742 final long identity = Binder.clearCallingIdentity();
9743 try {
9744 return getGbaManager(subId).overrideReleaseTime(interval);
9745 } finally {
9746 Binder.restoreCallingIdentity(identity);
9747 }
9748 }
9749
9750 /**
9751 * Return the release time for telephony to unbind GbaService.
9752 *
9753 * @param subId The sim that the GbaService is associated with.
9754 * @return The release time to unbind GbaService by millisecond.
9755 */
9756 @Override
9757 public int getGbaReleaseTime(int subId) {
9758 enforceReadPrivilegedPermission("getGbaReleaseTime");
9759
9760 final long identity = Binder.clearCallingIdentity();
9761 try {
9762 return getGbaManager(subId).getReleaseTime();
9763 } finally {
9764 Binder.restoreCallingIdentity(identity);
9765 }
9766 }
9767
9768 private GbaManager getGbaManager(int subId) {
9769 GbaManager instance = GbaManager.getInstance(subId);
9770 if (instance == null) {
9771 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9772 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9773 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9774 }
9775 return instance;
9776 }
Hui Wang068ab862020-10-31 05:12:53 +00009777
9778 /**
9779 * indicate whether the device and the carrier can support
9780 * RCS VoLTE single registration.
9781 */
9782 @Override
9783 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009784 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9785 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9786 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9787 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009788
9789 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9790 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9791 }
9792
9793 final long identity = Binder.clearCallingIdentity();
9794 try {
9795 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9796 if (rpm != null) {
Hui Wang048c10a2021-06-21 18:05:57 +00009797 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
9798 if (isCapable != null) {
9799 return isCapable;
9800 }
Hui Wang068ab862020-10-31 05:12:53 +00009801 }
Hui Wang048c10a2021-06-21 18:05:57 +00009802 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
9803 "service is temporarily unavailable.");
Hui Wang068ab862020-10-31 05:12:53 +00009804 } finally {
9805 Binder.restoreCallingIdentity(identity);
9806 }
9807 }
9808
9809 /**
9810 * Register RCS provisioning callback.
9811 */
9812 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009813 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009814 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009815 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009816 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009817 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9818 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009819
9820 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9821 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9822 }
9823 if (!isImsAvailableOnDevice()) {
9824 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9825 "IMS not available on device.");
9826 }
9827
9828 final long identity = Binder.clearCallingIdentity();
9829 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009830 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009831 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009832 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9833 "Service not available for the subscription.");
9834 }
Hui Wang068ab862020-10-31 05:12:53 +00009835 } finally {
9836 Binder.restoreCallingIdentity(identity);
9837 }
9838 }
9839
9840 /**
9841 * Unregister RCS provisioning callback.
9842 */
9843 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009844 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009845 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009846 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009847 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009848 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9849 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009850
9851 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9852 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9853 }
9854 if (!isImsAvailableOnDevice()) {
9855 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9856 "IMS not available on device.");
9857 }
9858
9859 final long identity = Binder.clearCallingIdentity();
9860 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009861 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009862 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009863 } finally {
9864 Binder.restoreCallingIdentity(identity);
9865 }
9866 }
9867
9868 /**
9869 * trigger RCS reconfiguration.
9870 */
9871 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009872 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9873 "triggerRcsReconfiguration",
9874 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009875
9876 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9877 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9878 }
9879 if (!isImsAvailableOnDevice()) {
9880 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9881 "IMS not available on device.");
9882 }
9883
9884 final long identity = Binder.clearCallingIdentity();
9885 try {
9886 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9887 } finally {
9888 Binder.restoreCallingIdentity(identity);
9889 }
9890 }
9891
9892 /**
9893 * Provide the client configuration parameters of the RCS application.
9894 */
9895 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009896 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9897 "setRcsClientConfiguration",
9898 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009899
9900 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9901 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9902 }
9903 if (!isImsAvailableOnDevice()) {
9904 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9905 "IMS not available on device.");
9906 }
9907
9908 final long identity = Binder.clearCallingIdentity();
9909
9910 try {
9911 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9912 if (configBinder == null) {
9913 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9914 } else {
9915 configBinder.setRcsClientConfiguration(rcc);
9916 }
9917 } catch (RemoteException e) {
9918 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9919 } finally {
9920 Binder.restoreCallingIdentity(identity);
9921 }
9922 }
9923
9924 /**
Hui Wang19a21872021-02-19 20:45:36 -08009925 * Enables or disables the test mode for RCS VoLTE single registration.
9926 */
9927 @Override
9928 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9929 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9930 "setRcsSingleRegistrationTestModeEnabled");
9931
9932 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9933 }
9934
9935 /**
9936 * Gets the test mode for RCS VoLTE single registration.
9937 */
9938 @Override
9939 public boolean getRcsSingleRegistrationTestModeEnabled() {
9940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9941 "getRcsSingleRegistrationTestModeEnabled");
9942
9943 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9944 }
9945
9946 /**
Hui Wang068ab862020-10-31 05:12:53 +00009947 * Overrides the config of RCS VoLTE single registration enabled for the device.
9948 */
9949 @Override
9950 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9951 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9952 "setDeviceSingleRegistrationEnabledOverride");
9953 enforceModifyPermission();
9954
9955 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9956 : Boolean.parseBoolean(enabledStr);
9957 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009958 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009959 }
9960
9961 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009962 * Sends a device to device communication message. Only usable via shell.
9963 * @param message message to send.
9964 * @param value message value.
9965 */
9966 @Override
9967 public void sendDeviceToDeviceMessage(int message, int value) {
9968 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9969 "setCarrierSingleRegistrationEnabledOverride");
9970 enforceModifyPermission();
9971
9972 final long identity = Binder.clearCallingIdentity();
9973 try {
9974 TelephonyConnectionService service =
9975 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9976 if (service == null) {
9977 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9978 return;
9979 }
9980 service.sendTestDeviceToDeviceMessage(message, value);
9981 } finally {
9982 Binder.restoreCallingIdentity(identity);
9983 }
9984 }
9985
9986
9987 /**
Hui Wang068ab862020-10-31 05:12:53 +00009988 * Gets the config of RCS VoLTE single registration enabled for the device.
9989 */
9990 @Override
9991 public boolean getDeviceSingleRegistrationEnabled() {
9992 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9993 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9994 }
9995
9996 /**
9997 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9998 */
9999 @Override
10000 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10001 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10002 "setCarrierSingleRegistrationEnabledOverride");
10003 enforceModifyPermission();
10004
10005 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10006 : Boolean.parseBoolean(enabledStr);
10007 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10008 subId, enabled);
10009 }
10010
10011 /**
10012 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10013 */
10014 @Override
10015 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10016 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10017 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10018 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010019
10020 /**
Hui Wangeadb2562021-02-26 09:33:38 -080010021 * Overrides the ims feature validation result
10022 */
10023 @Override
10024 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10025 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10026 "setImsFeatureValidationOverride");
10027
10028 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10029 : Boolean.parseBoolean(enabledStr);
10030 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10031 subId, enabled);
10032 }
10033
10034 /**
10035 * Gets the ims feature validation override value
10036 */
10037 @Override
10038 public boolean getImsFeatureValidationOverride(int subId) {
10039 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10040 "getImsFeatureValidationOverride");
10041 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10042 }
10043
10044 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010045 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10046 * their mobile plan.
10047 */
10048 @Override
10049 public String getMobileProvisioningUrl() {
10050 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10051 final long identity = Binder.clearCallingIdentity();
10052 try {
10053 return getDefaultPhone().getMobileProvisioningUrl();
10054 } finally {
10055 Binder.restoreCallingIdentity(identity);
10056 }
10057 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010058
James.cf Linbcdf8b32021-01-14 16:44:13 +080010059 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010060 * Get the EAB contact from the EAB database.
10061 */
10062 @Override
10063 public String getContactFromEab(String contact) {
10064 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10065 enforceModifyPermission();
10066 final long identity = Binder.clearCallingIdentity();
10067 try {
10068 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10069 } finally {
10070 Binder.restoreCallingIdentity(identity);
10071 }
10072 }
10073
10074 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010075 * Remove the EAB contacts from the EAB database.
10076 */
10077 @Override
10078 public int removeContactFromEab(int subId, String contacts) {
10079 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10080 enforceModifyPermission();
10081 final long identity = Binder.clearCallingIdentity();
10082 try {
10083 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10084 } finally {
10085 Binder.restoreCallingIdentity(identity);
10086 }
10087 }
10088
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010089 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010090 public boolean getDeviceUceEnabled() {
10091 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10092 final long identity = Binder.clearCallingIdentity();
10093 try {
10094 return mApp.getDeviceUceEnabled();
10095 } finally {
10096 Binder.restoreCallingIdentity(identity);
10097 }
10098 }
10099
10100 @Override
10101 public void setDeviceUceEnabled(boolean isEnabled) {
10102 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10103 final long identity = Binder.clearCallingIdentity();
10104 try {
10105 mApp.setDeviceUceEnabled(isEnabled);
10106 } finally {
10107 Binder.restoreCallingIdentity(identity);
10108 }
10109 }
10110
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010111 /**
10112 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10113 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10114 */
10115 // Used for SHELL command only right now.
10116 @Override
10117 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10118 List<String> featureTags) {
10119 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10120 "addUceRegistrationOverrideShell");
10121 final long identity = Binder.clearCallingIdentity();
10122 try {
10123 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10124 new ArraySet<>(featureTags));
10125 } catch (ImsException e) {
10126 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10127 } finally {
10128 Binder.restoreCallingIdentity(identity);
10129 }
10130 }
10131
10132 /**
10133 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10134 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10135 */
10136 // Used for SHELL command only right now.
10137 @Override
10138 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10139 List<String> featureTags) {
10140 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10141 "removeUceRegistrationOverrideShell");
10142 final long identity = Binder.clearCallingIdentity();
10143 try {
10144 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10145 new ArraySet<>(featureTags));
10146 } catch (ImsException e) {
10147 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10148 } finally {
10149 Binder.restoreCallingIdentity(identity);
10150 }
10151 }
10152
10153 /**
10154 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10155 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10156 */
10157 // Used for SHELL command only right now.
10158 @Override
10159 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10161 "clearUceRegistrationOverrideShell");
10162 final long identity = Binder.clearCallingIdentity();
10163 try {
10164 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10165 } catch (ImsException e) {
10166 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10167 } finally {
10168 Binder.restoreCallingIdentity(identity);
10169 }
10170 }
10171
10172 /**
10173 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10174 */
10175 // Used for SHELL command only right now.
10176 @Override
10177 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10178 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10179 "getLatestRcsContactUceCapabilityShell");
10180 final long identity = Binder.clearCallingIdentity();
10181 try {
10182 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10183 } catch (ImsException e) {
10184 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10185 } finally {
10186 Binder.restoreCallingIdentity(identity);
10187 }
10188 }
10189
10190 /**
10191 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10192 * device does not have an active PUBLISH.
10193 */
10194 // Used for SHELL command only right now.
10195 @Override
10196 public String getLastUcePidfXmlShell(int subId) {
10197 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10198 final long identity = Binder.clearCallingIdentity();
10199 try {
10200 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10201 } catch (ImsException e) {
10202 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10203 } finally {
10204 Binder.restoreCallingIdentity(identity);
10205 }
10206 }
10207
James.cf Line8713a42021-04-29 16:04:26 +080010208 /**
10209 * Remove UCE requests cannot be sent to the network status.
10210 */
10211 // Used for SHELL command only right now.
10212 @Override
10213 public boolean removeUceRequestDisallowedStatus(int subId) {
10214 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10215 final long identity = Binder.clearCallingIdentity();
10216 try {
10217 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10218 } catch (ImsException e) {
10219 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10220 } finally {
10221 Binder.restoreCallingIdentity(identity);
10222 }
10223 }
10224
James.cf Lin18bb9002021-05-25 01:37:38 +080010225 /**
10226 * Remove UCE requests cannot be sent to the network status.
10227 */
10228 // Used for SHELL command only.
10229 @Override
10230 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10232 final long identity = Binder.clearCallingIdentity();
10233 try {
10234 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10235 } catch (ImsException e) {
10236 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10237 } finally {
10238 Binder.restoreCallingIdentity(identity);
10239 }
10240 }
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010241
James.cf Lin4b784aa2021-01-31 03:25:15 +080010242 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010243 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10244 String callingPackage) {
10245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10246 mApp, subId, "setSignalStrengthUpdateRequest");
10247
10248 final int callingUid = Binder.getCallingUid();
10249 // Verify that tha callingPackage belongs to the calling UID
10250 mApp.getSystemService(AppOpsManager.class)
10251 .checkPackage(callingUid, callingPackage);
10252
10253 validateSignalStrengthUpdateRequest(request, callingUid);
10254
10255 final long identity = Binder.clearCallingIdentity();
10256 try {
10257 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10258 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10259
10260 if (result instanceof IllegalStateException) {
10261 throw (IllegalStateException) result;
10262 }
10263 } finally {
10264 Binder.restoreCallingIdentity(identity);
10265 }
10266 }
10267
10268 @Override
10269 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10270 String callingPackage) {
10271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10272 mApp, subId, "clearSignalStrengthUpdateRequest");
10273
10274 final int callingUid = Binder.getCallingUid();
10275 // Verify that tha callingPackage belongs to the calling UID
10276 mApp.getSystemService(AppOpsManager.class)
10277 .checkPackage(callingUid, callingPackage);
10278
10279 final long identity = Binder.clearCallingIdentity();
10280 try {
10281 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10282 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10283
10284 if (result instanceof IllegalStateException) {
10285 throw (IllegalStateException) result;
10286 }
10287 } finally {
10288 Binder.restoreCallingIdentity(identity);
10289 }
10290 }
10291
10292 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10293 int callingUid) {
10294 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10295 // phone/system process do not have further restriction on request
10296 return;
10297 }
10298
10299 // Applications has restrictions on how to use the request:
10300 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10301 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10302 // This is not system caller which has been checked above
10303 throw new IllegalArgumentException(
10304 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10305 }
10306
10307 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10308 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10309 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10310 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10311 || info.isEnabled()) {
10312 throw new IllegalArgumentException(
10313 "Only system can set hide fields in SignalThresholdInfo");
10314 }
10315
10316 // Thresholds length for each RAN need in range. This has been validated in
10317 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10318 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10319 final int[] thresholds = info.getThresholds();
10320 Objects.requireNonNull(thresholds);
10321 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10322 || thresholds.length
10323 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10324 throw new IllegalArgumentException(
10325 "thresholds length is out of range: " + thresholds.length);
10326 }
10327 }
10328 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010329
10330 /**
10331 * Prepare TelephonyManager for an unattended reboot. The reboot is
10332 * required to be done shortly after the API is invoked.
10333 */
10334 @Override
10335 @TelephonyManager.PrepareUnattendedRebootResult
10336 public int prepareForUnattendedReboot() {
10337 enforceRebootPermission();
10338
10339 final long identity = Binder.clearCallingIdentity();
10340 try {
10341 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10342 } finally {
10343 Binder.restoreCallingIdentity(identity);
10344 }
10345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010346}