blob: 44858d27d3165b7ea3234ac7bb26ae646b339c9b [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;
Hongbo Zengd31d3a32021-02-08 21:50:28 +0800109import android.telephony.data.SlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700111import android.telephony.gba.GbaAuthRequest;
112import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700113import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000115import android.telephony.ims.RcsClientConfiguration;
Brad Ebingerd4c5bde2021-02-12 06:18:28 +0000116import android.telephony.ims.RcsContactUceCapability;
Brad Ebinger774ba362019-10-22 17:36:18 -0700117import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700118import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800119import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700120import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700122import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000123import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700124import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800126import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800128import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700131import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800133import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800134
Andrew Lee312e8172014-10-23 17:01:36 -0700135import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800136import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800137import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWang51ee2b12021-05-27 22:44:54 +0800138import com.android.internal.annotations.VisibleForTesting;
sqian80370722020-01-29 15:02:51 -0800139import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700141import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700142import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800143import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700144import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800146import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700148import com.android.internal.telephony.GbaManager;
Shuo Qian479dd9e2021-02-22 18:32:21 -0800149import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800150import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800151import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700152import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800154import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800156import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700157import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700158import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700159import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700161import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800162import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700163import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700164import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700165import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700166import com.android.internal.telephony.RIL;
SongFerngWang522637d2021-03-02 22:09:29 +0800167import com.android.internal.telephony.RILConstants;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800168import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700170import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800172import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800173import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800174import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700175import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800176import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700177import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800178import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700179import com.android.internal.telephony.imsphone.ImsPhone;
180import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800181import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900182import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800184import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccUtils;
Grace Jia59437e82021-09-21 15:47:32 -0700186import com.android.internal.telephony.uicc.PinStorage;
Nathan Haroldb3014052017-01-25 15:57:32 -0800187import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700188import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700190import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800191import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000192import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800193import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700194import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700195import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800196import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700197import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700198import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800199import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700200import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700201import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800202import com.android.services.telephony.TelecomAccountRegistry;
203import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800204import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800205
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700206import java.io.FileDescriptor;
207import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800209import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800210import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800211import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800212import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100213import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800214import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700215import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800216import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800217import java.util.Set;
SongFerngWangc63cf522021-03-31 22:08:45 +0800218import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800219import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800220import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221
222/**
223 * Implementation of the ITelephony interface.
224 */
Santos Cordon117fee72014-05-16 17:56:12 -0700225public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226 private static final String LOG_TAG = "PhoneInterfaceManager";
227 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
228 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800229 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230
231 // Message codes used with mMainThreadHandler
232 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700233 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
234 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700235 private static final int CMD_OPEN_CHANNEL = 9;
236 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
237 private static final int CMD_CLOSE_CHANNEL = 11;
238 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800239 private static final int CMD_NV_READ_ITEM = 13;
240 private static final int EVENT_NV_READ_ITEM_DONE = 14;
241 private static final int CMD_NV_WRITE_ITEM = 15;
242 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
243 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
244 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700245 private static final int CMD_RESET_MODEM_CONFIG = 19;
246 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800247 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
248 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800249 private static final int CMD_SEND_ENVELOPE = 25;
250 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000251 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
252 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700253 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
254 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
255 private static final int CMD_EXCHANGE_SIM_IO = 31;
256 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800257 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
258 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700259 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
260 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700261 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
262 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700263 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
264 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
265 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
266 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700267 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
268 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
269 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
270 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700271 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800272 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
273 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000274 private static final int CMD_SWITCH_SLOTS = 50;
275 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700276 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
277 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
278 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
279 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
280 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
281 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
282 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
283 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700284 private static final int CMD_GET_ALL_CELL_INFO = 60;
285 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
286 private static final int CMD_GET_CELL_LOCATION = 62;
287 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700288 private static final int CMD_MODEM_REBOOT = 64;
289 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700290 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
291 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800292 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
293 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700294 private static final int CMD_GET_MODEM_STATUS = 70;
295 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700296 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
297 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700298 private static final int CMD_ERASE_MODEM_CONFIG = 74;
299 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800300 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
301 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
302 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
303 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800304 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
305 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800306 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800307 private static final int CMD_GET_CALL_FORWARDING = 83;
308 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
309 private static final int CMD_SET_CALL_FORWARDING = 85;
310 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
311 private static final int CMD_GET_CALL_WAITING = 87;
312 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
313 private static final int CMD_SET_CALL_WAITING = 89;
314 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700315 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
316 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
317 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
318 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700319 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
320 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800321 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
322 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800323 private static final int CMD_SET_DATA_THROTTLING = 99;
324 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800325 private static final int CMD_SET_SIM_POWER = 101;
326 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800327 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
328 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
329 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
330 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800331 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
332 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000333 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zengd31d3a32021-02-08 21:50:28 +0800334 private static final int CMD_GET_SLICING_CONFIG = 110;
335 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800337 // Parameters of select command.
338 private static final int SELECT_COMMAND = 0xA4;
339 private static final int SELECT_P1 = 0x04;
340 private static final int SELECT_P2 = 0;
341 private static final int SELECT_P3 = 0x10;
342
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 /** The singleton instance. */
344 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800345 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346
Wink Saville3ab207e2014-11-20 13:07:20 -0800347 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800348 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800349 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700350 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800351 private AppOpsManager mAppOps;
352 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800353 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800354 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700355 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800356 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
Peter Wangdafb9ac2020-01-15 14:13:38 -0800358 /** User Activity */
359 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800360 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
361
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700362 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
363
Derek Tan97ebb422014-09-05 16:55:38 -0700364 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
365 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800366 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800367 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700368
Michelecea4cf22018-12-21 15:00:11 -0800369 // String to store multi SIM allowed
370 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
371
Derek Tan740e1672017-06-27 14:56:27 -0700372 // The AID of ISD-R.
373 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
374
yinxub1bed742017-04-17 11:45:04 -0700375 private NetworkScanRequestTracker mNetworkScanRequestTracker;
376
David Kelly5e06a7f2018-03-12 14:10:59 +0000377 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
378 private static final int MANUFACTURER_CODE_LENGTH = 8;
379
Jack Nudelman24d51a52020-11-24 12:08:04 -0800380 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800381 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800382
Derek Tan89e89d42014-07-08 17:00:10 -0700383 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700384 * Experiment flag to enable erase modem config on reset network, default value is false
385 */
386 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
387 "reset_network_erase_modem_config_enabled";
388
Rambo Wang0f050d82021-02-12 11:43:36 -0800389 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
390
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700391 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700392 * A request object to use for transmitting data to an ICC.
393 */
394 private static final class IccAPDUArgument {
395 public int channel, cla, command, p1, p2, p3;
396 public String data;
397
398 public IccAPDUArgument(int channel, int cla, int command,
399 int p1, int p2, int p3, String data) {
400 this.channel = channel;
401 this.cla = cla;
402 this.command = command;
403 this.p1 = p1;
404 this.p2 = p2;
405 this.p3 = p3;
406 this.data = data;
407 }
408 }
409
410 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700411 * A request object to use for transmitting data to an ICC.
412 */
413 private static final class ManualNetworkSelectionArgument {
414 public OperatorInfo operatorInfo;
415 public boolean persistSelection;
416
417 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
418 this.operatorInfo = operatorInfo;
419 this.persistSelection = persistSelection;
420 }
421 }
422
423 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
425 * request after sending. The main thread will notify the request when it is complete.
426 */
427 private static final class MainThreadRequest {
428 /** The argument to use for the request */
429 public Object argument;
430 /** The result of the request that is run on the main thread */
431 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800432 // The subscriber id that this request applies to. Defaults to
433 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
434 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435
Nathan Harold92bed182018-10-12 18:16:49 -0700436 // In cases where subId is unavailable, the caller needs to specify the phone.
437 public Phone phone;
438
vagdeviaf9a5b92018-08-15 16:01:53 -0700439 public WorkSource workSource;
440
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 public MainThreadRequest(Object argument) {
442 this.argument = argument;
443 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800444
Nathan Harold92bed182018-10-12 18:16:49 -0700445 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
446 this.argument = argument;
447 if (phone != null) {
448 this.phone = phone;
449 }
450 this.workSource = workSource;
451 }
452
vagdeviaf9a5b92018-08-15 16:01:53 -0700453 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800454 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800455 if (subId != null) {
456 this.subId = subId;
457 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700458 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 }
461
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800462 private static final class IncomingThirdPartyCallArgs {
463 public final ComponentName component;
464 public final String callId;
465 public final String callerDisplayName;
466
467 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
468 String callerDisplayName) {
469 this.component = component;
470 this.callId = callId;
471 this.callerDisplayName = callerDisplayName;
472 }
473 }
474
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 /**
476 * A handler that processes messages on the main thread in the phone process. Since many
477 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
478 * inbound binder threads to the main thread in the phone process. The Binder thread
479 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
480 * on, which will be notified when the operation completes and will contain the result of the
481 * request.
482 *
483 * <p>If a MainThreadRequest object is provided in the msg.obj field,
484 * note that request.result must be set to something non-null for the calling thread to
485 * unblock.
486 */
487 private final class MainThreadHandler extends Handler {
488 @Override
489 public void handleMessage(Message msg) {
490 MainThreadRequest request;
491 Message onCompleted;
492 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800493 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800495 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700496
497 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700498 case CMD_HANDLE_USSD_REQUEST: {
499 request = (MainThreadRequest) msg.obj;
500 final Phone phone = getPhoneFromRequest(request);
501 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
502 String ussdRequest = ussdObject.first;
503 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700504
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 if (!isUssdApiAllowed(request.subId)) {
506 // Carrier does not support use of this API, return failure.
507 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
508 UssdResponse response = new UssdResponse(ussdRequest, null);
509 Bundle returnData = new Bundle();
510 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
511 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700512
Pengquan Menga1bb6272018-09-06 09:59:22 -0700513 request.result = true;
514 notifyRequester(request);
515 return;
516 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700517
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 try {
519 request.result = phone != null
520 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
521 } catch (CallStateException cse) {
522 request.result = false;
523 }
524 // Wake up the requesting thread
525 notifyRequester(request);
526 break;
pkanwar32d516d2016-10-14 19:37:38 -0700527 }
528
Yorke Lee716f67e2015-06-17 15:39:16 -0700529 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700531 final Phone phone = getPhoneFromRequest(request);
532 request.result = phone != null ?
533 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
534 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700536 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700537 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800543 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700544 if (uiccCard == null) {
545 loge("iccTransmitApduLogicalChannel: No UICC");
546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700548 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
550 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 iccArgument.channel, iccArgument.cla, iccArgument.command,
553 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 break;
557
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 ar = (AsyncResult) msg.obj;
560 request = (MainThreadRequest) ar.userObj;
561 if (ar.exception == null && ar.result != null) {
562 request.result = ar.result;
563 } else {
564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
565 if (ar.result == null) {
566 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800567 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800569 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 } else {
571 loge("iccTransmitApduLogicalChannel: Unknown exception");
572 }
573 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700574 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 break;
576
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
578 request = (MainThreadRequest) msg.obj;
579 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800580 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 if (uiccCard == null) {
582 loge("iccTransmitApduBasicChannel: No UICC");
583 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 } else {
586 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
587 request);
588 uiccCard.iccTransmitApduBasicChannel(
589 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
590 iccArgument.p3, iccArgument.data, onCompleted);
591 }
592 break;
593
594 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
595 ar = (AsyncResult) msg.obj;
596 request = (MainThreadRequest) ar.userObj;
597 if (ar.exception == null && ar.result != null) {
598 request.result = ar.result;
599 } else {
600 request.result = new IccIoResult(0x6F, 0, (byte[])null);
601 if (ar.result == null) {
602 loge("iccTransmitApduBasicChannel: Empty response");
603 } else if (ar.exception instanceof CommandException) {
604 loge("iccTransmitApduBasicChannel: CommandException: " +
605 ar.exception);
606 } else {
607 loge("iccTransmitApduBasicChannel: Unknown exception");
608 }
609 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 break;
612
613 case CMD_EXCHANGE_SIM_IO:
614 request = (MainThreadRequest) msg.obj;
615 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800616 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 if (uiccCard == null) {
618 loge("iccExchangeSimIO: No UICC");
619 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 } else {
622 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
623 request);
624 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
625 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
626 iccArgument.data, onCompleted);
627 }
628 break;
629
630 case EVENT_EXCHANGE_SIM_IO_DONE:
631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result;
635 } else {
636 request.result = new IccIoResult(0x6f, 0, (byte[])null);
637 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 break;
640
Derek Tan4d5e5c12014-02-04 11:54:58 -0800641 case CMD_SEND_ENVELOPE:
642 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800643 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 if (uiccCard == null) {
645 loge("sendEnvelopeWithStatus: No UICC");
646 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700648 } else {
649 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
650 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
651 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800652 break;
653
654 case EVENT_SEND_ENVELOPE_DONE:
655 ar = (AsyncResult) msg.obj;
656 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700657 if (ar.exception == null && ar.result != null) {
658 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800659 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700660 request.result = new IccIoResult(0x6F, 0, (byte[])null);
661 if (ar.result == null) {
662 loge("sendEnvelopeWithStatus: Empty response");
663 } else if (ar.exception instanceof CommandException) {
664 loge("sendEnvelopeWithStatus: CommandException: " +
665 ar.exception);
666 } else {
667 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
668 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800671 break;
672
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 case CMD_OPEN_CHANNEL:
674 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800675 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800676 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 if (uiccCard == null) {
678 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800679 request.result = new IccOpenLogicalChannelResponse(-1,
680 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 } else {
683 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800684 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
685 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 break;
688
689 case EVENT_OPEN_CHANNEL_DONE:
690 ar = (AsyncResult) msg.obj;
691 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 int[] result = (int[]) ar.result;
695 int channelId = result[0];
696 byte[] selectResponse = null;
697 if (result.length > 1) {
698 selectResponse = new byte[result.length - 1];
699 for (int i = 1; i < result.length; ++i) {
700 selectResponse[i - 1] = (byte) result[i];
701 }
702 }
703 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700704 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 if (ar.result == null) {
707 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 if (ar.exception != null) {
710 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
711 }
712
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700713 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700714 if (ar.exception instanceof CommandException) {
715 CommandException.Error error =
716 ((CommandException) (ar.exception)).getCommandError();
717 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700718 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700719 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700720 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 }
722 }
723 openChannelResp = new IccOpenLogicalChannelResponse(
724 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700725 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700726 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700728 break;
729
730 case CMD_CLOSE_CHANNEL:
731 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800732 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 if (uiccCard == null) {
734 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900735 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700737 } else {
738 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
739 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
740 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 break;
742
743 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800744 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
745 break;
746
747 case CMD_NV_READ_ITEM:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800750 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
751 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800752 break;
753
754 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 ar = (AsyncResult) msg.obj;
756 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800757 if (ar.exception == null && ar.result != null) {
758 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800760 request.result = "";
761 if (ar.result == null) {
762 loge("nvReadItem: Empty response");
763 } else if (ar.exception instanceof CommandException) {
764 loge("nvReadItem: CommandException: " +
765 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700766 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800767 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 }
769 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700771 break;
772
Jake Hambye994d462014-02-03 13:10:13 -0800773 case CMD_NV_WRITE_ITEM:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
776 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800777 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700778 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800779 break;
780
781 case EVENT_NV_WRITE_ITEM_DONE:
782 handleNullReturnEvent(msg, "nvWriteItem");
783 break;
784
785 case CMD_NV_WRITE_CDMA_PRL:
786 request = (MainThreadRequest) msg.obj;
787 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800788 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800789 break;
790
791 case EVENT_NV_WRITE_CDMA_PRL_DONE:
792 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
793 break;
794
chen xu6dac5ab2018-10-26 17:39:23 -0700795 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800796 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700797 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800798 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800799 break;
800
chen xu6dac5ab2018-10-26 17:39:23 -0700801 case EVENT_RESET_MODEM_CONFIG_DONE:
802 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800803 break;
804
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700805 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
808 request);
809 Phone phone = getPhoneFromRequest(request);
810 if (phone != null) {
811 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
812 } else {
813 loge("isNRDualConnectivityEnabled: No phone object");
814 request.result = false;
815 notifyRequester(request);
816 }
817 break;
818 }
819
820 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
821 ar = (AsyncResult) msg.obj;
822 request = (MainThreadRequest) ar.userObj;
823 if (ar.exception == null && ar.result != null) {
824 request.result = ar.result;
825 } else {
826 // request.result must be set to something non-null
827 // for the calling thread to unblock
828 if (request.result != null) {
829 request.result = ar.result;
830 } else {
831 request.result = false;
832 }
833 if (ar.result == null) {
834 loge("isNRDualConnectivityEnabled: Empty response");
835 } else if (ar.exception instanceof CommandException) {
836 loge("isNRDualConnectivityEnabled: CommandException: "
837 + ar.exception);
838 } else {
839 loge("isNRDualConnectivityEnabled: Unknown exception");
840 }
841 }
842 notifyRequester(request);
843 break;
844
845 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
846 request = (MainThreadRequest) msg.obj;
847 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
848 Phone phone = getPhoneFromRequest(request);
849 if (phone != null) {
850 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
851 request.workSource);
852 } else {
853 loge("enableNrDualConnectivity: No phone object");
854 request.result =
855 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
856 notifyRequester(request);
857 }
858 break;
859 }
860
861 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null) {
865 request.result =
866 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
867 } else {
868 request.result =
869 TelephonyManager
870 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
871 if (ar.exception instanceof CommandException) {
872 CommandException.Error error =
873 ((CommandException) (ar.exception)).getCommandError();
874 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
875 request.result =
876 TelephonyManager
877 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000878 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
879 request.result =
880 TelephonyManager
881 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700882 }
883 loge("enableNrDualConnectivity" + ": CommandException: "
884 + ar.exception);
885 } else {
886 loge("enableNrDualConnectivity" + ": Unknown exception");
887 }
888 }
889 notifyRequester(request);
890 break;
891 }
892
SongFerngWang9e060372020-12-21 16:41:52 +0800893 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800894 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800895 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
896 request);
897 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800898 break;
899
SongFerngWang9e060372020-12-21 16:41:52 +0800900 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null && ar.result != null) {
904 request.result = ar.result; // Integer
905 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530906 // request.result must be set to something non-null
907 // for the calling thread to unblock
908 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800909 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800910 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800911 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800912 loge("getAllowedNetworkTypesBitmask: CommandException: "
913 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800914 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800915 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800916 }
917 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700918 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800919 break;
920
SongFerngWang9e060372020-12-21 16:41:52 +0800921 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800922 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800923 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
924 request);
925 Pair<Integer, Long> reasonWithNetworkTypes =
926 (Pair<Integer, Long>) request.argument;
927 getPhoneFromRequest(request).setAllowedNetworkTypes(
928 reasonWithNetworkTypes.first,
929 reasonWithNetworkTypes.second,
930 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800931 break;
932
SongFerngWang9e060372020-12-21 16:41:52 +0800933 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
934 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800935 break;
936
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000937 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
938 request = (MainThreadRequest)msg.obj;
939 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800940 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000941 break;
942
943 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
944 ar = (AsyncResult)msg.obj;
945 request = (MainThreadRequest)ar.userObj;
946 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700947 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000948 break;
949
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800950 case CMD_SET_VOICEMAIL_NUMBER:
951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
953 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800954 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
955 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800956 break;
957
958 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
959 handleNullReturnEvent(msg, "setVoicemailNumber");
960 break;
961
Stuart Scott54788802015-03-30 13:18:01 -0700962 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
963 request = (MainThreadRequest) msg.obj;
964 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
965 request);
966 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
967 break;
968
969 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
970 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
971 break;
972
Shishir Agrawal302c8692015-06-19 13:49:39 -0700973 case CMD_PERFORM_NETWORK_SCAN:
974 request = (MainThreadRequest) msg.obj;
975 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
976 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
977 break;
978
Hall Liua1acea22020-09-18 19:04:59 -0700979 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800980 request = (MainThreadRequest) msg.obj;
981 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700982 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
983 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
984 request.argument;
985 int callForwardingReason = args.first;
986 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800987 break;
Hall Liua1acea22020-09-18 19:04:59 -0700988 }
989 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700992 TelephonyManager.CallForwardingInfoCallback callback =
993 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
994 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800995 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700996 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800997 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
998 for (CallForwardInfo callForwardInfo : callForwardInfos) {
999 // Service Class is a bit mask per 3gpp 27.007. Search for
1000 // any service for voice call.
1001 if ((callForwardInfo.serviceClass
1002 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -07001003 callForwardingInfo = new CallForwardingInfo(true,
1004 callForwardInfo.reason,
1005 callForwardInfo.number,
1006 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -08001007 break;
1008 }
1009 }
1010 // Didn't find a call forward info for voice call.
1011 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -07001012 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1013 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001014 }
Hall Liua1acea22020-09-18 19:04:59 -07001015 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001016 } else {
1017 if (ar.result == null) {
1018 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1019 }
1020 if (ar.exception != null) {
1021 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1022 }
Hall Liuae527aa2020-09-29 17:10:18 -07001023 int errorCode = TelephonyManager
1024 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001025 if (ar.exception instanceof CommandException) {
1026 CommandException.Error error =
1027 ((CommandException) (ar.exception)).getCommandError();
1028 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001029 errorCode = TelephonyManager
1030 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001031 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001032 errorCode = TelephonyManager
1033 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001034 }
1035 }
Hall Liua1acea22020-09-18 19:04:59 -07001036 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001037 }
sqian80370722020-01-29 15:02:51 -08001038 break;
Hall Liua1acea22020-09-18 19:04:59 -07001039 }
sqian80370722020-01-29 15:02:51 -08001040
Hall Liua1acea22020-09-18 19:04:59 -07001041 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001042 request = (MainThreadRequest) msg.obj;
1043 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001044 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001045 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001046 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1047 request.argument).first;
1048 request.phone.setCallForwardingOption(
1049 callForwardingInfoToSet.isEnabled()
1050 ? CommandsInterface.CF_ACTION_ENABLE
1051 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001052 callForwardingInfoToSet.getReason(),
1053 callForwardingInfoToSet.getNumber(),
1054 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1055 break;
Hall Liua1acea22020-09-18 19:04:59 -07001056 }
sqian80370722020-01-29 15:02:51 -08001057
Hall Liua1acea22020-09-18 19:04:59 -07001058 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001061 Consumer<Integer> callback =
1062 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1063 request.argument).second;
1064 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001065 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001066 int errorCode = TelephonyManager.CallForwardingInfoCallback
1067 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001068 if (ar.exception instanceof CommandException) {
1069 CommandException.Error error =
1070 ((CommandException) (ar.exception)).getCommandError();
1071 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001072 errorCode = TelephonyManager.CallForwardingInfoCallback
1073 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001074 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001075 errorCode = TelephonyManager.CallForwardingInfoCallback
1076 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001077 }
1078 }
1079 callback.accept(errorCode);
1080 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001081 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001082 }
sqian80370722020-01-29 15:02:51 -08001083 break;
Hall Liua1acea22020-09-18 19:04:59 -07001084 }
sqian80370722020-01-29 15:02:51 -08001085
Hall Liua1acea22020-09-18 19:04:59 -07001086 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001087 request = (MainThreadRequest) msg.obj;
1088 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1089 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1090 break;
Hall Liua1acea22020-09-18 19:04:59 -07001091 }
sqian80370722020-01-29 15:02:51 -08001092
Hall Liua1acea22020-09-18 19:04:59 -07001093 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001094 ar = (AsyncResult) msg.obj;
1095 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001096 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001097 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1098 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001099 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001100 // Service Class is a bit mask per 3gpp 27.007.
1101 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001102 if (callForwardResults.length > 1
1103 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001104 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001105 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001106 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1107 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001108 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001109 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001110 }
1111 } else {
1112 if (ar.result == null) {
1113 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1114 }
1115 if (ar.exception != null) {
1116 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1117 }
1118 if (ar.exception instanceof CommandException) {
1119 CommandException.Error error =
1120 ((CommandException) (ar.exception)).getCommandError();
1121 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1122 callForwardingStatus =
1123 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1124 }
1125 }
1126 }
Hall Liua1acea22020-09-18 19:04:59 -07001127 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001128 break;
Hall Liua1acea22020-09-18 19:04:59 -07001129 }
sqian80370722020-01-29 15:02:51 -08001130
Hall Liua1acea22020-09-18 19:04:59 -07001131 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001132 request = (MainThreadRequest) msg.obj;
1133 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001134 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1135 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001136 break;
Hall Liua1acea22020-09-18 19:04:59 -07001137 }
sqian80370722020-01-29 15:02:51 -08001138
Hall Liua1acea22020-09-18 19:04:59 -07001139 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001140 ar = (AsyncResult) msg.obj;
1141 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001142 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1143 Consumer<Integer> callback =
1144 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1145 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001146 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001147 if (ar.exception instanceof CommandException) {
1148 CommandException.Error error =
1149 ((CommandException) (ar.exception)).getCommandError();
1150 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1151 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1152 } else {
1153 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1154 }
1155 } else {
1156 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1157 }
1158 } else {
1159 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1160 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001161 }
sqian80370722020-01-29 15:02:51 -08001162 break;
Hall Liua1acea22020-09-18 19:04:59 -07001163 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001164 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1165 ar = (AsyncResult) msg.obj;
1166 request = (MainThreadRequest) ar.userObj;
1167 CellNetworkScanResult cellScanResult;
1168 if (ar.exception == null && ar.result != null) {
1169 cellScanResult = new CellNetworkScanResult(
1170 CellNetworkScanResult.STATUS_SUCCESS,
1171 (List<OperatorInfo>) ar.result);
1172 } else {
1173 if (ar.result == null) {
1174 loge("getCellNetworkScanResults: Empty response");
1175 }
1176 if (ar.exception != null) {
1177 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1178 }
1179 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1180 if (ar.exception instanceof CommandException) {
1181 CommandException.Error error =
1182 ((CommandException) (ar.exception)).getCommandError();
1183 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1184 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1185 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1186 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1187 }
1188 }
1189 cellScanResult = new CellNetworkScanResult(errorCode, null);
1190 }
1191 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001192 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001193 break;
1194
1195 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1196 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001197 ManualNetworkSelectionArgument selArg =
1198 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001199 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1200 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001201 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1202 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001203 break;
1204
1205 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001206 ar = (AsyncResult) msg.obj;
1207 request = (MainThreadRequest) ar.userObj;
1208 if (ar.exception == null) {
1209 request.result = true;
1210 } else {
1211 request.result = false;
1212 loge("setNetworkSelectionModeManual " + ar.exception);
1213 }
1214 notifyRequester(request);
1215 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001216 break;
1217
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001218 case CMD_GET_MODEM_ACTIVITY_INFO:
1219 request = (MainThreadRequest) msg.obj;
1220 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001221 if (defaultPhone != null) {
1222 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001223 } else {
1224 ResultReceiver result = (ResultReceiver) request.argument;
1225 Bundle bundle = new Bundle();
1226 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liue8315982020-10-09 19:00:11 -07001227 new ModemActivityInfo(0, 0, 0,
1228 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
sqian1a1be542020-03-05 11:37:28 -08001229 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001230 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001231 break;
1232
Hall Liudf4171d2020-10-14 16:54:44 -07001233 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001234 ar = (AsyncResult) msg.obj;
1235 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001236 ResultReceiver result = (ResultReceiver) request.argument;
1237
Hall Liudf4171d2020-10-14 16:54:44 -07001238 ModemActivityInfo ret = null;
1239 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001240 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001241 // Update the last modem activity info and the result of the request.
1242 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1243 if (isModemActivityInfoValid(info)) {
Hall Liue8315982020-10-09 19:00:11 -07001244 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
sqian1a1be542020-03-05 11:37:28 -08001245 int[] txTimeMs = info.getTransmitTimeMillis();
1246 int[] lastModemTxTimeMs = mLastModemActivityInfo
1247 .getTransmitTimeMillis();
1248 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1249 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1250 }
Hall Liue8315982020-10-09 19:00:11 -07001251 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
sqian1a1be542020-03-05 11:37:28 -08001252 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1253 + mLastModemActivityInfo.getSleepTimeMillis());
1254 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1255 + mLastModemActivityInfo.getIdleTimeMillis());
1256 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1257 mLastModemActivityInfo.setReceiveTimeMillis(
1258 info.getReceiveTimeMillis()
1259 + mLastModemActivityInfo.getReceiveTimeMillis());
1260 }
Hall Liue8315982020-10-09 19:00:11 -07001261 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
sqian1a1be542020-03-05 11:37:28 -08001262 mLastModemActivityInfo.getSleepTimeMillis(),
1263 mLastModemActivityInfo.getIdleTimeMillis(),
1264 mLastModemActivityInfo.getTransmitTimeMillis(),
1265 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001266 } else {
1267 if (ar.result == null) {
1268 loge("queryModemActivityInfo: Empty response");
Hall Liudf4171d2020-10-14 16:54:44 -07001269 error = TelephonyManager.ModemActivityInfoException
1270 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001271 } else if (ar.exception instanceof CommandException) {
1272 loge("queryModemActivityInfo: CommandException: " +
1273 ar.exception);
Hall Liudf4171d2020-10-14 16:54:44 -07001274 error = TelephonyManager.ModemActivityInfoException
1275 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001276 } else {
1277 loge("queryModemActivityInfo: Unknown exception");
Hall Liudf4171d2020-10-14 16:54:44 -07001278 error = TelephonyManager.ModemActivityInfoException
1279 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001280 }
1281 }
sqian1a1be542020-03-05 11:37:28 -08001282 Bundle bundle = new Bundle();
Hall Liudf4171d2020-10-14 16:54:44 -07001283 if (ret != null) {
1284 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1285 } else {
1286 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1287 }
sqian1a1be542020-03-05 11:37:28 -08001288 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001289 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001290 break;
Hall Liudf4171d2020-10-14 16:54:44 -07001291 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001292
Meng Wang1a7c35a2016-05-05 20:56:15 -07001293 case CMD_SET_ALLOWED_CARRIERS:
1294 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001295 CarrierRestrictionRules argument =
1296 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001297 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001298 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 break;
1300
1301 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
1304 if (ar.exception == null && ar.result != null) {
1305 request.result = ar.result;
1306 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001307 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1308 if (ar.exception instanceof CommandException) {
1309 loge("setAllowedCarriers: CommandException: " + ar.exception);
1310 CommandException.Error error =
1311 ((CommandException) (ar.exception)).getCommandError();
1312 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1313 request.result =
1314 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1315 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001316 } else {
1317 loge("setAllowedCarriers: Unknown exception");
1318 }
1319 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001320 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001321 break;
1322
1323 case CMD_GET_ALLOWED_CARRIERS:
1324 request = (MainThreadRequest) msg.obj;
1325 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001326 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001327 break;
1328
1329 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
1332 if (ar.exception == null && ar.result != null) {
1333 request.result = ar.result;
1334 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001335 request.result = new IllegalStateException(
1336 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001337 if (ar.result == null) {
1338 loge("getAllowedCarriers: Empty response");
1339 } else if (ar.exception instanceof CommandException) {
1340 loge("getAllowedCarriers: CommandException: " +
1341 ar.exception);
1342 } else {
1343 loge("getAllowedCarriers: Unknown exception");
1344 }
1345 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001346 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001347 break;
1348
Nathan Haroldb3014052017-01-25 15:57:32 -08001349 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1350 ar = (AsyncResult) msg.obj;
1351 request = (MainThreadRequest) ar.userObj;
1352 if (ar.exception == null && ar.result != null) {
1353 request.result = ar.result;
1354 } else {
1355 request.result = new IllegalArgumentException(
1356 "Failed to retrieve Forbidden Plmns");
1357 if (ar.result == null) {
1358 loge("getForbiddenPlmns: Empty response");
1359 } else {
1360 loge("getForbiddenPlmns: Unknown exception");
1361 }
1362 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001363 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001364 break;
1365
1366 case CMD_GET_FORBIDDEN_PLMNS:
1367 request = (MainThreadRequest) msg.obj;
1368 uiccCard = getUiccCardFromRequest(request);
1369 if (uiccCard == null) {
1370 loge("getForbiddenPlmns() UiccCard is null");
1371 request.result = new IllegalArgumentException(
1372 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001373 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001374 break;
1375 }
1376 Integer appType = (Integer) request.argument;
1377 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1378 if (uiccApp == null) {
1379 loge("getForbiddenPlmns() no app with specified type -- "
1380 + appType);
1381 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001382 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001383 break;
1384 } else {
1385 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1386 + " specified type -- " + appType);
1387 }
1388 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1389 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1390 onCompleted);
1391 break;
1392
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001393 case CMD_SWITCH_SLOTS:
1394 request = (MainThreadRequest) msg.obj;
1395 int[] physicalSlots = (int[]) request.argument;
1396 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1397 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1398 break;
1399
1400 case EVENT_SWITCH_SLOTS_DONE:
1401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
1403 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001404 notifyRequester(request);
1405 break;
1406 case CMD_GET_NETWORK_SELECTION_MODE:
1407 request = (MainThreadRequest) msg.obj;
1408 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1409 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1410 break;
1411
1412 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1413 ar = (AsyncResult) msg.obj;
1414 request = (MainThreadRequest) ar.userObj;
1415 if (ar.exception != null) {
1416 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1417 } else {
1418 int mode = ((int[]) ar.result)[0];
1419 if (mode == 0) {
1420 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1421 } else {
1422 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1423 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001424 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001425 notifyRequester(request);
1426 break;
1427 case CMD_GET_CDMA_ROAMING_MODE:
1428 request = (MainThreadRequest) msg.obj;
1429 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1430 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1431 break;
1432 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1433 ar = (AsyncResult) msg.obj;
1434 request = (MainThreadRequest) ar.userObj;
1435 if (ar.exception != null) {
1436 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1437 } else {
1438 request.result = ((int[]) ar.result)[0];
1439 }
1440 notifyRequester(request);
1441 break;
1442 case CMD_SET_CDMA_ROAMING_MODE:
1443 request = (MainThreadRequest) msg.obj;
1444 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1445 int mode = (int) request.argument;
1446 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1447 break;
1448 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1449 ar = (AsyncResult) msg.obj;
1450 request = (MainThreadRequest) ar.userObj;
1451 request.result = ar.exception == null;
1452 notifyRequester(request);
1453 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001454 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1455 request = (MainThreadRequest) msg.obj;
1456 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1457 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1458 break;
1459 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 if (ar.exception != null) {
1463 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1464 } else {
1465 request.result = ((int[]) ar.result)[0];
1466 }
1467 notifyRequester(request);
1468 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001469 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1470 request = (MainThreadRequest) msg.obj;
1471 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1472 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001473 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1474 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001475 break;
1476 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1477 ar = (AsyncResult) msg.obj;
1478 request = (MainThreadRequest) ar.userObj;
1479 request.result = ar.exception == null;
1480 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001481 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001482 case CMD_GET_ALL_CELL_INFO:
1483 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001484 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001485 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001486 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001487 case EVENT_GET_ALL_CELL_INFO_DONE:
1488 ar = (AsyncResult) msg.obj;
1489 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001490 // If a timeout occurs, the response will be null
1491 request.result = (ar.exception == null && ar.result != null)
1492 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 synchronized (request) {
1494 request.notifyAll();
1495 }
1496 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001497 case CMD_REQUEST_CELL_INFO_UPDATE:
1498 request = (MainThreadRequest) msg.obj;
1499 request.phone.requestCellInfoUpdate(request.workSource,
1500 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1501 break;
1502 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1503 ar = (AsyncResult) msg.obj;
1504 request = (MainThreadRequest) ar.userObj;
1505 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1506 try {
1507 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001508 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001509 cb.onError(
1510 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1511 ar.exception.getClass().getName(),
1512 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001513 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001514 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001515 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001516 } else {
1517 // use the result as returned
1518 cb.onCellInfo((List<CellInfo>) ar.result);
1519 }
1520 } catch (RemoteException re) {
1521 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1522 }
1523 break;
Sarah Chincc055732020-11-18 13:39:35 -08001524 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001525 request = (MainThreadRequest) msg.obj;
1526 WorkSource ws = (WorkSource) request.argument;
1527 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001528 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001529 break;
Sarah Chincc055732020-11-18 13:39:35 -08001530 }
1531 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001532 ar = (AsyncResult) msg.obj;
1533 request = (MainThreadRequest) ar.userObj;
1534 if (ar.exception == null) {
1535 request.result = ar.result;
1536 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001537 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001538 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001539 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001540 }
1541
1542 synchronized (request) {
1543 request.notifyAll();
1544 }
1545 break;
Sarah Chincc055732020-11-18 13:39:35 -08001546 }
chen xu6dac5ab2018-10-26 17:39:23 -07001547 case CMD_MODEM_REBOOT:
1548 request = (MainThreadRequest) msg.obj;
1549 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001550 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001551 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001552 case EVENT_CMD_MODEM_REBOOT_DONE:
1553 handleNullReturnEvent(msg, "rebootModem");
1554 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001555 case CMD_REQUEST_ENABLE_MODEM:
1556 request = (MainThreadRequest) msg.obj;
1557 boolean enable = (boolean) request.argument;
1558 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001559 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001560 PhoneConfigurationManager.getInstance()
1561 .enablePhone(request.phone, enable, onCompleted);
1562 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001563 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001564 ar = (AsyncResult) msg.obj;
1565 request = (MainThreadRequest) ar.userObj;
1566 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001567 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001568 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001569 if ((boolean) request.result) {
1570 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1571 updateModemStateMetrics();
1572 } else {
1573 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1574 + ar.exception);
1575 }
1576 notifyRequester(request);
1577 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001578 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001579 case CMD_GET_MODEM_STATUS:
1580 request = (MainThreadRequest) msg.obj;
1581 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1582 PhoneConfigurationManager.getInstance()
1583 .getPhoneStatusFromModem(request.phone, onCompleted);
1584 break;
1585 case EVENT_GET_MODEM_STATUS_DONE:
1586 ar = (AsyncResult) msg.obj;
1587 request = (MainThreadRequest) ar.userObj;
1588 int id = request.phone.getPhoneId();
1589 if (ar.exception == null && ar.result != null) {
1590 request.result = ar.result;
1591 //update the cache as modem status has changed
1592 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1593 (boolean) request.result);
1594 } else {
1595 // Return true if modem status cannot be retrieved. For most cases,
1596 // modem status is on. And for older version modems, GET_MODEM_STATUS
1597 // and disable modem are not supported. Modem is always on.
1598 // TODO: this should be fixed in R to support a third
1599 // status UNKNOWN b/131631629
1600 request.result = true;
1601 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1602 + ar.exception);
1603 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001604 notifyRequester(request);
1605 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001606 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1607 request = (MainThreadRequest) msg.obj;
1608 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1609 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1610 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1611 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1612 break;
1613 }
1614 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1615 ar = (AsyncResult) msg.obj;
1616 request = (MainThreadRequest) ar.userObj;
1617 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1618 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1619 args.second.accept(ar.exception == null);
1620 notifyRequester(request);
1621 break;
1622 }
Sarah Chincc055732020-11-18 13:39:35 -08001623 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1624 request = (MainThreadRequest) msg.obj;
1625 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1626 Phone phone = getPhoneFromRequest(request);
1627 if (phone != null) {
1628 phone.getSystemSelectionChannels(onCompleted);
1629 } else {
1630 loge("getSystemSelectionChannels: No phone object");
1631 request.result = new ArrayList<RadioAccessSpecifier>();
1632 notifyRequester(request);
1633 }
1634 break;
1635 }
1636 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1637 ar = (AsyncResult) msg.obj;
1638 request = (MainThreadRequest) ar.userObj;
1639 if (ar.exception == null && ar.result != null) {
1640 request.result = ar.result;
1641 } else {
Sarah Chin58691872021-03-13 03:17:40 -08001642 request.result = new IllegalStateException(
1643 "Failed to retrieve system selecton channels");
Sarah Chincc055732020-11-18 13:39:35 -08001644 if (ar.result == null) {
1645 loge("getSystemSelectionChannels: Empty response");
1646 } else {
1647 loge("getSystemSelectionChannels: Unknown exception");
1648 }
1649 }
1650 notifyRequester(request);
1651 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001652 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1653 ar = (AsyncResult) msg.obj;
1654 request = (MainThreadRequest) ar.userObj;
1655 if (ar.exception == null && ar.result != null) {
1656 request.result = ar.result;
1657 } else {
1658 request.result = -1;
1659 loge("Failed to set Forbidden Plmns");
1660 if (ar.result == null) {
1661 loge("setForbidenPlmns: Empty response");
1662 } else if (ar.exception != null) {
1663 loge("setForbiddenPlmns: Exception: " + ar.exception);
1664 request.result = -1;
1665 } else {
1666 loge("setForbiddenPlmns: Unknown exception");
1667 }
1668 }
1669 notifyRequester(request);
1670 break;
1671 case CMD_SET_FORBIDDEN_PLMNS:
1672 request = (MainThreadRequest) msg.obj;
1673 uiccCard = getUiccCardFromRequest(request);
1674 if (uiccCard == null) {
1675 loge("setForbiddenPlmns: UiccCard is null");
1676 request.result = -1;
1677 notifyRequester(request);
1678 break;
1679 }
1680 Pair<Integer, List<String>> setFplmnsArgs =
1681 (Pair<Integer, List<String>>) request.argument;
1682 appType = setFplmnsArgs.first;
1683 List<String> fplmns = setFplmnsArgs.second;
1684 uiccApp = uiccCard.getApplicationByType(appType);
1685 if (uiccApp == null) {
1686 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1687 request.result = -1;
1688 loge("Failed to get UICC App");
1689 notifyRequester(request);
1690 } else {
1691 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1692 ((SIMRecords) uiccApp.getIccRecords())
1693 .setForbiddenPlmns(onCompleted, fplmns);
1694 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001695 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001696 case CMD_ERASE_MODEM_CONFIG:
1697 request = (MainThreadRequest) msg.obj;
1698 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1699 defaultPhone.eraseModemConfig(onCompleted);
1700 break;
1701 case EVENT_ERASE_MODEM_CONFIG_DONE:
1702 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001703 break;
zoey chenf95ca592019-12-30 16:11:23 +08001704
1705 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1708 Pair<String, String> changed = (Pair<String, String>) request.argument;
1709 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1710 changed.first, changed.second, onCompleted);
1711 break;
1712 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1713 ar = (AsyncResult) msg.obj;
1714 request = (MainThreadRequest) ar.userObj;
1715 if (ar.exception == null) {
1716 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001717 // If the operation is successful, update the PIN storage
1718 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1719 int phoneId = getPhoneFromRequest(request).getPhoneId();
Grace Jia59437e82021-09-21 15:47:32 -07001720 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1721 pinStorage.storePin(passwords.second, phoneId,
1722 pinStorage.getIccid(phoneId));
zoey chenf95ca592019-12-30 16:11:23 +08001723 } else {
1724 request.result = msg.arg1;
1725 }
1726 notifyRequester(request);
1727 break;
1728
Michele Berionned9fbae52020-11-13 02:36:59 +00001729 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001730 request = (MainThreadRequest) msg.obj;
1731 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1732 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1733 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1734 enabled.first, enabled.second, onCompleted);
1735 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001736 }
zoey chenf95ca592019-12-30 16:11:23 +08001737 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1738 ar = (AsyncResult) msg.obj;
1739 request = (MainThreadRequest) ar.userObj;
1740 if (ar.exception == null) {
1741 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001742 // If the operation is successful, update the PIN storage
1743 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1744 int phoneId = getPhoneFromRequest(request).getPhoneId();
1745 if (enabled.first) {
Grace Jia59437e82021-09-21 15:47:32 -07001746 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1747 pinStorage.storePin(enabled.second, phoneId,
1748 pinStorage.getIccid(phoneId));
Michele Berionned9fbae52020-11-13 02:36:59 +00001749 } else {
1750 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1751 }
zoey chenf95ca592019-12-30 16:11:23 +08001752 } else {
1753 request.result = msg.arg1;
1754 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001755
1756
zoey chenf95ca592019-12-30 16:11:23 +08001757 notifyRequester(request);
1758 break;
1759
Peter Wangdafb9ac2020-01-15 14:13:38 -08001760 case MSG_NOTIFY_USER_ACTIVITY:
1761 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001762 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001763 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1764 getDefaultPhone().getContext().sendBroadcastAsUser(
1765 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1766 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001767
1768 case CMD_SET_DATA_THROTTLING: {
1769 request = (MainThreadRequest) msg.obj;
1770 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1771 DataThrottlingRequest dataThrottlingRequest =
1772 (DataThrottlingRequest) request.argument;
1773 Phone phone = getPhoneFromRequest(request);
1774 if (phone != null) {
1775 phone.setDataThrottling(onCompleted,
1776 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1777 dataThrottlingRequest.getCompletionDurationMillis());
1778 } else {
1779 loge("setDataThrottling: No phone object");
1780 request.result =
1781 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1782 notifyRequester(request);
1783 }
1784
1785 break;
1786 }
1787 case EVENT_SET_DATA_THROTTLING_DONE:
1788 ar = (AsyncResult) msg.obj;
1789 request = (MainThreadRequest) ar.userObj;
1790
1791 if (ar.exception == null) {
1792 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1793 } else if (ar.exception instanceof CommandException) {
1794 loge("setDataThrottling: CommandException: " + ar.exception);
1795 CommandException.Error error =
1796 ((CommandException) (ar.exception)).getCommandError();
1797
1798 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1799 request.result = TelephonyManager
1800 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1801 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1802 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001803 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1804 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001805 } else {
1806 request.result =
1807 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1808 }
1809 } else {
1810 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1811 }
1812 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1813 notifyRequester(request);
1814 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001815
1816 case CMD_SET_SIM_POWER: {
1817 request = (MainThreadRequest) msg.obj;
1818 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1819 request = (MainThreadRequest) msg.obj;
1820 int stateToSet =
1821 ((Pair<Integer, IIntegerConsumer>)
1822 request.argument).first;
1823 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1824 break;
1825 }
1826 case EVENT_SET_SIM_POWER_DONE: {
1827 ar = (AsyncResult) msg.obj;
1828 request = (MainThreadRequest) ar.userObj;
1829 IIntegerConsumer callback =
1830 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1831 if (ar.exception != null) {
1832 loge("setSimPower exception: " + ar.exception);
1833 int errorCode = TelephonyManager.CallForwardingInfoCallback
1834 .RESULT_ERROR_UNKNOWN;
1835 if (ar.exception instanceof CommandException) {
1836 CommandException.Error error =
1837 ((CommandException) (ar.exception)).getCommandError();
1838 if (error == CommandException.Error.SIM_ERR) {
1839 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1840 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1841 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1842 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1843 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1844 } else {
1845 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1846 }
1847 }
1848 try {
1849 callback.accept(errorCode);
1850 } catch (RemoteException e) {
1851 // Ignore if the remote process is no longer available to call back.
1852 Log.w(LOG_TAG, "setSimPower: callback not available.");
1853 }
1854 } else {
1855 try {
1856 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1857 } catch (RemoteException e) {
1858 // Ignore if the remote process is no longer available to call back.
1859 Log.w(LOG_TAG, "setSimPower: callback not available.");
1860 }
1861 }
1862 break;
1863 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001864 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1865 request = (MainThreadRequest) msg.obj;
1866
1867 final Phone phone = getPhoneFromRequest(request);
1868 if (phone == null || phone.getServiceStateTracker() == null) {
1869 request.result = new IllegalStateException("Phone or SST is null");
1870 notifyRequester(request);
1871 break;
1872 }
1873
1874 Pair<Integer, SignalStrengthUpdateRequest> pair =
1875 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1876 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1877 request);
1878 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1879 request.subId, pair.first /*callingUid*/,
1880 pair.second /*request*/, onCompleted);
1881 break;
1882 }
1883 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1884 ar = (AsyncResult) msg.obj;
1885 request = (MainThreadRequest) ar.userObj;
1886 // request.result will be the exception of ar if present, true otherwise.
1887 // Be cautious not to leave result null which will wait() forever
1888 request.result = ar.exception != null ? ar.exception : true;
1889 notifyRequester(request);
1890 break;
1891 }
1892 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1893 request = (MainThreadRequest) msg.obj;
1894
1895 Phone phone = getPhoneFromRequest(request);
1896 if (phone == null || phone.getServiceStateTracker() == null) {
1897 request.result = new IllegalStateException("Phone or SST is null");
1898 notifyRequester(request);
1899 break;
1900 }
1901
1902 Pair<Integer, SignalStrengthUpdateRequest> pair =
1903 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1904 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1905 request);
1906 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1907 request.subId, pair.first /*callingUid*/,
1908 pair.second /*request*/, onCompleted);
1909 break;
1910 }
1911 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1912 ar = (AsyncResult) msg.obj;
1913 request = (MainThreadRequest) ar.userObj;
1914 request.result = ar.exception != null ? ar.exception : true;
1915 notifyRequester(request);
1916 break;
1917 }
Jordan Liud5366d92020-11-24 14:50:34 -08001918
Hongbo Zengd31d3a32021-02-08 21:50:28 +08001919 case CMD_GET_SLICING_CONFIG: {
1920 request = (MainThreadRequest) msg.obj;
1921 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1922 request.phone.getSlicingConfig(onCompleted);
1923 break;
1924 }
1925 case EVENT_GET_SLICING_CONFIG_DONE: {
1926 ar = (AsyncResult) msg.obj;
1927 request = (MainThreadRequest) ar.userObj;
1928 ResultReceiver result = (ResultReceiver) request.argument;
1929
1930 SlicingConfig slicingConfig = null;
1931 Bundle bundle = new Bundle();
1932 int resultCode = 0;
1933 if (ar.exception != null) {
1934 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1935 + ar.exception);
1936 resultCode = TelephonyManager.SlicingException.ERROR_MODEM_ERROR;
1937 } else if (ar.result == null) {
1938 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
1939 resultCode = TelephonyManager.SlicingException.ERROR_TIMEOUT;
1940 } else {
1941 // use the result as returned
1942 resultCode = TelephonyManager.SlicingException.SUCCESS;
1943 slicingConfig = (SlicingConfig) ar.result;
1944 }
1945
1946 if (slicingConfig == null) {
1947 slicingConfig = new SlicingConfig();
1948 }
1949 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1950 result.send(resultCode, bundle);
1951 notifyRequester(request);
1952 break;
1953 }
1954
Michele Berionned9fbae52020-11-13 02:36:59 +00001955 case CMD_PREPARE_UNATTENDED_REBOOT:
1956 request = (MainThreadRequest) msg.obj;
1957 request.result =
Rafael Higuera Silvacd3aef22021-08-30 15:16:50 +00001958 UiccController.getInstance().getPinStorage()
1959 .prepareUnattendedReboot(request.workSource);
Michele Berionned9fbae52020-11-13 02:36:59 +00001960 notifyRequester(request);
1961 break;
1962
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 default:
1964 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1965 break;
1966 }
1967 }
Jake Hambye994d462014-02-03 13:10:13 -08001968
Pengquan Menga1bb6272018-09-06 09:59:22 -07001969 private void notifyRequester(MainThreadRequest request) {
1970 synchronized (request) {
1971 request.notifyAll();
1972 }
1973 }
1974
Jake Hambye994d462014-02-03 13:10:13 -08001975 private void handleNullReturnEvent(Message msg, String command) {
1976 AsyncResult ar = (AsyncResult) msg.obj;
1977 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1978 if (ar.exception == null) {
1979 request.result = true;
1980 } else {
1981 request.result = false;
1982 if (ar.exception instanceof CommandException) {
1983 loge(command + ": CommandException: " + ar.exception);
1984 } else {
1985 loge(command + ": Unknown exception");
1986 }
1987 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001988 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 }
1991
1992 /**
1993 * Posts the specified command to be executed on the main thread,
1994 * waits for the request to complete, and returns the result.
1995 * @see #sendRequestAsync
1996 */
1997 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001998 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1999 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002000 }
2001
2002 /**
2003 * Posts the specified command to be executed on the main thread,
2004 * waits for the request to complete, and returns the result.
2005 * @see #sendRequestAsync
2006 */
2007 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2008 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002009 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002010 }
2011
2012 /**
2013 * Posts the specified command to be executed on the main thread,
2014 * waits for the request to complete, and returns the result.
2015 * @see #sendRequestAsync
2016 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002017 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002018 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2019 }
2020
2021 /**
2022 * Posts the specified command to be executed on the main thread,
2023 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2024 * if not timeout or null otherwise.
2025 * @see #sendRequestAsync
2026 */
2027 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2028 long timeoutInMs) {
2029 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002030 }
2031
2032 /**
2033 * Posts the specified command to be executed on the main thread,
2034 * waits for the request to complete, and returns the result.
2035 * @see #sendRequestAsync
2036 */
Nathan Harold92bed182018-10-12 18:16:49 -07002037 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002038 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002039 }
2040
2041 /**
2042 * Posts the specified command to be executed on the main thread,
2043 * waits for the request to complete, and returns the result.
2044 * @see #sendRequestAsync
2045 */
2046 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002047 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2048 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002049 }
2050
2051 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002052 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2053 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2054 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002055 * @see #sendRequestAsync
2056 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002057 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2058 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2060 throw new RuntimeException("This method will deadlock if called from the main thread.");
2061 }
2062
Nathan Harold92bed182018-10-12 18:16:49 -07002063 MainThreadRequest request = null;
2064 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2065 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2066 } else if (phone != null) {
2067 request = new MainThreadRequest(argument, phone, workSource);
2068 } else {
2069 request = new MainThreadRequest(argument, subId, workSource);
2070 }
2071
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 Message msg = mMainThreadHandler.obtainMessage(command, request);
2073 msg.sendToTarget();
2074
Rambo Wang0f050d82021-02-12 11:43:36 -08002075
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002076 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002077 if (timeoutInMs >= 0) {
2078 // Wait for at least timeoutInMs before returning null request result
2079 long now = SystemClock.elapsedRealtime();
2080 long deadline = now + timeoutInMs;
2081 while (request == null && now < deadline) {
2082 try {
2083 request.wait(deadline - now);
2084 } catch (InterruptedException e) {
2085 // Do nothing, go back and check if request is completed or timeout
2086 } finally {
2087 now = SystemClock.elapsedRealtime();
2088 }
2089 }
2090 } else {
2091 // Wait for the request to complete
2092 while (request.result == null) {
2093 try {
2094 request.wait();
2095 } catch (InterruptedException e) {
2096 // Do nothing, go back and wait until the request is complete
2097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 }
2099 }
2100 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002101 if (request.result == null) {
2102 Log.wtf(LOG_TAG,
2103 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 return request.result;
2106 }
2107
2108 /**
2109 * Asynchronous ("fire and forget") version of sendRequest():
2110 * Posts the specified command to be executed on the main thread, and
2111 * returns immediately.
2112 * @see #sendRequest
2113 */
2114 private void sendRequestAsync(int command) {
2115 mMainThreadHandler.sendEmptyMessage(command);
2116 }
2117
2118 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002119 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002120 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002121 */
2122 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002123 sendRequestAsync(command, argument, null, null);
2124 }
2125
2126 /**
2127 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2128 * @see {@link #sendRequest(int,Object)}
2129 */
2130 private void sendRequestAsync(
2131 int command, Object argument, Phone phone, WorkSource workSource) {
2132 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002133 Message msg = mMainThreadHandler.obtainMessage(command, request);
2134 msg.sendToTarget();
2135 }
2136
2137 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 * Initialize the singleton PhoneInterfaceManager instance.
2139 * This is only done once, at startup, from PhoneApp.onCreate().
2140 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002141 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 synchronized (PhoneInterfaceManager.class) {
2143 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002144 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145 } else {
2146 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2147 }
2148 return sInstance;
2149 }
2150 }
2151
2152 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002153 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerc9c432e2021-05-17 20:54:49 +00002156 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002157 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2159 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002160 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002161 mTelephonySharedPreferences =
2162 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002163 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002164 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002165 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002166 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002167
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 publish();
2169 }
2170
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002171 private Phone getDefaultPhone() {
2172 Phone thePhone = getPhone(getDefaultSubscription());
2173 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2174 }
2175
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 private void publish() {
2177 if (DBG) log("publish: " + this);
2178
Peter Wangc035ce42020-01-08 21:00:22 -08002179 TelephonyFrameworkInitializer
2180 .getTelephonyServiceManager()
2181 .getTelephonyServiceRegisterer()
2182 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
2184
Stuart Scott584921c2015-01-15 17:10:34 -08002185 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002186 if (request.phone != null) {
2187 return request.phone;
2188 } else {
2189 return getPhoneFromSubId(request.subId);
2190 }
2191 }
2192
2193 private Phone getPhoneFromSubId(int subId) {
2194 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2195 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002196 }
2197
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002198 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2199 Phone phone = getPhoneFromRequest(request);
2200 return phone == null ? null :
2201 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2202 }
2203
Wink Saville36469e72014-06-11 15:17:00 -07002204 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002205 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002206 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002209 private void sendEraseModemConfig(Phone phone) {
2210 if (phone != null) {
2211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2212 mApp, phone.getSubId(), "eraseModemConfig");
2213 final long identity = Binder.clearCallingIdentity();
2214 try {
2215 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2216 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2217 } finally {
2218 Binder.restoreCallingIdentity(identity);
2219 }
2220 }
2221 }
2222
Peter Wang050bb052020-01-13 23:33:09 -08002223 private boolean isImsAvailableOnDevice() {
2224 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2225 if (pm == null) {
2226 // For some reason package manger is not available.. This will fail internally anyway,
2227 // so do not throw error and allow.
2228 return true;
2229 }
2230 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2231 }
2232
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002234 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002235 }
2236
Wink Savilleb564aae2014-10-23 10:18:09 -07002237 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 if (DBG) log("dial: " + number);
2239 // No permission check needed here: This is just a wrapper around the
2240 // ACTION_DIAL intent, which is available to any app since it puts up
2241 // the UI before it does anything.
2242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243 final long identity = Binder.clearCallingIdentity();
2244 try {
2245 String url = createTelUrl(number);
2246 if (url == null) {
2247 return;
2248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250 // PENDING: should we just silently fail if phone is offhook or ringing?
2251 PhoneConstants.State state = mCM.getState(subId);
2252 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2253 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2254 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2255 mApp.startActivity(intent);
2256 }
2257 } finally {
2258 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260 }
2261
2262 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002263 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002264 }
2265
Wink Savilleb564aae2014-10-23 10:18:09 -07002266 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 if (DBG) log("call: " + number);
2268
2269 // This is just a wrapper around the ACTION_CALL intent, but we still
2270 // need to do a permission check since we're calling startActivity()
2271 // from the context of the phone app.
2272 enforceCallPermission();
2273
Jordan Liu1617b712019-07-10 15:06:26 -07002274 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 != AppOpsManager.MODE_ALLOWED) {
2276 return;
2277 }
2278
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279 final long identity = Binder.clearCallingIdentity();
2280 try {
2281 String url = createTelUrl(number);
2282 if (url == null) {
2283 return;
2284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286 boolean isValid = false;
2287 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2288 if (slist != null) {
2289 for (SubscriptionInfo subInfoRecord : slist) {
2290 if (subInfoRecord.getSubscriptionId() == subId) {
2291 isValid = true;
2292 break;
2293 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002294 }
Wink Saville08874612014-08-31 19:19:58 -07002295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 if (!isValid) {
2297 return;
2298 }
Wink Saville08874612014-08-31 19:19:58 -07002299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002300 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2301 intent.putExtra(SUBSCRIPTION_KEY, subId);
2302 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2303 mApp.startActivity(intent);
2304 } finally {
2305 Binder.restoreCallingIdentity(identity);
2306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 }
2308
Wink Savilleb564aae2014-10-23 10:18:09 -07002309 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002310 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002311 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2312 }
2313
Wink Savilleb564aae2014-10-23 10:18:09 -07002314 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002315 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002316 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2317 }
2318
Wink Savilleb564aae2014-10-23 10:18:09 -07002319 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002321
2322 final long identity = Binder.clearCallingIdentity();
2323 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002324 Phone phone = getPhone(subId);
2325 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326 checkSimPin.start();
2327 return checkSimPin.unlockSim(null, pin);
2328 } finally {
2329 Binder.restoreCallingIdentity(identity);
2330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 }
2332
Wink Savilleb564aae2014-10-23 10:18:09 -07002333 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002335
2336 final long identity = Binder.clearCallingIdentity();
2337 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002338 Phone phone = getPhone(subId);
2339 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340 checkSimPuk.start();
2341 return checkSimPuk.unlockSim(puk, pin);
2342 } finally {
2343 Binder.restoreCallingIdentity(identity);
2344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 }
2346
2347 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002348 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 * a synchronous one.
2350 */
2351 private static class UnlockSim extends Thread {
2352
2353 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002354 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355
2356 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002357 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2358 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359
2360 // For replies from SimCard interface
2361 private Handler mHandler;
2362
2363 // For async handler to identify request type
2364 private static final int SUPPLY_PIN_COMPLETE = 100;
2365
Michele Berionned9fbae52020-11-13 02:36:59 +00002366 UnlockSim(int phoneId, IccCard simCard) {
2367 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 mSimCard = simCard;
2369 }
2370
2371 @Override
2372 public void run() {
2373 Looper.prepare();
2374 synchronized (UnlockSim.this) {
2375 mHandler = new Handler() {
2376 @Override
2377 public void handleMessage(Message msg) {
2378 AsyncResult ar = (AsyncResult) msg.obj;
2379 switch (msg.what) {
2380 case SUPPLY_PIN_COMPLETE:
2381 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2382 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002383 mRetryCount = msg.arg1;
2384 if (ar.exception != null) {
2385 if (ar.exception instanceof CommandException &&
2386 ((CommandException)(ar.exception)).getCommandError()
2387 == CommandException.Error.PASSWORD_INCORRECT) {
2388 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002389 } //When UiccCardApp dispose,handle message and return exception
2390 else if (ar.exception instanceof CommandException &&
2391 ((CommandException) (ar.exception)).getCommandError()
2392 == CommandException.Error.ABORTED) {
2393 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002394 } else {
2395 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2396 }
2397 } else {
2398 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 mDone = true;
2401 UnlockSim.this.notifyAll();
2402 }
2403 break;
2404 }
2405 }
2406 };
2407 UnlockSim.this.notifyAll();
2408 }
2409 Looper.loop();
2410 }
2411
2412 /*
2413 * Use PIN or PUK to unlock SIM card
2414 *
2415 * If PUK is null, unlock SIM card with PIN
2416 *
2417 * If PUK is not null, unlock SIM card with PUK and set PIN code
2418 */
Wink Saville9de0f752013-10-22 19:04:03 -07002419 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420
2421 while (mHandler == null) {
2422 try {
2423 wait();
2424 } catch (InterruptedException e) {
2425 Thread.currentThread().interrupt();
2426 }
2427 }
2428 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2429
2430 if (puk == null) {
2431 mSimCard.supplyPin(pin, callback);
2432 } else {
2433 mSimCard.supplyPuk(puk, pin, callback);
2434 }
2435
2436 while (!mDone) {
2437 try {
2438 Log.d(LOG_TAG, "wait for done");
2439 wait();
2440 } catch (InterruptedException e) {
2441 // Restore the interrupted status
2442 Thread.currentThread().interrupt();
2443 }
2444 }
2445 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002446 int[] resultArray = new int[2];
2447 resultArray[0] = mResult;
2448 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002449
2450 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Grace Jia59437e82021-09-21 15:47:32 -07002451 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
2452 pinStorage.storePin(pin, mPhoneId, pinStorage.getIccid(mPhoneId));
Michele Berionned9fbae52020-11-13 02:36:59 +00002453 }
2454
Wink Saville9de0f752013-10-22 19:04:03 -07002455 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456 }
2457 }
2458
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002459 /**
2460 * This method has been removed due to privacy and stability concerns.
2461 */
2462 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002464 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2465 return;
Wink Saville36469e72014-06-11 15:17:00 -07002466 }
2467
Nathan Harold1f889d82020-06-04 17:05:26 -07002468 @Override
2469 public void updateServiceLocationWithPackageName(String callingPackage) {
2470 mApp.getSystemService(AppOpsManager.class)
2471 .checkPackage(Binder.getCallingUid(), callingPackage);
2472
Nathan Haroldf096d982020-11-18 17:18:06 -08002473 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002474 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2475 // Callers targeting S have no business invoking this method.
2476 return;
2477 }
2478
2479 LocationAccessPolicy.LocationPermissionResult locationResult =
2480 LocationAccessPolicy.checkLocationPermission(mApp,
2481 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2482 .setCallingPackage(callingPackage)
2483 .setCallingFeatureId(null)
2484 .setCallingPid(Binder.getCallingPid())
2485 .setCallingUid(Binder.getCallingUid())
2486 .setMethod("updateServiceLocation")
2487 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2488 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2489 .build());
2490 // Apps that lack location permission have no business calling this method;
2491 // however, because no permission was declared in the public API, denials must
2492 // all be "soft".
2493 switch (locationResult) {
2494 case DENIED_HARD: /* fall through */
2495 case DENIED_SOFT:
2496 return;
2497 }
2498
2499 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500 final long identity = Binder.clearCallingIdentity();
2501 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002502 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002504 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 }
2506 } finally {
2507 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002509 }
2510
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002511 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002512 @Override
2513 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002514 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002515 }
2516
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002517
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002518 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002519 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2520 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2521 callingFeatureId);
2522 }
2523
2524 @Deprecated
2525 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002526 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002527 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2528 }
2529
2530 @Override
2531 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2532 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002533 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002534 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002535 return false;
2536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002537
2538 final long identity = Binder.clearCallingIdentity();
2539 try {
2540 return isRadioOnForSubscriber(subId);
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
2543 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002544 }
2545
2546 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547 final long identity = Binder.clearCallingIdentity();
2548 try {
2549 final Phone phone = getPhone(subId);
2550 if (phone != null) {
2551 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2552 } else {
2553 return false;
2554 }
2555 } finally {
2556 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002557 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 }
2559
2560 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002561 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 }
Wink Saville36469e72014-06-11 15:17:00 -07002563
Wink Savilleb564aae2014-10-23 10:18:09 -07002564 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566
2567 final long identity = Binder.clearCallingIdentity();
2568 try {
2569 final Phone phone = getPhone(subId);
2570 if (phone != null) {
2571 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2572 }
2573 } finally {
2574 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 }
Wink Saville36469e72014-06-11 15:17:00 -07002576 }
2577
2578 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002579 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002580 }
2581
Wink Savilleb564aae2014-10-23 10:18:09 -07002582 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002583 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002584
2585 final long identity = Binder.clearCallingIdentity();
2586 try {
2587 final Phone phone = getPhone(subId);
2588 if (phone == null) {
2589 return false;
2590 }
2591 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2592 toggleRadioOnOffForSubscriber(subId);
2593 }
2594 return true;
2595 } finally {
2596 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002598 }
Wink Saville36469e72014-06-11 15:17:00 -07002599
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002600 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002601 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002602 /*
2603 * If any of the Radios are available, it will need to be
2604 * shutdown. So return true if any Radio is available.
2605 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2609 Phone phone = PhoneFactory.getPhone(i);
2610 if (phone != null && phone.isRadioAvailable()) return true;
2611 }
2612 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2613 return false;
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002616 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002617 }
2618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002620 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 enforceModifyPermission();
2622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2626 logv("Shutting down Phone " + i);
2627 shutdownRadioUsingPhoneId(i);
2628 }
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002631 }
2632 }
2633
2634 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002635 Phone phone = PhoneFactory.getPhone(phoneId);
2636 if (phone != null && phone.isRadioAvailable()) {
2637 phone.shutdownRadio();
2638 }
2639 }
2640
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002642 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643
2644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2647 if (defaultPhone != null) {
2648 defaultPhone.setRadioPower(turnOn);
2649 return true;
2650 } else {
2651 loge("There's no default phone.");
2652 return false;
2653 }
2654 } finally {
2655 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002656 }
Wink Saville36469e72014-06-11 15:17:00 -07002657 }
2658
Wink Savilleb564aae2014-10-23 10:18:09 -07002659 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661
2662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 if (phone != null) {
2666 phone.setRadioPower(turnOn);
2667 return true;
2668 } 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
Wink Saville36469e72014-06-11 15:17:00 -07002676 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 public boolean enableDataConnectivity() {
2679 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680
2681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 int subId = mSubscriptionController.getDefaultDataSubId();
2684 final Phone phone = getPhone(subId);
2685 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002686 phone.getDataEnabledSettings().setDataEnabled(
2687 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688 return true;
2689 } else {
2690 return false;
2691 }
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
2696
Wink Saville36469e72014-06-11 15:17:00 -07002697 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 public boolean disableDataConnectivity() {
2700 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701
2702 final long identity = Binder.clearCallingIdentity();
2703 try {
2704 int subId = mSubscriptionController.getDefaultDataSubId();
2705 final Phone phone = getPhone(subId);
2706 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002707 phone.getDataEnabledSettings().setDataEnabled(
2708 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709 return true;
2710 } else {
2711 return false;
2712 }
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002715 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716 }
2717
Sanket Padawe356d7632015-06-22 14:03:32 -07002718 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002719 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 final Phone phone = getPhone(subId);
2723 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002724 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 } else {
2726 return false;
2727 }
2728 } finally {
2729 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002730 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 }
2732
2733 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002734 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002735 }
2736
pkanwarae03a6b2016-11-06 20:37:09 -08002737 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 enforceCallPermission();
2739
2740 final long identity = Binder.clearCallingIdentity();
2741 try {
2742 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2743 return;
2744 }
2745 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2746 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2747 } finally {
2748 Binder.restoreCallingIdentity(identity);
2749 }
pkanwar32d516d2016-10-14 19:37:38 -07002750 };
2751
Wink Savilleb564aae2014-10-23 10:18:09 -07002752 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002753 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754
2755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2758 return false;
2759 }
2760 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2761 } finally {
2762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002764 }
2765
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002767 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002768 }
2769
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002770 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 Phone phone = PhoneFactory.getPhone(slotIndex);
2774 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2775 PhoneConstantConversions.convertCallState(phone.getState());
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
2778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780
Sanket Padawe356d7632015-06-22 14:03:32 -07002781 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002782 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002783 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2784 }
2785
2786 @Override
2787 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 final long identity = Binder.clearCallingIdentity();
2789 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002790 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 if (phone != null) {
2792 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2793 } else {
2794 return PhoneConstantConversions.convertDataState(
2795 PhoneConstants.DataState.DISCONNECTED);
2796 }
2797 } finally {
2798 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002799 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002800 }
2801
Sanket Padawe356d7632015-06-22 14:03:32 -07002802 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002803 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002804 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2805 }
2806
2807 @Override
2808 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809 final long identity = Binder.clearCallingIdentity();
2810 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002811 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812 if (phone != null) {
2813 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2814 } else {
2815 return TelephonyManager.DATA_ACTIVITY_NONE;
2816 }
2817 } finally {
2818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 }
2821
2822 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002823 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002824 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002825 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002826
2827 LocationAccessPolicy.LocationPermissionResult locationResult =
2828 LocationAccessPolicy.checkLocationPermission(mApp,
2829 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2830 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002831 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002832 .setCallingPid(Binder.getCallingPid())
2833 .setCallingUid(Binder.getCallingUid())
2834 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002835 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002836 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2837 .build());
2838 switch (locationResult) {
2839 case DENIED_HARD:
2840 throw new SecurityException("Not allowed to access cell location");
2841 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002842 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2843 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 }
2845
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002846 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847 final long identity = Binder.clearCallingIdentity();
2848 try {
2849 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002850 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002851 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 } finally {
2853 Binder.restoreCallingIdentity(identity);
2854 }
Svetoslav64fad262015-04-14 14:35:21 -07002855 }
2856
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 @Override
Jack Yu01425032020-02-22 19:38:58 -08002858 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002859 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2860 // registered cell info, so return a NULL country instead.
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002863 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2864 // Get default phone in this case.
2865 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2866 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002867 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002868 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002869 if (phone == null) return "";
2870 ServiceStateTracker sst = phone.getServiceStateTracker();
2871 if (sst == null) return "";
2872 LocaleTracker lt = sst.getLocaleTracker();
2873 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002874 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002875 } finally {
2876 Binder.restoreCallingIdentity(identity);
2877 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002878 }
2879
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002880 /**
2881 * This method was removed due to potential issues caused by performing partial
2882 * updates of service state, and lack of a credible use case.
2883 *
2884 * This has the ability to break the telephony implementation by disabling notification of
2885 * changes in device connectivity. DO NOT USE THIS!
2886 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002887 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 public void enableLocationUpdates() {
2889 mApp.enforceCallingOrSelfPermission(
2890 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002891 }
2892
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002893 /**
2894 * This method was removed due to potential issues caused by performing partial
2895 * updates of service state, and lack of a credible use case.
2896 *
2897 * This has the ability to break the telephony implementation by disabling notification of
2898 * changes in device connectivity. DO NOT USE THIS!
2899 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002900 @Override
2901 public void disableLocationUpdates() {
2902 mApp.enforceCallingOrSelfPermission(
2903 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002904 }
2905
2906 @Override
2907 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002908 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2909 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002910 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002911 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2912 throw new SecurityException(
2913 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2914 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002915
Jordan Liu1617b712019-07-10 15:06:26 -07002916 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002917 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2918 return null;
2919 }
Svetoslav64fad262015-04-14 14:35:21 -07002920
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002921 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002922
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002923 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002924 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002925
Nathan Haroldf180aac2018-06-01 18:43:55 -07002926 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2927 for (CellInfo ci : info) {
2928 if (ci instanceof CellInfoGsm) {
2929 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2930 } else if (ci instanceof CellInfoWcdma) {
2931 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002934 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002935 }
2936
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002937 private List<CellInfo> getCachedCellInfo() {
2938 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2939 for (Phone phone : PhoneFactory.getPhones()) {
2940 List<CellInfo> info = phone.getAllCellInfo();
2941 if (info != null) cellInfos.addAll(info);
2942 }
2943 return cellInfos;
2944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945
2946 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002947 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002948 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002949 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002950
2951 LocationAccessPolicy.LocationPermissionResult locationResult =
2952 LocationAccessPolicy.checkLocationPermission(mApp,
2953 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2954 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002955 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002956 .setCallingPid(Binder.getCallingPid())
2957 .setCallingUid(Binder.getCallingUid())
2958 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002959 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002960 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2961 .build());
2962 switch (locationResult) {
2963 case DENIED_HARD:
2964 throw new SecurityException("Not allowed to access cell info");
2965 case DENIED_SOFT:
2966 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002967 }
2968
Nathan Haroldf096d982020-11-18 17:18:06 -08002969 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002970 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2971 return getCachedCellInfo();
2972 }
2973
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002974 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2979 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002980 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002981 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982 if (info != null) cellInfos.addAll(info);
2983 }
2984 return cellInfos;
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002987 }
2988 }
2989
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002990 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002991 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2992 String callingFeatureId) {
2993 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2994 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002995 }
2996
2997 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002998 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2999 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003000 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003001 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003002 }
3003
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003004 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3005 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003006 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003007 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003008
3009 LocationAccessPolicy.LocationPermissionResult locationResult =
3010 LocationAccessPolicy.checkLocationPermission(mApp,
3011 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3012 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003013 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003014 .setCallingPid(Binder.getCallingPid())
3015 .setCallingUid(Binder.getCallingUid())
3016 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07003017 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3018 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003019 .build());
3020 switch (locationResult) {
3021 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003022 if (TelephonyPermissions
3023 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07003024 // Safetynet logging for b/154934934
3025 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3026 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003027 throw new SecurityException("Not allowed to access cell info");
3028 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003029 if (TelephonyPermissions
3030 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07003031 // Safetynet logging for b/154934934
3032 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3033 }
Nathan Harold5320c422019-05-09 10:26:08 -07003034 try {
3035 cb.onCellInfo(new ArrayList<CellInfo>());
3036 } catch (RemoteException re) {
3037 // Drop without consequences
3038 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003039 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003040 }
3041
Nathan Harolda939a962019-05-09 10:13:47 -07003042
3043 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003044 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3045
3046 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3047 }
3048
3049 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003050 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003051 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003052 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003053
3054 final long identity = Binder.clearCallingIdentity();
3055 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003056 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003057 } finally {
3058 Binder.restoreCallingIdentity(identity);
3059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003060 }
3061
Shishir Agrawala9f32182016-04-12 12:00:16 -07003062 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003063 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003064 Phone phone = PhoneFactory.getPhone(slotIndex);
3065 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003066 return null;
3067 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003068 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003069 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003070 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003071 return null;
3072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003073
3074 final long identity = Binder.clearCallingIdentity();
3075 try {
3076 return phone.getImei();
3077 } finally {
3078 Binder.restoreCallingIdentity(identity);
3079 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003080 }
3081
3082 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003083 public String getTypeAllocationCodeForSlot(int slotIndex) {
3084 Phone phone = PhoneFactory.getPhone(slotIndex);
3085 String tac = null;
3086 if (phone != null) {
3087 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003088 try {
3089 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3090 } catch (IndexOutOfBoundsException e) {
3091 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3092 return null;
3093 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003094 }
3095 return tac;
3096 }
3097
3098 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003099 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003100 Phone phone = PhoneFactory.getPhone(slotIndex);
3101 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003102 return null;
3103 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003104
Jeff Davidson913390f2018-02-23 17:11:49 -08003105 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003106 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003107 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003108 return null;
3109 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110
3111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 return phone.getMeid();
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
Jack Yu2af8d712017-03-15 17:14:14 -07003117 }
3118
3119 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003120 public String getManufacturerCodeForSlot(int slotIndex) {
3121 Phone phone = PhoneFactory.getPhone(slotIndex);
3122 String manufacturerCode = null;
3123 if (phone != null) {
3124 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003125 try {
3126 manufacturerCode =
3127 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3128 } catch (IndexOutOfBoundsException e) {
3129 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3130 return null;
3131 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003132 }
3133 return manufacturerCode;
3134 }
3135
3136 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003137 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3138 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003139 Phone phone = PhoneFactory.getPhone(slotIndex);
3140 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003141 return null;
3142 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003143 int subId = phone.getSubId();
3144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003145 mApp, subId, callingPackage, callingFeatureId,
3146 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003147 return null;
3148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149
3150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 return phone.getDeviceSvn();
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003156 }
3157
fionaxu43304da2017-11-27 22:51:16 -08003158 @Override
3159 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003160 final long identity = Binder.clearCallingIdentity();
3161 try {
3162 final Phone phone = getPhone(subId);
3163 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3164 } finally {
3165 Binder.restoreCallingIdentity(identity);
3166 }
fionaxu43304da2017-11-27 22:51:16 -08003167 }
3168
3169 @Override
3170 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 final Phone phone = getPhone(subId);
3174 return phone == null ? null : phone.getCarrierName();
3175 } finally {
3176 Binder.restoreCallingIdentity(identity);
3177 }
fionaxu43304da2017-11-27 22:51:16 -08003178 }
3179
calvinpanffe225e2018-11-01 19:43:06 +08003180 @Override
chen xu0026ca62019-03-06 15:28:50 -08003181 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 final Phone phone = getPhone(subId);
3185 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003186 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003187 } finally {
3188 Binder.restoreCallingIdentity(identity);
3189 }
3190 }
3191
3192 @Override
chen xu0026ca62019-03-06 15:28:50 -08003193 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003197 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
3201 }
3202
chen xu651eec72018-11-11 19:03:44 -08003203 @Override
chen xu864e11c2018-12-06 22:10:03 -08003204 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3205 if (!isSubscriptionMccMnc) {
3206 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3207 }
chen xu651eec72018-11-11 19:03:44 -08003208 final Phone phone = PhoneFactory.getPhone(slotIndex);
3209 if (phone == null) {
3210 return TelephonyManager.UNKNOWN_CARRIER_ID;
3211 }
3212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
3218 }
3219
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003220 //
3221 // Internal helper methods.
3222 //
3223
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003224 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003225 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3226 *
3227 * @throws SecurityException if the caller does not have the required permission
3228 */
3229 private void enforceModifyPermission() {
3230 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3231 }
3232
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003233 /**
3234 * Make sure the caller is system.
3235 *
3236 * @throws SecurityException if the caller is not system.
3237 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003238 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003239 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3240 throw new SecurityException("Caller must be system");
3241 }
3242 }
3243
Shuo Qianf2b2df42019-11-13 17:43:31 -08003244 private void enforceActiveEmergencySessionPermission() {
3245 mApp.enforceCallingOrSelfPermission(
3246 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3247 }
3248
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003249 /**
3250 * Make sure the caller has the CALL_PHONE permission.
3251 *
3252 * @throws SecurityException if the caller does not have the required permission
3253 */
3254 private void enforceCallPermission() {
3255 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3256 }
3257
paulhu423b5f22019-08-23 19:17:33 +08003258 private void enforceSettingsPermission() {
3259 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003260 }
3261
Michele Berionned9fbae52020-11-13 02:36:59 +00003262 private void enforceRebootPermission() {
3263 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3264 }
3265
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003266 private String createTelUrl(String number) {
3267 if (TextUtils.isEmpty(number)) {
3268 return null;
3269 }
3270
Jake Hambye994d462014-02-03 13:10:13 -08003271 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 }
3273
Ihab Awadf9e92732013-12-05 18:02:52 -08003274 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3276 }
3277
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003278 private static void logv(String msg) {
3279 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3280 }
3281
Ihab Awadf9e92732013-12-05 18:02:52 -08003282 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3284 }
3285
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003286 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003287 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003288 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003289 }
3290
Sanket Padawe356d7632015-06-22 14:03:32 -07003291 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003292 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 final Phone phone = PhoneFactory.getPhone(slotIndex);
3296 if (phone == null) {
3297 return PhoneConstants.PHONE_TYPE_NONE;
3298 } else {
3299 return phone.getPhoneType();
3300 }
3301 } finally {
3302 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003304 }
3305
3306 /**
3307 * Returns the CDMA ERI icon index to display
3308 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003309 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003310 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3311 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3312 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003313 }
3314
Sanket Padawe356d7632015-06-22 14:03:32 -07003315 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003316 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3317 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003318 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003319 mApp, subId, callingPackage, callingFeatureId,
3320 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003321 return -1;
3322 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003323
3324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 final Phone phone = getPhone(subId);
3327 if (phone != null) {
3328 return phone.getCdmaEriIconIndex();
3329 } else {
3330 return -1;
3331 }
3332 } finally {
3333 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003334 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003335 }
3336
3337 /**
3338 * Returns the CDMA ERI icon mode,
3339 * 0 - ON
3340 * 1 - FLASHING
3341 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003342 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003343 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3344 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3345 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003346 }
3347
Sanket Padawe356d7632015-06-22 14:03:32 -07003348 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003349 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3350 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003351 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003352 mApp, subId, callingPackage, callingFeatureId,
3353 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003354 return -1;
3355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 final Phone phone = getPhone(subId);
3360 if (phone != null) {
3361 return phone.getCdmaEriIconMode();
3362 } else {
3363 return -1;
3364 }
3365 } finally {
3366 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003368 }
3369
3370 /**
3371 * Returns the CDMA ERI text,
3372 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003373 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003374 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3375 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3376 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003377 }
3378
Sanket Padawe356d7632015-06-22 14:03:32 -07003379 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003380 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3381 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003382 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003383 mApp, subId, callingPackage, callingFeatureId,
3384 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003385 return null;
3386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003387
3388 final long identity = Binder.clearCallingIdentity();
3389 try {
3390 final Phone phone = getPhone(subId);
3391 if (phone != null) {
3392 return phone.getCdmaEriText();
3393 } else {
3394 return null;
3395 }
3396 } finally {
3397 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003399 }
3400
3401 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003402 * Returns the CDMA MDN.
3403 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003404 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003405 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3407 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003412 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413 return phone.getLine1Number();
3414 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003415 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003416 return null;
3417 }
3418 } finally {
3419 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003420 }
3421 }
3422
3423 /**
3424 * Returns the CDMA MIN.
3425 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003426 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003427 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3429 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003430
3431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 final Phone phone = getPhone(subId);
3434 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3435 return phone.getCdmaMin();
3436 } else {
3437 return null;
3438 }
3439 } finally {
3440 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003441 }
3442 }
3443
Hall Liud892bec2018-11-30 14:51:45 -08003444 @Override
3445 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3446 INumberVerificationCallback callback, String callingPackage) {
3447 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3448 != PERMISSION_GRANTED) {
3449 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3450 }
3451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3452
3453 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3454 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003455 throw new SecurityException("Calling package must be configured in the device config: "
3456 + "calling package: " + callingPackage
3457 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003458 }
3459
3460 if (range == null) {
3461 throw new NullPointerException("Range must be non-null");
3462 }
3463
3464 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003465 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003466
3467 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3468 }
3469
Junda Liuca05d5d2014-08-14 22:36:34 -07003470 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003471 * Returns true if CDMA provisioning needs to run.
3472 */
3473 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003474 final long identity = Binder.clearCallingIdentity();
3475 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003476 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003477 } finally {
3478 Binder.restoreCallingIdentity(identity);
3479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003480 }
3481
3482 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003483 * Sets the voice mail number of a given subId.
3484 */
3485 @Override
3486 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003487 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3488 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003489
3490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3493 new Pair<String, String>(alphaTag, number), new Integer(subId));
3494 return success;
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
3497 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003498 }
3499
Ta-wei Yen87c49842016-05-13 21:19:52 -07003500 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003501 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003503 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3504 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003505 if (!TextUtils.equals(callingPackage, systemDialer)) {
3506 throw new SecurityException("caller must be system dialer");
3507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003508
3509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3512 if (phoneAccountHandle == null) {
3513 return null;
3514 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003515 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003516 } finally {
3517 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003518 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003519 }
3520
3521 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003522 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3523 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003524 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003526 mApp, subId, callingPackage, callingFeatureId,
3527 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003528 return null;
3529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003531 final long identity = Binder.clearCallingIdentity();
3532 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003533 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003534 } finally {
3535 Binder.restoreCallingIdentity(identity);
3536 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003537 }
3538
3539 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003540 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3541 VisualVoicemailSmsFilterSettings settings) {
3542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003547 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003551 }
3552
3553 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003554 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3555 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003556
3557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003560 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003561 } finally {
3562 Binder.restoreCallingIdentity(identity);
3563 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003564 }
3565
3566 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003567 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3568 String callingPackage, int subId) {
3569 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003570
3571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003578 }
3579
3580 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003581 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583
3584 final long identity = Binder.clearCallingIdentity();
3585 try {
3586 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003587 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003588 } finally {
3589 Binder.restoreCallingIdentity(identity);
3590 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003591 }
3592
3593 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003594 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3595 String callingAttributionTag, int subId, String number, int port, String text,
3596 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003597 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003598 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003599 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003600 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003601 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3602 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003603 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003604
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003605 /**
fionaxu0152e512016-11-14 13:36:14 -08003606 * Sets the voice activation state of a given subId.
3607 */
3608 @Override
3609 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3611 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003612
3613 final long identity = Binder.clearCallingIdentity();
3614 try {
3615 final Phone phone = getPhone(subId);
3616 if (phone != null) {
3617 phone.setVoiceActivationState(activationState);
3618 } else {
3619 loge("setVoiceActivationState fails with invalid subId: " + subId);
3620 }
3621 } finally {
3622 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003623 }
3624 }
3625
3626 /**
3627 * Sets the data activation state of a given subId.
3628 */
3629 @Override
3630 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3632 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633
3634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 final Phone phone = getPhone(subId);
3637 if (phone != null) {
3638 phone.setDataActivationState(activationState);
3639 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003640 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003641 }
3642 } finally {
3643 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003644 }
3645 }
3646
3647 /**
3648 * Returns the voice activation state of a given subId.
3649 */
3650 @Override
3651 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003652 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653
fionaxu0152e512016-11-14 13:36:14 -08003654 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 if (phone != null) {
3658 return phone.getVoiceActivationState();
3659 } else {
3660 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3661 }
3662 } finally {
3663 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003664 }
3665 }
3666
3667 /**
3668 * Returns the data activation state of a given subId.
3669 */
3670 @Override
3671 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003672 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673
fionaxu0152e512016-11-14 13:36:14 -08003674 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675 final long identity = Binder.clearCallingIdentity();
3676 try {
3677 if (phone != null) {
3678 return phone.getDataActivationState();
3679 } else {
3680 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3681 }
3682 } finally {
3683 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003684 }
3685 }
3686
3687 /**
Wink Saville36469e72014-06-11 15:17:00 -07003688 * Returns the unread count of voicemails for a subId
3689 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003690 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003691 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3692 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003694 mApp, subId, callingPackage, callingFeatureId,
3695 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003696 return 0;
3697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 final Phone phone = getPhone(subId);
3701 if (phone != null) {
3702 return phone.getVoiceMessageCount();
3703 } else {
3704 return 0;
3705 }
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003708 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003709 }
3710
3711 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003712 * returns true, if the device is in a state where both voice and data
3713 * are supported simultaneously. This can change based on location or network condition.
3714 */
3715 @Override
3716 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 final Phone phone = getPhone(subId);
3720 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3721 } finally {
3722 Binder.restoreCallingIdentity(identity);
3723 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003724 }
3725
3726 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003727 * Send the dialer code if called from the current default dialer or the caller has
3728 * carrier privilege.
3729 * @param inputCode The dialer code to send
3730 */
3731 @Override
3732 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003733 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003735 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3736 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003737 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003738 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003739 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003740 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741
3742 final long identity = Binder.clearCallingIdentity();
3743 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003744 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745 } finally {
3746 Binder.restoreCallingIdentity(identity);
3747 }
fionaxu235cc5e2017-03-06 22:25:57 -08003748 }
3749
Pengquan Menga1bb6272018-09-06 09:59:22 -07003750 @Override
3751 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003752 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07003753 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003754 mApp, subId, "getNetworkSelectionMode");
3755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 if (!isActiveSubscription(subId)) {
3758 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3759 }
3760 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3761 } finally {
3762 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003763 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003764 }
3765
Brad Ebinger35c841c2018-10-01 10:40:55 -07003766 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003767 public boolean isInEmergencySmsMode() {
3768 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3769 final long identity = Binder.clearCallingIdentity();
3770 try {
3771 for (Phone phone : PhoneFactory.getPhones()) {
3772 if (phone.isInEmergencySmsMode()) {
3773 return true;
3774 }
3775 }
3776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
3779 return false;
3780 }
3781
shilu366312e2019-12-17 09:28:10 -08003782 /**
3783 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3784 * @param subId The subscription to use to check the configuration.
3785 * @param c The callback that will be used to send the result.
3786 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003787 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003788 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3789 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003790 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003791 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003792
Brad Ebinger77b832e2019-10-17 17:03:22 -07003793 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3794 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3795 "IMS not available on device.");
3796 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003797 final long token = Binder.clearCallingIdentity();
3798 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003799 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003800 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003801 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003802 } catch (ImsException e) {
3803 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003804 } finally {
3805 Binder.restoreCallingIdentity(token);
3806 }
3807 }
3808
shilu366312e2019-12-17 09:28:10 -08003809 /**
3810 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3811 * @param subId The subscription to use to check the configuration.
3812 * @param c The callback that will be used to send the result.
3813 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003814 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003815 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003816 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003817 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003818 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3819 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3820 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003821 final long token = Binder.clearCallingIdentity();
3822 try {
3823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3824 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3825 .removeRegistrationCallbackForSubscription(c, subId);
3826 } catch (ImsException e) {
3827 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3828 + "is inactive, ignoring unregister.");
3829 // If the subscription is no longer active, just return, since the callback
3830 // will already have been removed internally.
3831 } finally {
3832 Binder.restoreCallingIdentity(token);
3833 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003834 }
3835
Brad Ebinger774ba362019-10-22 17:36:18 -07003836 /**
3837 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3838 */
3839 @Override
3840 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3841 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3842 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3843 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3844 "IMS not available on device.");
3845 }
3846 final long token = Binder.clearCallingIdentity();
3847 try {
3848 Phone phone = getPhone(subId);
3849 if (phone == null) {
3850 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3851 + subId + "'");
3852 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3853 }
3854 phone.getImsRegistrationState(regState -> {
3855 try {
3856 consumer.accept((regState == null)
3857 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3858 } catch (RemoteException e) {
3859 // Ignore if the remote process is no longer available to call back.
3860 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3861 }
3862 });
3863 } finally {
3864 Binder.restoreCallingIdentity(token);
3865 }
3866 }
3867
3868 /**
3869 * Get the transport type for the IMS service registration state.
3870 */
3871 @Override
3872 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003873 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003874 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003875 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3876 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3877 "IMS not available on device.");
3878 }
3879 final long token = Binder.clearCallingIdentity();
3880 try {
3881 Phone phone = getPhone(subId);
3882 if (phone == null) {
3883 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3884 + subId + "'");
3885 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3886 }
3887 phone.getImsRegistrationTech(regTech -> {
3888 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3889 int regTechConverted = (regTech == null)
3890 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3891 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3892 regTechConverted);
3893 try {
3894 consumer.accept(regTechConverted);
3895 } catch (RemoteException e) {
3896 // Ignore if the remote process is no longer available to call back.
3897 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3898 }
3899 });
3900 } finally {
3901 Binder.restoreCallingIdentity(token);
3902 }
3903 }
3904
shilu366312e2019-12-17 09:28:10 -08003905 /**
3906 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3907 * @param subId The subscription to use to check the configuration.
3908 * @param c The callback that will be used to send the result.
3909 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003911 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3912 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003913 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003914 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003915 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3916 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3917 "IMS not available on device.");
3918 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3920 final long token = Binder.clearCallingIdentity();
3921 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003922 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003923 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003924 } catch (ImsException e) {
3925 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003926 } finally {
3927 Binder.restoreCallingIdentity(token);
3928 }
3929 }
3930
shilu366312e2019-12-17 09:28:10 -08003931 /**
3932 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3933 * @param subId The subscription to use to check the configuration.
3934 * @param c The callback that will be used to send the result.
3935 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003937 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003938 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003939 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003940 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3941 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3942 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003943
3944 final long token = Binder.clearCallingIdentity();
3945 try {
3946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3947 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003948 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003949 } catch (ImsException e) {
3950 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3951 + "is inactive, ignoring unregister.");
3952 // If the subscription is no longer active, just return, since the callback
3953 // will already have been removed internally.
3954 } finally {
3955 Binder.restoreCallingIdentity(token);
3956 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 }
3958
3959 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003960 public boolean isCapable(int subId, int capability, int regTech) {
3961 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3963 final long token = Binder.clearCallingIdentity();
3964 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003965 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003967 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3969 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003970 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003971 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3972 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 } finally {
3974 Binder.restoreCallingIdentity(token);
3975 }
3976 }
3977
3978 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003979 public boolean isAvailable(int subId, int capability, int regTech) {
3980 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 final long token = Binder.clearCallingIdentity();
3982 try {
3983 Phone phone = getPhone(subId);
3984 if (phone == null) return false;
3985 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003986 } catch (com.android.ims.ImsException e) {
3987 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3988 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 } finally {
3990 Binder.restoreCallingIdentity(token);
3991 }
3992 }
3993
Brad Ebinger77b832e2019-10-17 17:03:22 -07003994 /**
3995 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3996 * subscription.
3997 * @param subId The subscription to use to check the configuration.
3998 * @param callback The callback that will be used to send the result.
3999 * @param capability The MmTelFeature capability that will be used to send the result.
4000 * @param transportType The transport type of the MmTelFeature capability.
4001 */
4002 @Override
4003 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4004 int transportType) {
4005 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4006 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4007 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4008 "IMS not available on device.");
4009 }
4010 final long token = Binder.clearCallingIdentity();
4011 try {
4012 int slotId = getSlotIndex(subId);
4013 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4014 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4015 + subId + "'");
4016 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4017 }
4018 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4019 transportType, aBoolean -> {
4020 try {
4021 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4022 } catch (RemoteException e) {
4023 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4024 + "running. Ignore");
4025 }
4026 });
4027 } finally {
4028 Binder.restoreCallingIdentity(token);
4029 }
4030 }
4031
shilu366312e2019-12-17 09:28:10 -08004032 /**
4033 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4034 * @param subId The subscription to use to check the configuration.
4035 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 @Override
4037 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004038 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004039 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004040
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4042 final long token = Binder.clearCallingIdentity();
4043 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004044 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004046 } catch (ImsException e) {
4047 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 } finally {
4049 Binder.restoreCallingIdentity(token);
4050 }
4051 }
4052
4053 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004054 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004056 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 final long identity = Binder.clearCallingIdentity();
4058 try {
4059 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004060 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004062 } catch (ImsException e) {
4063 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004064 } finally {
4065 Binder.restoreCallingIdentity(identity);
4066 }
4067 }
4068
shilu366312e2019-12-17 09:28:10 -08004069 /**
4070 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4071 * @param subId The subscription to use to check the configuration.
4072 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004074 public boolean isVtSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004075 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004076 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004080 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4081 } catch (ImsException e) {
4082 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
4086 }
4087
4088 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004089 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004091 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004095 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004096 } catch (ImsException e) {
4097 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 } finally {
4099 Binder.restoreCallingIdentity(identity);
4100 }
4101 }
4102
shilu366312e2019-12-17 09:28:10 -08004103 /**
4104 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4105 * @param subId The subscription to use to check the configuration.
4106 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 @Override
4108 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004109 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004110 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004114 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004116 } catch (ImsException e) {
4117 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
4121 }
4122
4123 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004124 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004126 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 final long identity = Binder.clearCallingIdentity();
4128 try {
4129 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004130 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004131 } catch (ImsException e) {
4132 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 } finally {
4134 Binder.restoreCallingIdentity(identity);
4135 }
4136 }
4137
shilu366312e2019-12-17 09:28:10 -08004138 /**
4139 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4140 * @param subId The subscription to use to check the configuration.
4141 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 @Override
4143 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004144 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004145 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
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
Brad Ebinger1c162042019-02-21 14:49:10 -08004159 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004161 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004165 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004167 } catch (ImsException e) {
4168 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
4172 }
4173
4174 @Override
4175 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4177 "setVoWiFiNonPersistent");
4178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004181 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004182 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004183 } catch (ImsException e) {
4184 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 } finally {
4186 Binder.restoreCallingIdentity(identity);
4187 }
4188 }
4189
shilu366312e2019-12-17 09:28:10 -08004190 /**
4191 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4192 * @param subId The subscription to use to check the configuration.
4193 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 @Override
4195 public int getVoWiFiModeSetting(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004196 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004197 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004201 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004203 } catch (ImsException e) {
4204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
4208 }
4209
4210 @Override
4211 public void setVoWiFiModeSetting(int subId, int mode) {
4212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4213 "setVoWiFiModeSetting");
4214 final long identity = Binder.clearCallingIdentity();
4215 try {
4216 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004217 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004219 } catch (ImsException e) {
4220 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 } finally {
4222 Binder.restoreCallingIdentity(identity);
4223 }
4224 }
4225
4226 @Override
4227 public int getVoWiFiRoamingModeSetting(int subId) {
4228 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4229 final long identity = Binder.clearCallingIdentity();
4230 try {
4231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004232 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004234 } catch (ImsException e) {
4235 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 } finally {
4237 Binder.restoreCallingIdentity(identity);
4238 }
4239 }
4240
4241 @Override
4242 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4244 "setVoWiFiRoamingModeSetting");
4245 final long identity = Binder.clearCallingIdentity();
4246 try {
4247 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004248 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004249 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004250 } catch (ImsException e) {
4251 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004252 } finally {
4253 Binder.restoreCallingIdentity(identity);
4254 }
4255 }
4256
4257 @Override
4258 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4260 "setRttCapabilityEnabled");
4261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004264 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4265 } catch (ImsException e) {
4266 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
4270 }
4271
shilu366312e2019-12-17 09:28:10 -08004272 /**
4273 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4274 * @param subId The subscription to use to check the configuration.
4275 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 @Override
4277 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004278 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004279 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 final long identity = Binder.clearCallingIdentity();
4281 try {
4282 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004283 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004285 } catch (ImsException e) {
4286 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
4290 }
4291
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004292 @Override
4293 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4294 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004297 if (!isImsAvailableOnDevice()) {
4298 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4299 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004300 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004302 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004303 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004304 } catch (ImsException e) {
4305 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004306 } finally {
4307 Binder.restoreCallingIdentity(identity);
4308 }
4309 }
4310
4311 @Override
4312 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4313 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4314 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004315 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4316 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4317 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004318 try {
4319 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004320 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004321 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004322 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004323 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4324 + "is inactive, ignoring unregister.");
4325 // If the subscription is no longer active, just return, since the callback will already
4326 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004327 } finally {
4328 Binder.restoreCallingIdentity(identity);
4329 }
4330 }
4331
allenwtsu99c623b2020-01-03 18:24:23 +08004332
4333 private void checkModifyPhoneStatePermission(int subId, String message) {
4334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4335 message);
4336 }
4337
4338 private boolean isImsProvisioningRequired(int subId, int capability,
4339 boolean isMmtelCapability) {
4340 Phone phone = getPhone(subId);
4341 if (phone == null) {
4342 loge("phone instance null for subid " + subId);
4343 return false;
4344 }
4345 if (isMmtelCapability) {
4346 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4347 return false;
4348 }
4349 } else {
4350 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4351 return false;
4352 }
4353 }
4354 return true;
4355 }
4356
4357 @Override
4358 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4359 boolean isProvisioned) {
4360 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4361
4362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4365 if (!isImsProvisioningRequired(subId, capability, false)) {
4366 return;
4367 }
4368
4369 // this capability requires provisioning, route to the correct API.
4370 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4371 switch (capability) {
4372 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4373 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4374 ims.setEabProvisioned(isProvisioned);
4375 break;
4376 default: {
4377 throw new IllegalArgumentException("Tried to set provisioning for "
4378 + "rcs capability '" + capability + "', which does not require "
4379 + "provisioning.");
4380 }
4381 }
4382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
4385
4386 }
4387
4388
4389 @Override
4390 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4391 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4392 final long identity = Binder.clearCallingIdentity();
4393 try {
4394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4395 if (!isImsProvisioningRequired(subId, capability, false)) {
4396 return true;
4397 }
4398
4399 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4400 switch (capability) {
4401 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4402 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4403 return ims.isEabProvisionedOnDevice();
4404
4405 default: {
4406 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4407 + "capability '" + capability + "', which does not require "
4408 + "provisioning.");
4409 }
4410 }
4411
4412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
4415 }
4416
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004417 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004418 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4419 boolean isProvisioned) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004420 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4421 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004422 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4423 }
allenwtsu99c623b2020-01-03 18:24:23 +08004424 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004425 final long identity = Binder.clearCallingIdentity();
4426 try {
4427 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004428 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004429 return;
4430 }
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004431 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4432 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4433 loge("setImsProvisioningStatusForCapability: called for technology that does "
4434 + "not support provisioning - " + tech);
4435 return;
4436 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004437
4438 // this capability requires provisioning, route to the correct API.
4439 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4440 switch (capability) {
4441 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4442 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4443 ims.setVolteProvisioned(isProvisioned);
4444 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4445 ims.setWfcProvisioned(isProvisioned);
4446 }
4447 break;
4448 }
4449 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4450 // There is currently no difference in VT provisioning type.
4451 ims.setVtProvisioned(isProvisioned);
4452 break;
4453 }
4454 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4455 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4456 // change the capability of the feature instead if needed.
4457 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4458 == isProvisioned) {
4459 // No change in provisioning.
4460 return;
4461 }
4462 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4463 try {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004464 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004465 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004466 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4467 + ", Exception" + e.getMessage());
4468 }
4469 break;
4470 }
4471 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004472 throw new IllegalArgumentException("Tried to set provisioning for "
4473 + "MmTel capability '" + capability + "', which does not require "
4474 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004475 }
4476 }
4477
4478 } finally {
4479 Binder.restoreCallingIdentity(identity);
4480 }
4481 }
4482
4483 @Override
4484 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004485 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4486 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004487 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4488 }
4489 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4490 final long identity = Binder.clearCallingIdentity();
4491 try {
4492 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004493 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004494 return true;
4495 }
4496
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004497 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4498 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4499 loge("getImsProvisioningStatusForCapability: called for technology that does "
4500 + "not support provisioning - " + tech);
4501 return true;
4502 }
4503
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004504 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4505 switch (capability) {
4506 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4507 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4508 return ims.isVolteProvisionedOnDevice();
4509 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4510 return ims.isWfcProvisionedOnDevice();
4511 }
4512 // This should never happen, since we are checking tech above to make sure it
4513 // is either LTE or IWLAN.
4514 throw new IllegalArgumentException("Invalid radio technology for voice "
4515 + "capability.");
4516 }
4517 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4518 // There is currently no difference in VT provisioning type.
4519 return ims.isVtProvisionedOnDevice();
4520 }
4521 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4522 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4523 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4524 }
4525 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004526 throw new IllegalArgumentException(
4527 "Tried to get provisioning for MmTel capability '" + capability
4528 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004529 }
4530 }
4531
4532 } finally {
4533 Binder.restoreCallingIdentity(identity);
4534 }
4535 }
4536
4537 @Override
4538 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4539 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4540 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4541 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4542 }
4543 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4544 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4545 return (provisionedBits & capability) > 0;
4546 }
4547
4548 @Override
4549 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4550 boolean isProvisioned) {
4551 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4552 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4553 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4554 }
4555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4556 "setProvisioningStatusForCapability");
4557 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4558 // If the current provisioning status for capability already matches isProvisioned,
4559 // do nothing.
4560 if (((provisionedBits & capability) > 0) == isProvisioned) {
4561 return;
4562 }
4563 if (isProvisioned) {
4564 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4565 } else {
4566 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4567 }
4568 }
4569
4570 /**
4571 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4572 * technology. The bitfield should mirror the bitfield defined by
4573 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4574 */
4575 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4576 String key = getMmTelProvisioningKey(subId, tech);
4577 // Default is no capabilities are provisioned.
4578 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4579 }
4580
4581 /**
4582 * Sets the MmTel capability provisioning bitfield (defined by
4583 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4584 * technology specified.
4585 *
4586 * Note: This is a synchronous command and should not be called on UI thread.
4587 */
4588 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4589 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4590 String key = getMmTelProvisioningKey(subId, tech);
4591 editor.putInt(key, newField);
4592 editor.commit();
4593 }
4594
4595 private static String getMmTelProvisioningKey(int subId, int tech) {
4596 // resulting key is provision_ims_mmtel_{subId}_{tech}
4597 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4598 }
4599
4600 /**
4601 * Query CarrierConfig to see if the specified capability requires provisioning for the
4602 * carrier associated with the subscription id.
4603 */
4604 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4605 int capability) {
4606 CarrierConfigManager configManager = new CarrierConfigManager(context);
4607 PersistableBundle c = configManager.getConfigForSubId(subId);
4608 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004609 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004610 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4611 false);
4612 boolean requireVoiceVtProvisioning = c.getBoolean(
4613 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4614
4615 // First check to make sure that the capability requires provisioning.
4616 switch (capability) {
4617 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4618 // intentional fallthrough
4619 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4620 if (requireVoiceVtProvisioning) {
4621 // Voice and Video requires provisioning
4622 return true;
4623 }
4624 break;
4625 }
4626 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4627 if (requireUtProvisioning) {
4628 // UT requires provisioning
4629 return true;
4630 }
4631 break;
4632 }
4633 }
4634 return false;
4635 }
4636
allenwtsu99c623b2020-01-03 18:24:23 +08004637 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4638 int capability) {
4639 CarrierConfigManager configManager = new CarrierConfigManager(context);
4640 PersistableBundle c = configManager.getConfigForSubId(subId);
4641
4642 boolean requireRcsProvisioning = c.getBoolean(
4643 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4644
4645 // First check to make sure that the capability requires provisioning.
4646 switch (capability) {
4647 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4648 // intentional fallthrough
4649 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4650 if (requireRcsProvisioning) {
4651 // OPTION or PRESENCE requires provisioning
4652 return true;
4653 }
4654 break;
4655 }
4656 }
4657 return false;
4658 }
4659
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004660 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004661 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4663 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4664 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004665 enforceReadPrivilegedPermission("getImsProvisioningInt");
4666 final long identity = Binder.clearCallingIdentity();
4667 try {
4668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004669 int slotId = getSlotIndex(subId);
4670 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4671 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4672 + subId + "' for key:" + key);
4673 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4674 }
calvinpan9cfff472021-02-08 19:59:36 +08004675 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004676 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004677 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4678 + subId + "' for key:" + key);
4679 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
4683 }
4684
4685 @Override
4686 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004687 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4688 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4689 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004690 enforceReadPrivilegedPermission("getImsProvisioningString");
4691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004694 int slotId = getSlotIndex(subId);
4695 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4696 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4697 + subId + "' for key:" + key);
4698 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4699 }
calvinpan9cfff472021-02-08 19:59:36 +08004700 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004701 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004702 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4703 + subId + "' for key:" + key);
4704 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004705 } finally {
4706 Binder.restoreCallingIdentity(identity);
4707 }
4708 }
4709
4710 @Override
4711 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004712 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4713 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4714 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4716 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004717 final long identity = Binder.clearCallingIdentity();
4718 try {
4719 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004720 int slotId = getSlotIndex(subId);
4721 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4722 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4723 + subId + "' for key:" + key);
4724 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4725 }
calvinpan9cfff472021-02-08 19:59:36 +08004726 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4727 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004728 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004729 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004730 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004731 } finally {
4732 Binder.restoreCallingIdentity(identity);
4733 }
4734 }
4735
4736 @Override
4737 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004738 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4739 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4740 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4742 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004743 final long identity = Binder.clearCallingIdentity();
4744 try {
4745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004746 int slotId = getSlotIndex(subId);
4747 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4748 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4749 + subId + "' for key:" + key);
4750 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4751 }
calvinpan9cfff472021-02-08 19:59:36 +08004752 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4753 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004754 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004755 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004756 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
4760 }
4761
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004762 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004763 int slotId = SubscriptionManager.getSlotIndex(subId);
4764 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004765 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4766 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004767 }
4768 return slotId;
4769 }
4770
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004771 private int getSlotIndex(int subId) {
4772 int slotId = SubscriptionManager.getSlotIndex(subId);
4773 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4774 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4775 }
4776 return slotId;
4777 }
4778
Wink Saville36469e72014-06-11 15:17:00 -07004779 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004780 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004781 */
4782 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004783 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4784 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004785 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004786 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004787 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004788 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004789 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004790 mApp, subId, callingPackage, callingFeatureId,
4791 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004792 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4793 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004795 final long identity = Binder.clearCallingIdentity();
4796 try {
4797 final Phone phone = getPhone(subId);
4798 if (phone != null) {
4799 return phone.getServiceState().getDataNetworkType();
4800 } else {
4801 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4802 }
4803 } finally {
4804 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004805 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004806 }
4807
4808 /**
4809 * Returns the data network type
4810 */
4811 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004812 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004813 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4814 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004815 }
4816
4817 /**
4818 * Returns the data network type for a subId
4819 */
4820 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004821 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4822 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004824 mApp, subId, callingPackage, callingFeatureId,
4825 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004826 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4827 }
4828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 final long identity = Binder.clearCallingIdentity();
4830 try {
4831 final Phone phone = getPhone(subId);
4832 if (phone != null) {
4833 return phone.getServiceState().getDataNetworkType();
4834 } else {
4835 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4836 }
4837 } finally {
4838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004840 }
4841
4842 /**
Wink Saville36469e72014-06-11 15:17:00 -07004843 * Returns the Voice network type for a subId
4844 */
4845 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004846 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4847 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004849 mApp, subId, callingPackage, callingFeatureId,
4850 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004851 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4852 }
4853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 final Phone phone = getPhone(subId);
4857 if (phone != null) {
4858 return phone.getServiceState().getVoiceNetworkType();
4859 } else {
4860 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4861 }
4862 } finally {
4863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004865 }
4866
4867 /**
4868 * @return true if a ICC card is present
4869 */
4870 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004871 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004872 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4873 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004874 }
4875
4876 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004877 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004878 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004879 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004880 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881 final long identity = Binder.clearCallingIdentity();
4882 try {
4883 final Phone phone = PhoneFactory.getPhone(slotIndex);
4884 if (phone != null) {
4885 return phone.getIccCard().hasIccCard();
4886 } else {
4887 return false;
4888 }
4889 } finally {
4890 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004892 }
4893
4894 /**
4895 * Return if the current radio is LTE on CDMA. This
4896 * is a tri-state return value as for a period of time
4897 * the mode may be unknown.
4898 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004899 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004900 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004901 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004902 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004903 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004904 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4905 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4906 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004907 }
4908
Sanket Padawe356d7632015-06-22 14:03:32 -07004909 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004910 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4911 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004912 try {
4913 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4914 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004915 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4916 }
4917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004918 final long identity = Binder.clearCallingIdentity();
4919 try {
4920 final Phone phone = getPhone(subId);
4921 if (phone == null) {
4922 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4923 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004924 return TelephonyProperties.lte_on_cdma_device()
4925 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 }
4927 } finally {
4928 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004929 }
Wink Saville36469e72014-06-11 15:17:00 -07004930 }
4931
Wink Saville36469e72014-06-11 15:17:00 -07004932 /**
4933 * {@hide}
4934 * Returns Default subId, 0 in the case of single standby.
4935 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004936 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004937 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004938 }
4939
Shishir Agrawala9f32182016-04-12 12:00:16 -07004940 private int getSlotForDefaultSubscription() {
4941 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4942 }
4943
Wink Savilleb564aae2014-10-23 10:18:09 -07004944 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004945 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004946 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004947
Pengquan Menge92a50d2018-09-21 15:54:48 -07004948 private boolean isActiveSubscription(int subId) {
4949 return mSubscriptionController.isActiveSubId(subId);
4950 }
4951
Ihab Awadf2177b72013-11-25 13:33:23 -08004952 /**
4953 * @see android.telephony.TelephonyManager.WifiCallingChoices
4954 */
4955 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 final long identity = Binder.clearCallingIdentity();
4957 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004958 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4960 getWhenToMakeWifiCallsDefaultPreference());
4961 } finally {
4962 Binder.restoreCallingIdentity(identity);
4963 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004964 }
4965
4966 /**
4967 * @see android.telephony.TelephonyManager.WifiCallingChoices
4968 */
4969 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 final long identity = Binder.clearCallingIdentity();
4971 try {
4972 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004973 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
4977 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004978 }
4979
Sailesh Nepald1e68152013-12-12 19:08:02 -08004980 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004981 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004982 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004983 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004984
Jordan Liu4c733742019-02-28 12:03:40 -08004985 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4986 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4987 if (phoneId == -1) {
4988 throw new IllegalArgumentException("Given slot index: " + slotIndex
4989 + " does not correspond to an active phone");
4990 }
4991 return PhoneFactory.getPhone(phoneId);
4992 }
4993
Shishir Agrawal566b7612013-10-28 14:41:00 -07004994 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004995 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4996 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4998 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005000 if (DBG) {
5001 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5002 }
5003 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5004 p2);
5005 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005006
Jordan Liu4c733742019-02-28 12:03:40 -08005007
5008 @Override
5009 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5010 int slotIndex, String callingPackage, String aid, int p2) {
5011 enforceModifyPermission();
5012 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5013 if (DBG) {
5014 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5015 }
5016 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5017 callingPackage, aid, p2);
5018 }
5019
5020 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5021 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 final long identity = Binder.clearCallingIdentity();
5023 try {
5024 if (TextUtils.equals(ISDR_AID, aid)) {
5025 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005026 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5027 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 if (bestComponent == null
5029 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5030 loge("The calling package is not allowed to access ISD-R.");
5031 throw new SecurityException(
5032 "The calling package is not allowed to access ISD-R.");
5033 }
Derek Tan740e1672017-06-27 14:56:27 -07005034 }
Derek Tan740e1672017-06-27 14:56:27 -07005035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005037 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5038 null /* workSource */);
5039 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040 return response;
5041 } finally {
5042 Binder.restoreCallingIdentity(identity);
5043 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005044 }
5045
5046 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005047 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5049 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005050 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5051 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5052 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005053
Jordan Liu4c733742019-02-28 12:03:40 -08005054 @Override
5055 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5056 enforceModifyPermission();
5057 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5058 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5059 channel);
5060 }
5061
5062 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 final long identity = Binder.clearCallingIdentity();
5064 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005065 if (channel < 0) {
5066 return false;
5067 }
Jordan Liu4c733742019-02-28 12:03:40 -08005068 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5069 null /* workSource */);
5070 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 return success;
5072 } finally {
5073 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005074 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005075 }
5076
5077 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005078 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005079 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5081 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005082 if (DBG) {
5083 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5084 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5085 + p3 + " data=" + data);
5086 }
5087 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5088 command, p1, p2, p3, data);
5089 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005090
Jordan Liu4c733742019-02-28 12:03:40 -08005091 @Override
5092 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5093 int command, int p1, int p2, int p3, String data) {
5094 enforceModifyPermission();
5095 if (DBG) {
5096 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5097 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5098 + p3 + " data=" + data);
5099 }
5100 return iccTransmitApduLogicalChannelWithPermission(
5101 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5102 data);
5103 }
5104
5105 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5106 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005107 final long identity = Binder.clearCallingIdentity();
5108 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005109 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 return "";
5111 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005114 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5115 null /* workSource */);
5116 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005118 // Append the returned status code to the end of the response payload.
5119 String s = Integer.toHexString(
5120 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5121 if (response.payload != null) {
5122 s = IccUtils.bytesToHexString(response.payload) + s;
5123 }
5124 return s;
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005127 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005128 }
Jake Hambye994d462014-02-03 13:10:13 -08005129
Evan Charltonc66da362014-05-16 14:06:40 -07005130 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005131 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5132 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5134 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005136 if (DBG) {
5137 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5138 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5139 }
5140 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5141 cla, command, p1, p2, p3, data);
5142 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005143
Jordan Liu4c733742019-02-28 12:03:40 -08005144 @Override
5145 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5146 int command, int p1, int p2, int p3, String data) {
5147 enforceModifyPermission();
5148 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5149 if (DBG) {
5150 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5151 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5152 + " data=" + data);
5153 }
5154
5155 return iccTransmitApduBasicChannelWithPermission(
5156 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5157 p2, p3, data);
5158 }
5159
5160 // open APDU basic channel assuming the caller has sufficient permissions
5161 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5162 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 final long identity = Binder.clearCallingIdentity();
5164 try {
5165 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5166 && TextUtils.equals(ISDR_AID, data)) {
5167 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005168 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5169 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 if (bestComponent == null
5171 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5172 loge("The calling package is not allowed to select ISD-R.");
5173 throw new SecurityException(
5174 "The calling package is not allowed to select ISD-R.");
5175 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005176 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005179 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5180 null /* workSource */);
5181 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183 // Append the returned status code to the end of the response payload.
5184 String s = Integer.toHexString(
5185 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5186 if (response.payload != null) {
5187 s = IccUtils.bytesToHexString(response.payload) + s;
5188 }
5189 return s;
5190 } finally {
5191 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005192 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005193 }
5194
5195 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005196 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005197 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5199 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 final long identity = Binder.clearCallingIdentity();
5202 try {
5203 if (DBG) {
5204 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5205 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5206 }
5207
5208 IccIoResult response =
5209 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5210 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5211 subId);
5212
5213 if (DBG) {
5214 log("Exchange SIM_IO [R]" + response);
5215 }
5216
5217 byte[] result = null;
5218 int length = 2;
5219 if (response.payload != null) {
5220 length = 2 + response.payload.length;
5221 result = new byte[length];
5222 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5223 } else {
5224 result = new byte[length];
5225 }
5226
5227 result[length - 1] = (byte) response.sw2;
5228 result[length - 2] = (byte) response.sw1;
5229 return result;
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005232 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005233 }
5234
Nathan Haroldb3014052017-01-25 15:57:32 -08005235 /**
5236 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5237 * on a particular subscription
5238 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005239 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5240 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005241 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005242 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005243 return null;
5244 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245
5246 final long identity = Binder.clearCallingIdentity();
5247 try {
5248 if (appType != TelephonyManager.APPTYPE_USIM
5249 && appType != TelephonyManager.APPTYPE_SIM) {
5250 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5251 return null;
5252 }
5253 Object response = sendRequest(
5254 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5255 if (response instanceof String[]) {
5256 return (String[]) response;
5257 }
yincheng zhaod698b842019-09-06 17:06:54 -07005258 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005260 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 } finally {
5262 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005263 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005264 }
5265
yincheng zhaod698b842019-09-06 17:06:54 -07005266 /**
5267 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5268 * subscription.
5269 *
5270 * @param subId the id of the subscription.
5271 * @param appType the uicc app type, must be USIM or SIM.
5272 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5273 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005274 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005275 * @return number of fplmns that is successfully written to the SIM.
5276 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005277 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5278 String callingFeatureId) {
5279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5280 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005281 if (DBG) logv("no permissions for setForbiddenplmns");
5282 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5283 }
5284 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5285 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5286 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5287 }
5288 if (fplmns == null) {
5289 throw new IllegalArgumentException("Fplmn List provided is null");
5290 }
5291 for (String fplmn : fplmns) {
5292 if (!CellIdentity.isValidPlmn(fplmn)) {
5293 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5294 }
5295 }
5296 final long identity = Binder.clearCallingIdentity();
5297 try {
5298 Object response = sendRequest(
5299 CMD_SET_FORBIDDEN_PLMNS,
5300 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5301 subId);
5302 return (int) response;
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
5306 }
5307
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005308 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005309 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5311 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 final long identity = Binder.clearCallingIdentity();
5314 try {
5315 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5316 if (response.payload == null) {
5317 return "";
5318 }
Evan Charltonc66da362014-05-16 14:06:40 -07005319
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 // Append the returned status code to the end of the response payload.
5321 String s = Integer.toHexString(
5322 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5323 s = IccUtils.bytesToHexString(response.payload) + s;
5324 return s;
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
Evan Charltonc66da362014-05-16 14:06:40 -07005328 }
5329
Jake Hambye994d462014-02-03 13:10:13 -08005330 /**
5331 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5332 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5333 *
5334 * @param itemID the ID of the item to read
5335 * @return the NV item as a String, or null on error.
5336 */
5337 @Override
5338 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005339 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5341 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342
5343 final long identity = Binder.clearCallingIdentity();
5344 try {
5345 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005346 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5348 return value;
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
Jake Hambye994d462014-02-03 13:10:13 -08005352 }
5353
5354 /**
5355 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5356 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5357 *
5358 * @param itemID the ID of the item to read
5359 * @param itemValue the value to write, as a String
5360 * @return true on success; false on any failure
5361 */
5362 @Override
5363 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005364 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5366 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367
5368 final long identity = Binder.clearCallingIdentity();
5369 try {
5370 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5371 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005372 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5374 return success;
5375 } finally {
5376 Binder.restoreCallingIdentity(identity);
5377 }
Jake Hambye994d462014-02-03 13:10:13 -08005378 }
5379
5380 /**
5381 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5382 * Used for device configuration by some CDMA operators.
5383 *
5384 * @param preferredRoamingList byte array containing the new PRL
5385 * @return true on success; false on any failure
5386 */
5387 @Override
5388 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5390 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391
5392 final long identity = Binder.clearCallingIdentity();
5393 try {
5394 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5395 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5396 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5397 return success;
5398 } finally {
5399 Binder.restoreCallingIdentity(identity);
5400 }
Jake Hambye994d462014-02-03 13:10:13 -08005401 }
5402
5403 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005404 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005405 * Used for device configuration by some CDMA operators.
5406 *
chen xu6dac5ab2018-10-26 17:39:23 -07005407 * @param slotIndex - device slot.
5408 *
Jake Hambye994d462014-02-03 13:10:13 -08005409 * @return true on success; false on any failure
5410 */
5411 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005412 public boolean resetModemConfig(int slotIndex) {
5413 Phone phone = PhoneFactory.getPhone(slotIndex);
5414 if (phone != null) {
5415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5416 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417
chen xu6dac5ab2018-10-26 17:39:23 -07005418 final long identity = Binder.clearCallingIdentity();
5419 try {
5420 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5421 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5422 return success;
5423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005426 }
chen xu6dac5ab2018-10-26 17:39:23 -07005427 return false;
5428 }
5429
5430 /**
5431 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5432 *
5433 * @param slotIndex - device slot.
5434 *
5435 * @return true on success; false on any failure
5436 */
5437 @Override
5438 public boolean rebootModem(int slotIndex) {
5439 Phone phone = PhoneFactory.getPhone(slotIndex);
5440 if (phone != null) {
5441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5442 mApp, phone.getSubId(), "rebootModem");
5443
5444 final long identity = Binder.clearCallingIdentity();
5445 try {
5446 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5447 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5448 return success;
5449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
5452 }
5453 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005454 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005455
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005456 public String[] getPcscfAddress(String apnType, String callingPackage,
5457 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005458 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5460 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005461 return new String[0];
5462 }
5463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 final long identity = Binder.clearCallingIdentity();
5465 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005466 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467 } finally {
5468 Binder.restoreCallingIdentity(identity);
5469 }
Wink Saville36469e72014-06-11 15:17:00 -07005470 }
5471
Brad Ebinger51f743a2017-01-23 13:50:20 -08005472 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005473 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5474 * {@link #disableIms(int)}.
5475 * @param slotIndex device slot.
5476 */
5477 public void resetIms(int slotIndex) {
5478 enforceModifyPermission();
5479
5480 final long identity = Binder.clearCallingIdentity();
5481 try {
5482 if (mImsResolver == null) {
5483 // may happen if the does not support IMS.
5484 return;
5485 }
5486 mImsResolver.disableIms(slotIndex);
5487 mImsResolver.enableIms(slotIndex);
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
5490 }
5491 }
5492
5493 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005494 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5495 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005496 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005497 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005498 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499
5500 final long identity = Binder.clearCallingIdentity();
5501 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005502 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005503 // may happen if the device does not support IMS.
5504 return;
5505 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005506 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 } finally {
5508 Binder.restoreCallingIdentity(identity);
5509 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005510 }
5511
5512 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005513 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5514 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005515 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005516 public void disableIms(int slotId) {
5517 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518
5519 final long identity = Binder.clearCallingIdentity();
5520 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005521 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005522 // may happen if the device does not support IMS.
5523 return;
5524 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005525 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 } finally {
5527 Binder.restoreCallingIdentity(identity);
5528 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005529 }
5530
5531 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005532 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5533 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005534 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005535 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005536 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005537 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538
5539 final long identity = Binder.clearCallingIdentity();
5540 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005541 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005542 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5543 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005544 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005545 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005549 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005550 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005551 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5552 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005553 @Override
5554 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005555 enforceModifyPermission();
5556
5557 final long identity = Binder.clearCallingIdentity();
5558 try {
5559 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005560 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
5564 }
5565
5566 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005567 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005568 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005569 */
5570 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005572
5573 final long identity = Binder.clearCallingIdentity();
5574 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005575 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005576 // may happen if the device does not support IMS.
5577 return null;
5578 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005579 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 } finally {
5581 Binder.restoreCallingIdentity(identity);
5582 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005583 }
5584
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005585 /**
5586 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005587 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005588 */
5589 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5590 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591
5592 final long identity = Binder.clearCallingIdentity();
5593 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005594 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005595 // may happen if the device does not support IMS.
5596 return null;
5597 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005598 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005602 }
5603
Brad Ebinger884c07b2018-02-15 16:17:40 -08005604 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005605 * Sets the ImsService Package Name that Telephony will bind to.
5606 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005607 * @param slotIndex the slot ID that the ImsService should bind for.
5608 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005609 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005610 * @param featureTypes An integer array of feature types associated with a packageName.
5611 * @param packageName The name of the package that the current configuration will be replaced
5612 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005613 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005614 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005615 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5616 int[] featureTypes, String packageName) {
5617 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5618 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5620 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005621 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 final long identity = Binder.clearCallingIdentity();
5624 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005625 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005626 // may happen if the device does not support IMS.
5627 return false;
5628 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005629 Map<Integer, String> featureConfig = new HashMap<>();
5630 for (int featureType : featureTypes) {
5631 featureConfig.put(featureType, packageName);
5632 }
5633 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5634 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005638 }
5639
5640 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005641 * Clears any carrier ImsService overrides for the slot index specified that were previously
5642 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5643 *
5644 * This should only be used for testing.
5645 *
5646 * @param slotIndex the slot ID that the ImsService should bind for.
5647 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5648 */
5649 @Override
5650 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5651 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5652 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5653 "clearCarrierImsServiceOverride");
5654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5655 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5656 "clearCarrierImsServiceOverride");
5657
5658 final long identity = Binder.clearCallingIdentity();
5659 try {
5660 if (mImsResolver == null) {
5661 // may happen if the device does not support IMS.
5662 return false;
5663 }
5664 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5665 } finally {
5666 Binder.restoreCallingIdentity(identity);
5667 }
5668 }
5669
5670 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005671 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005672 *
5673 * @param slotId The slot that the ImsService is associated with.
5674 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5675 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005676 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005677 * @return the package name of the ImsService configuration.
5678 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005679 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5680 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005681 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005682 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005683 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005684 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5685 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005686
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 final long identity = Binder.clearCallingIdentity();
5688 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005689 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005690 // may happen if the device does not support IMS.
5691 return "";
5692 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005693 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005694 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5695 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005699 }
5700
Brad Ebinger77b832e2019-10-17 17:03:22 -07005701 /**
5702 * Get the MmTelFeature state associated with the requested subscription id.
5703 * @param subId The subscription that the MmTelFeature is associated with.
5704 * @param callback A callback with an integer containing the
5705 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5706 */
5707 @Override
5708 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5709 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5710 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5711 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5712 "IMS not available on device.");
5713 }
5714 final long token = Binder.clearCallingIdentity();
5715 try {
5716 int slotId = getSlotIndex(subId);
5717 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5718 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5719 + subId + "'");
5720 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5721 }
5722 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5723 try {
5724 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5725 } catch (RemoteException e) {
5726 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5727 + "Ignore");
5728 }
5729 });
5730 } finally {
5731 Binder.restoreCallingIdentity(token);
5732 }
5733 }
5734
Daniel Brightbb5840b2021-01-12 15:48:18 -08005735 /**
5736 * Sets the ims registration state on all valid {@link Phone}s.
5737 */
5738 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740
5741 final long identity = Binder.clearCallingIdentity();
5742 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005743 // NOTE: Before S, this method only set the default phone.
5744 for (final Phone phone : PhoneFactory.getPhones()) {
5745 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5746 phone.setImsRegistrationState(registered);
5747 }
5748 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005749 } finally {
5750 Binder.restoreCallingIdentity(identity);
5751 }
Wink Saville36469e72014-06-11 15:17:00 -07005752 }
5753
5754 /**
Stuart Scott54788802015-03-30 13:18:01 -07005755 * Set the network selection mode to automatic.
5756 *
5757 */
5758 @Override
5759 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5761 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762
5763 final long identity = Binder.clearCallingIdentity();
5764 try {
shilufc958392020-01-20 11:36:01 -08005765 if (!isActiveSubscription(subId)) {
5766 return;
5767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005769 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5770 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
Stuart Scott54788802015-03-30 13:18:01 -07005774 }
5775
Jack Yud10cdd42020-09-28 20:28:01 -07005776 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005777 * Ask the radio to connect to the input network and change selection mode to manual.
5778 *
5779 * @param subId the id of the subscription.
5780 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5781 * the operator to attach to.
5782 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5783 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5784 * normal network selection next time.
5785 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005786 */
5787 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005788 public boolean setNetworkSelectionModeManual(
5789 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5791 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005792
5793 if (!isActiveSubscription(subId)) {
5794 return false;
5795 }
5796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797 final long identity = Binder.clearCallingIdentity();
5798 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005799 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005801 if (DBG) {
5802 log("setNetworkSelectionModeManual: subId: " + subId
5803 + " operator: " + operatorInfo);
5804 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5806 } finally {
5807 Binder.restoreCallingIdentity(identity);
5808 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005809 }
shilu84f6e8b2019-12-19 13:58:01 -08005810 /**
5811 * Get the manual network selection
5812 *
5813 * @param subId the id of the subscription.
5814 *
5815 * @return the previously saved user selected PLMN
5816 */
5817 @Override
5818 public String getManualNetworkSelectionPlmn(int subId) {
5819 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005820 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005821 mApp, subId, "getManualNetworkSelectionPlmn");
5822
5823 final long identity = Binder.clearCallingIdentity();
5824 try {
5825 if (!isActiveSubscription(subId)) {
5826 return "";
5827 }
5828
5829 final Phone phone = getPhone(subId);
5830 if (phone == null) {
5831 return "";
5832 }
5833 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5834 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5835 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
5838 }
5839 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005840
5841 /**
5842 * Scans for available networks.
5843 */
5844 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005845 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5846 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5848 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005849 LocationAccessPolicy.LocationPermissionResult locationResult =
5850 LocationAccessPolicy.checkLocationPermission(mApp,
5851 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5852 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005853 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005854 .setCallingPid(Binder.getCallingPid())
5855 .setCallingUid(Binder.getCallingUid())
5856 .setMethod("getCellNetworkScanResults")
5857 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07005858 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5859 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005860 .build());
5861 switch (locationResult) {
5862 case DENIED_HARD:
5863 throw new SecurityException("Not allowed to access scan results -- location");
5864 case DENIED_SOFT:
5865 return null;
5866 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005867
Pengquan Menga1bb6272018-09-06 09:59:22 -07005868 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 try {
5870 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005871 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873 } finally {
5874 Binder.restoreCallingIdentity(identity);
5875 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005876 }
5877
5878 /**
sqian80370722020-01-29 15:02:51 -08005879 * Get the call forwarding info, given the call forwarding reason.
5880 */
5881 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005882 public void getCallForwarding(int subId, int callForwardingReason,
5883 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005884 enforceReadPrivilegedPermission("getCallForwarding");
5885 long identity = Binder.clearCallingIdentity();
5886 try {
5887 if (DBG) {
5888 log("getCallForwarding: subId " + subId
5889 + " callForwardingReason" + callForwardingReason);
5890 }
Hall Liua1acea22020-09-18 19:04:59 -07005891
5892 Phone phone = getPhone(subId);
5893 if (phone == null) {
5894 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005895 callback.onError(
5896 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005897 } catch (RemoteException e) {
5898 // ignore
5899 }
5900 return;
5901 }
5902
5903 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5904 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5905 @Override
5906 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5907 try {
5908 callback.onCallForwardingInfoAvailable(info);
5909 } catch (RemoteException e) {
5910 // ignore
5911 }
5912 }
5913
5914 @Override
5915 public void onError(int error) {
5916 try {
5917 callback.onError(error);
5918 } catch (RemoteException e) {
5919 // ignore
5920 }
5921 }
5922 });
5923 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
5927 }
5928
5929 /**
5930 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5931 * reason, the number to forward, and the timeout before the forwarding is attempted.
5932 */
5933 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005934 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5935 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005936 enforceModifyPermission();
5937 long identity = Binder.clearCallingIdentity();
5938 try {
5939 if (DBG) {
5940 log("setCallForwarding: subId " + subId
5941 + " callForwardingInfo" + callForwardingInfo);
5942 }
Hall Liua1acea22020-09-18 19:04:59 -07005943
5944 Phone phone = getPhone(subId);
5945 if (phone == null) {
5946 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005947 callback.accept(
5948 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005949 } catch (RemoteException e) {
5950 // ignore
5951 }
5952 return;
5953 }
5954
5955 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5956 FunctionalUtils.ignoreRemoteException(callback::accept));
5957
5958 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005959 } finally {
5960 Binder.restoreCallingIdentity(identity);
5961 }
5962 }
5963
5964 /**
Hall Liua1acea22020-09-18 19:04:59 -07005965 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005966 */
5967 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005968 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWangc63cf522021-03-31 22:08:45 +08005969 enforceReadPrivilegedPermission("getCallWaitingStatus");
sqian80370722020-01-29 15:02:51 -08005970 long identity = Binder.clearCallingIdentity();
5971 try {
Hall Liua1acea22020-09-18 19:04:59 -07005972 Phone phone = getPhone(subId);
5973 if (phone == null) {
5974 try {
5975 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5976 } catch (RemoteException e) {
5977 // ignore
5978 }
5979 return;
5980 }
SongFerngWangc63cf522021-03-31 22:08:45 +08005981 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5982 PersistableBundle c = configManager.getConfigForSubId(subId);
5983 boolean requireUssd = c.getBoolean(
5984 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005985
sqian80370722020-01-29 15:02:51 -08005986 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWangc63cf522021-03-31 22:08:45 +08005987 if (requireUssd) {
5988 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5989 getSubscriptionCarrierId(subId));
5990 String newUssdCommand = "";
5991 try {
5992 newUssdCommand = carrierXmlParser.getFeature(
5993 CarrierXmlParser.FEATURE_CALL_WAITING)
5994 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
5995 } catch (NullPointerException e) {
5996 loge("Failed to generate USSD number" + e);
5997 }
5998 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5999 mMainThreadHandler, callback, carrierXmlParser,
6000 CarrierXmlParser.SsEntry.SSAction.QUERY);
6001 final String ussdCommand = newUssdCommand;
6002 Executors.newSingleThreadExecutor().execute(() -> {
6003 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6004 });
6005 } else {
6006 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6007 callback::accept);
6008 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6009 }
sqian80370722020-01-29 15:02:51 -08006010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
6013 }
6014
6015 /**
Hall Liua1acea22020-09-18 19:04:59 -07006016 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08006017 */
6018 @Override
Hall Liua1acea22020-09-18 19:04:59 -07006019 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08006020 enforceModifyPermission();
6021 long identity = Binder.clearCallingIdentity();
6022 try {
Hall Liua1acea22020-09-18 19:04:59 -07006023 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6024
6025 Phone phone = getPhone(subId);
6026 if (phone == null) {
6027 try {
6028 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6029 } catch (RemoteException e) {
6030 // ignore
6031 }
6032 return;
6033 }
6034
SongFerngWangc63cf522021-03-31 22:08:45 +08006035 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6036 PersistableBundle c = configManager.getConfigForSubId(subId);
6037 boolean requireUssd = c.getBoolean(
6038 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07006039
SongFerngWangc63cf522021-03-31 22:08:45 +08006040 if (DBG) log("getCallWaitingStatus: subId " + subId);
6041 if (requireUssd) {
6042 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6043 getSubscriptionCarrierId(subId));
6044 CarrierXmlParser.SsEntry.SSAction ssAction =
6045 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6046 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6047 String newUssdCommand = "";
6048 try {
6049 newUssdCommand = carrierXmlParser.getFeature(
6050 CarrierXmlParser.FEATURE_CALL_WAITING)
6051 .makeCommand(ssAction, null);
6052 } catch (NullPointerException e) {
6053 loge("Failed to generate USSD number" + e);
6054 }
6055 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6056 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6057 final String ussdCommand = newUssdCommand;
6058 Executors.newSingleThreadExecutor().execute(() -> {
6059 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6060 });
6061 } else {
6062 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6063 FunctionalUtils.ignoreRemoteException(callback::accept));
6064
6065 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6066 }
sqian80370722020-01-29 15:02:51 -08006067 } finally {
6068 Binder.restoreCallingIdentity(identity);
6069 }
6070 }
6071
6072 /**
yinxub1bed742017-04-17 11:45:04 -07006073 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006074 *
yinxub1bed742017-04-17 11:45:04 -07006075 * @param subId id of the subscription
6076 * @param request contains the radio access networks with bands/channels to scan
6077 * @param messenger callback messenger for scan results or errors
6078 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006079 * @return the id of the requested scan which can be used to stop the scan.
6080 */
6081 @Override
6082 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006083 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6085 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006086 LocationAccessPolicy.LocationPermissionResult locationResult =
6087 LocationAccessPolicy.checkLocationPermission(mApp,
6088 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6089 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006090 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006091 .setCallingPid(Binder.getCallingPid())
6092 .setCallingUid(Binder.getCallingUid())
6093 .setMethod("requestNetworkScan")
6094 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6095 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006096 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07006097 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6098 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006099 if (e != null) {
6100 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6101 throw e;
6102 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006103 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006104 return TelephonyScanManager.INVALID_SCAN_ID;
6105 }
6106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 }
Hall Liu912dfd32019-04-25 14:02:26 -07006108 int callingUid = Binder.getCallingUid();
6109 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006110 final long identity = Binder.clearCallingIdentity();
6111 try {
6112 return mNetworkScanRequestTracker.startNetworkScan(
6113 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006114 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
yinxu504e1392017-04-12 16:03:22 -07006118 }
6119
Hall Liub2ac8ef2019-02-28 15:56:23 -08006120 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07006121 NetworkScanRequest request, int subId, String callingPackage) {
6122 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006123 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6124 boolean hasNetworkScanPermission =
6125 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6126 == PERMISSION_GRANTED;
6127
6128 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6129 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6130 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006131 }
6132
6133 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6134 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006135 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6136 return new SecurityException("Specific channels must not be"
6137 + " scanned without location access.");
6138 }
6139 }
6140 }
6141
Hall Liub2ac8ef2019-02-28 15:56:23 -08006142 return null;
6143 }
6144
yinxu504e1392017-04-12 16:03:22 -07006145 /**
6146 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006147 *
6148 * @param subId id of the subscription
6149 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006150 */
6151 @Override
6152 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6154 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155
Hall Liu912dfd32019-04-25 14:02:26 -07006156 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 final long identity = Binder.clearCallingIdentity();
6158 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006159 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 } finally {
6161 Binder.restoreCallingIdentity(identity);
6162 }
yinxu504e1392017-04-12 16:03:22 -07006163 }
6164
6165 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006166 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006167 *
SongFerngWang9e060372020-12-21 16:41:52 +08006168 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006169 */
6170 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006171 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006172 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006173 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006174 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175
6176 final long identity = Binder.clearCallingIdentity();
6177 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006178 if (DBG) log("getAllowedNetworkTypesBitmask");
6179 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6180 int networkTypesBitmask = (result != null ? result[0] : -1);
6181 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6182 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 } finally {
6184 Binder.restoreCallingIdentity(identity);
6185 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006186 }
6187
6188 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006189 * Get the allowed network types for certain reason.
6190 *
6191 * @param subId the id of the subscription.
6192 * @param reason the reason the allowed network type change is taking place
6193 * @return the allowed network types.
6194 */
6195 @Override
6196 public long getAllowedNetworkTypesForReason(int subId,
6197 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006198 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006199 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006200 final long identity = Binder.clearCallingIdentity();
6201 try {
6202 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6203 } finally {
6204 Binder.restoreCallingIdentity(identity);
6205 }
6206 }
6207
6208 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006209 * Enable/Disable E-UTRA-NR Dual Connectivity
6210 * @param subId subscription id of the sim card
6211 * @param nrDualConnectivityState expected NR dual connectivity state
6212 * This can be passed following states
6213 * <ol>
6214 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6215 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6216 * <li>Disable NR dual connectivity and force secondary cell to be released
6217 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6218 * </ol>
6219 * @return operation result.
6220 */
6221 @Override
6222 public int setNrDualConnectivityState(int subId,
6223 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6225 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006226 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006227 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6228 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6229 }
6230
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006231 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6232 final long identity = Binder.clearCallingIdentity();
6233 try {
6234 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6235 nrDualConnectivityState, subId,
6236 workSource);
6237 if (DBG) log("enableNRDualConnectivity result: " + result);
6238 return result;
6239 } finally {
6240 Binder.restoreCallingIdentity(identity);
6241 }
6242 }
6243
6244 /**
6245 * Is E-UTRA-NR Dual Connectivity enabled
6246 * @return true if dual connectivity is enabled else false
6247 */
6248 @Override
6249 public boolean isNrDualConnectivityEnabled(int subId) {
6250 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006251 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006252 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006253 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006254 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6255 return false;
6256 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006257 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6258 final long identity = Binder.clearCallingIdentity();
6259 try {
6260 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6261 null, subId, workSource);
6262 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6263 return isEnabled;
6264 } finally {
6265 Binder.restoreCallingIdentity(identity);
6266 }
6267 }
6268
6269 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006270 * Set the allowed network types of the device and
6271 * provide the reason triggering the allowed network change.
6272 *
6273 * @param subId the id of the subscription.
6274 * @param reason the reason the allowed network type change is taking place
6275 * @param allowedNetworkTypes the allowed network types.
6276 * @return true on success; false on any failure.
6277 */
6278 @Override
6279 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006280 @TelephonyManager.AllowedNetworkTypesReason int reason,
6281 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6283 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006284 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWangc2d3ccc2021-04-15 19:46:33 +08006285 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6286 return false;
6287 }
6288 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6289 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang9e060372020-12-21 16:41:52 +08006290 return false;
6291 }
6292
SongFerngWang522637d2021-03-02 22:09:29 +08006293 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6294 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6295
6296
6297 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6298 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6299 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006300 }
SongFerngWang522637d2021-03-02 22:09:29 +08006301
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006302 final long identity = Binder.clearCallingIdentity();
6303 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006304 Boolean success = (Boolean) sendRequest(
6305 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6306 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6307
6308 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6309 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006310 } finally {
6311 Binder.restoreCallingIdentity(identity);
6312 }
6313 }
6314
6315 /**
Miaoa84611c2019-03-15 09:21:10 +08006316 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006317 *
Miaoa84611c2019-03-15 09:21:10 +08006318 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006319 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006320 * @hide
6321 */
6322 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006323 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006324 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006326 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327 try {
Miaoa84611c2019-03-15 09:21:10 +08006328 if (phone != null) {
6329 return phone.hasMatchedTetherApnSetting();
6330 } else {
6331 return false;
6332 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333 } finally {
6334 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006335 }
Junda Liu475951f2014-11-07 16:45:03 -08006336 }
6337
6338 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006339 * Enable or disable always reporting signal strength changes from radio.
6340 *
6341 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6342 */
6343 @Override
6344 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6345 enforceModifyPermission();
6346 enforceSystemCaller();
6347
6348 final long identity = Binder.clearCallingIdentity();
6349 final Phone phone = getPhone(subId);
6350 try {
6351 if (phone != null) {
6352 if (DBG) {
6353 log("setAlwaysReportSignalStrength: subId=" + subId
6354 + " isEnable=" + isEnable);
6355 }
6356 phone.setAlwaysReportSignalStrength(isEnable);
6357 } else {
6358 loge("setAlwaysReportSignalStrength: no phone found for subId="
6359 + subId);
6360 }
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
6364 }
6365
6366 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006367 * Get the user enabled state of Mobile Data.
6368 *
6369 * TODO: remove and use isUserDataEnabled.
6370 * This can't be removed now because some vendor codes
6371 * calls through ITelephony directly while they should
6372 * use TelephonyManager.
6373 *
6374 * @return true on enabled
6375 */
6376 @Override
6377 public boolean getDataEnabled(int subId) {
6378 return isUserDataEnabled(subId);
6379 }
6380
6381 /**
6382 * Get whether mobile data is enabled per user setting.
6383 *
6384 * There are other factors deciding whether mobile data is actually enabled, but they are
6385 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006386 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006387 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006388 *
6389 * @return {@code true} if data is enabled else {@code false}
6390 */
6391 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006392 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006393 try {
6394 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6395 null);
6396 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6398 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006399 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400
6401 final long identity = Binder.clearCallingIdentity();
6402 try {
6403 int phoneId = mSubscriptionController.getPhoneId(subId);
6404 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6405 Phone phone = PhoneFactory.getPhone(phoneId);
6406 if (phone != null) {
6407 boolean retVal = phone.isUserDataEnabled();
6408 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6409 return retVal;
6410 } else {
6411 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6412 return false;
6413 }
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006416 }
6417 }
6418
6419 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006420 * Checks if the device is capable of mobile data by considering whether whether the
6421 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6422 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006423 *
Shuo Qian985d1232020-01-08 14:30:06 -08006424 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006425 */
6426 @Override
6427 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006428 try {
6429 try {
6430 mApp.enforceCallingOrSelfPermission(
6431 android.Manifest.permission.ACCESS_NETWORK_STATE,
6432 null);
6433 } catch (Exception e) {
6434 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6435 "isDataEnabled");
6436 }
6437 } catch (Exception e) {
6438 enforceReadPrivilegedPermission("isDataEnabled");
6439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006440
6441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 int phoneId = mSubscriptionController.getPhoneId(subId);
6444 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6445 Phone phone = PhoneFactory.getPhone(phoneId);
6446 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006447 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6449 return retVal;
6450 } else {
6451 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6452 return false;
6453 }
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006456 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006457 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006458
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006459 /**
6460 * Check if data is enabled for a specific reason
6461 * @param subId Subscription index
6462 * @param reason the reason the data enable change is taking place
6463 * @return {@code true} if the overall data is enabled; {@code false} if not.
6464 */
6465 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006466 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006467 @TelephonyManager.DataEnabledReason int reason) {
6468 try {
6469 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6470 null);
6471 } catch (Exception e) {
6472 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006473 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006474 }
6475
6476
6477 final long identity = Binder.clearCallingIdentity();
6478 try {
6479 int phoneId = mSubscriptionController.getPhoneId(subId);
6480 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006481 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006482 + " reason=" + reason);
6483 }
6484 Phone phone = PhoneFactory.getPhone(phoneId);
6485 if (phone != null) {
6486 boolean retVal;
6487 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6488 retVal = phone.isUserDataEnabled();
6489 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006490 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006491 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006492 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006493 return retVal;
6494 } else {
6495 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006496 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006497 + subId + " retVal=false");
6498 }
6499 return false;
6500 }
6501 } finally {
6502 Binder.restoreCallingIdentity(identity);
6503 }
6504 }
6505
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006506 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006507 Phone phone) {
Sarah Chinca45c312021-04-09 10:37:15 -07006508 if (uid == Process.PHONE_UID) {
6509 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6510 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liuce478d22020-07-13 12:13:03 -07006511 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6512 }
6513
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006514 //load access rules from carrier configs, and check those as well: b/139133814
6515 SubscriptionController subController = SubscriptionController.getInstance();
6516 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6517 || subController == null) return privilegeFromSim;
6518
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006519 PackageManager pkgMgr = phone.getContext().getPackageManager();
6520 String[] packages = pkgMgr.getPackagesForUid(uid);
6521
6522 final long identity = Binder.clearCallingIdentity();
6523 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006524 int subId = phone.getSubId();
6525 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6526 // A test override is in place for the privileges for this subId, so don't try to
6527 // read the subscription privileges.
6528 return privilegeFromSim;
6529 }
6530 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006531 SubscriptionManager subManager = (SubscriptionManager)
6532 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6533 for (String pkg : packages) {
6534 if (subManager.canManageSubscription(subInfo, pkg)) {
6535 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6536 }
6537 }
6538 return privilegeFromSim;
6539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
6542 }
6543
6544 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6545 String pkgName) {
6546 //load access rules from carrier configs, and check those as well: b/139133814
6547 SubscriptionController subController = SubscriptionController.getInstance();
6548 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6549 || subController == null) return privilegeFromSim;
6550
6551 final long identity = Binder.clearCallingIdentity();
6552 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006553 int subId = phone.getSubId();
6554 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6555 // A test override is in place for the privileges for this subId, so don't try to
6556 // read the subscription privileges.
6557 return privilegeFromSim;
6558 }
6559 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006560 SubscriptionManager subManager = (SubscriptionManager)
6561 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6562 return subManager.canManageSubscription(subInfo, pkgName)
6563 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6564 } finally {
6565 Binder.restoreCallingIdentity(identity);
6566 }
6567 }
6568
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006569 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006570 public int getCarrierPrivilegeStatus(int subId) {
6571 final Phone phone = getPhone(subId);
6572 if (phone == null) {
6573 loge("getCarrierPrivilegeStatus: Invalid subId");
6574 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6575 }
6576 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006577 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006578 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006579 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6580 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006581
6582 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6583 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006584 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006585 }
Junda Liu29340342014-07-10 15:23:27 -07006586
6587 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006588 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006589 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006590 final Phone phone = getPhone(subId);
6591 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006592 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006593 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6594 }
6595 UiccProfile profile =
6596 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6597 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006598 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006599 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6600 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006601 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006602 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006603 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006604 }
6605
6606 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006607 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6608 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006609 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006610 }
6611
6612 int phoneId = SubscriptionManager.getPhoneId(subId);
6613 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006614 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006615 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006616 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6617 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006618 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6619 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6620 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006621 }
6622
6623 @Override
6624 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006625 if (TextUtils.isEmpty(pkgName))
6626 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006627 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6628 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6629 UiccCard card = UiccController.getInstance().getUiccCard(i);
6630 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006631 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006632 continue;
6633 }
6634
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006635 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6636 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6637 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006638 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6639 break;
6640 }
6641 }
6642
6643 return result;
Junda Liu29340342014-07-10 15:23:27 -07006644 }
Derek Tan89e89d42014-07-08 17:00:10 -07006645
6646 @Override
Junda Liue64de782015-04-16 17:19:16 -07006647 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6648 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6649 loge("phoneId " + phoneId + " is not valid.");
6650 return null;
6651 }
6652 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006653 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006654 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006655 return null ;
6656 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006657 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006658 }
6659
Amith Yamasani6e118872016-02-19 12:53:51 -08006660 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006661 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006662 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006663 List<String> privilegedPackages = new ArrayList<>();
6664 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006665 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6666 // has UICC in that slot.
6667 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006668 if (card.hasCarrierPrivilegeRules()) {
6669 if (packages == null) {
6670 // Only check packages in user 0 for now
6671 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006672 PackageManager.MATCH_DISABLED_COMPONENTS
6673 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006674 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006675 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006676 }
6677 for (int p = packages.size() - 1; p >= 0; p--) {
6678 PackageInfo pkgInfo = packages.get(p);
6679 if (pkgInfo != null && pkgInfo.packageName != null
6680 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006681 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006682 privilegedPackages.add(pkgInfo.packageName);
6683 }
6684 }
6685 }
6686 }
6687 return privilegedPackages;
6688 }
6689
chen xuf7e9fe82019-05-09 19:31:02 -07006690 @Override
6691 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006692 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6693
6694 final long identity = Binder.clearCallingIdentity();
6695
chen xuf7e9fe82019-05-09 19:31:02 -07006696 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006697 try {
6698 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6699 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6700 }
6701 } finally {
6702 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006703 }
6704 return privilegedPackages;
6705 }
6706
Wink Savilleb564aae2014-10-23 10:18:09 -07006707 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006708 final Phone phone = getPhone(subId);
6709 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006710 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006711 return null;
6712 }
6713 String iccId = card.getIccId();
6714 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006715 return null;
6716 }
6717 return iccId;
6718 }
6719
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006720 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006721 public void setCallComposerStatus(int subId, int status) {
6722 enforceModifyPermission();
6723
6724 final long identity = Binder.clearCallingIdentity();
6725 try {
6726 Phone phone = getPhone(subId);
6727 if (phone != null) {
6728 Phone defaultPhone = phone.getImsPhone();
6729 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6730 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6731 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006732 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6733 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006734 }
6735 }
Shuo Qiand8782462020-12-22 19:10:14 -08006736 } catch (ImsException e) {
6737 throw new ServiceSpecificException(e.getCode());
6738 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006739 Binder.restoreCallingIdentity(identity);
6740 }
6741 }
6742
6743 @Override
6744 public int getCallComposerStatus(int subId) {
6745 enforceReadPrivilegedPermission("getCallComposerStatus");
6746
6747 final long identity = Binder.clearCallingIdentity();
6748 try {
6749 Phone phone = getPhone(subId);
6750 if (phone != null) {
6751 Phone defaultPhone = phone.getImsPhone();
6752 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6753 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6754 return imsPhone.getCallComposerStatus();
6755 }
6756 }
6757 } finally {
6758 Binder.restoreCallingIdentity(identity);
6759 }
6760 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6761 }
6762
6763 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006764 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6765 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006766 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006767 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006768
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769 final long identity = Binder.clearCallingIdentity();
6770 try {
6771 final String iccId = getIccId(subId);
6772 final Phone phone = getPhone(subId);
6773 if (phone == null) {
6774 return false;
6775 }
6776 final String subscriberId = phone.getSubscriberId();
6777
6778 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006779 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006780 + subscriberId + " to " + number);
6781 }
6782
6783 if (TextUtils.isEmpty(iccId)) {
6784 return false;
6785 }
6786
6787 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6788
6789 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6790 if (alphaTag == null) {
6791 editor.remove(alphaTagPrefKey);
6792 } else {
6793 editor.putString(alphaTagPrefKey, alphaTag);
6794 }
6795
6796 // Record both the line number and IMSI for this ICCID, since we need to
6797 // track all merged IMSIs based on line number
6798 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6799 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6800 if (number == null) {
6801 editor.remove(numberPrefKey);
6802 editor.remove(subscriberPrefKey);
6803 } else {
6804 editor.putString(numberPrefKey, number);
6805 editor.putString(subscriberPrefKey, subscriberId);
6806 }
6807
6808 editor.commit();
6809 return true;
6810 } finally {
6811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006812 }
Derek Tan7226c842014-07-02 17:42:23 -07006813 }
6814
6815 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006816 public String getLine1NumberForDisplay(int subId, String callingPackage,
6817 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006818 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006819 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006820 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006821 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006822 return null;
6823 }
Derek Tan97ebb422014-09-05 16:55:38 -07006824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 final long identity = Binder.clearCallingIdentity();
6826 try {
6827 String iccId = getIccId(subId);
6828 if (iccId != null) {
6829 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6830 if (DBG_MERGE) {
6831 log("getLine1NumberForDisplay returning "
6832 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6833 }
6834 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6837 return null;
6838 } finally {
6839 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006840 }
Derek Tan7226c842014-07-02 17:42:23 -07006841 }
6842
6843 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006844 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6845 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006846 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006847 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006848 return null;
6849 }
Derek Tan97ebb422014-09-05 16:55:38 -07006850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851 final long identity = Binder.clearCallingIdentity();
6852 try {
6853 String iccId = getIccId(subId);
6854 if (iccId != null) {
6855 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6856 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6857 }
6858 return null;
6859 } finally {
6860 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006861 }
Derek Tan7226c842014-07-02 17:42:23 -07006862 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006863
6864 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006865 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6866 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006867 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6868 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006870 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006871 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006872 return null;
6873 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006874
Jordan Liub49b04b2019-05-06 14:45:15 -07006875 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6876 // the process, where TelephonyManager was instantiated.
6877 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006878 final long identity = Binder.clearCallingIdentity();
6879 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006880 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 final TelephonyManager tele = TelephonyManager.from(context);
6882 final SubscriptionManager sub = SubscriptionManager.from(context);
6883
6884 // Figure out what subscribers are currently active
6885 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886
Jordan Liub49b04b2019-05-06 14:45:15 -07006887 // Only consider subs which match the current subId
6888 // This logic can be simplified. See b/131189269 for progress.
6889 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006890 activeSubscriberIds.add(tele.getSubscriberId(subId));
6891 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006892
6893 // First pass, find a number override for an active subscriber
6894 String mergeNumber = null;
6895 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6896 for (String key : prefs.keySet()) {
6897 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6898 final String subscriberId = (String) prefs.get(key);
6899 if (activeSubscriberIds.contains(subscriberId)) {
6900 final String iccId = key.substring(
6901 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6902 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6903 mergeNumber = (String) prefs.get(numberKey);
6904 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006905 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906 + " for active subscriber " + subscriberId);
6907 }
6908 if (!TextUtils.isEmpty(mergeNumber)) {
6909 break;
6910 }
6911 }
6912 }
6913 }
6914
6915 // Shortcut when no active merged subscribers
6916 if (TextUtils.isEmpty(mergeNumber)) {
6917 return null;
6918 }
6919
6920 // Second pass, find all subscribers under that line override
6921 final ArraySet<String> result = new ArraySet<>();
6922 for (String key : prefs.keySet()) {
6923 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6924 final String number = (String) prefs.get(key);
6925 if (mergeNumber.equals(number)) {
6926 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6927 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6928 final String subscriberId = (String) prefs.get(subscriberKey);
6929 if (!TextUtils.isEmpty(subscriberId)) {
6930 result.add(subscriberId);
6931 }
6932 }
6933 }
6934 }
6935
6936 final String[] resultArray = result.toArray(new String[result.size()]);
6937 Arrays.sort(resultArray);
6938 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006939 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006940 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6941 }
6942 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006943 } finally {
6944 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006945 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006946 }
6947
6948 @Override
zoey chen38003472019-12-13 17:16:31 +08006949 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6950 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006951
6952 final long identity = Binder.clearCallingIdentity();
6953 try {
6954 final TelephonyManager telephonyManager = mApp.getSystemService(
6955 TelephonyManager.class);
6956 String subscriberId = telephonyManager.getSubscriberId(subId);
6957 if (subscriberId == null) {
6958 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006959 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006960 + subId);
6961 }
6962 return null;
6963 }
6964
6965 final SubscriptionInfo info = SubscriptionController.getInstance()
6966 .getSubscriptionInfo(subId);
6967 final ParcelUuid groupUuid = info.getGroupUuid();
6968 // If it doesn't belong to any group, return just subscriberId of itself.
6969 if (groupUuid == null) {
6970 return new String[]{subscriberId};
6971 }
6972
6973 // Get all subscriberIds from the group.
6974 final List<String> mergedSubscriberIds = new ArrayList<>();
6975 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006976 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006977 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006978 for (SubscriptionInfo subInfo : groupInfos) {
6979 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6980 if (subscriberId != null) {
6981 mergedSubscriberIds.add(subscriberId);
6982 }
6983 }
6984
6985 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6986 } finally {
6987 Binder.restoreCallingIdentity(identity);
6988
6989 }
6990 }
6991
6992 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006993 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006994 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006995 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996
6997 final long identity = Binder.clearCallingIdentity();
6998 try {
6999 final Phone phone = getPhone(subId);
7000 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7001 } finally {
7002 Binder.restoreCallingIdentity(identity);
7003 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007004 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007005
7006 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007007 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007008 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7009 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08007010 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7011 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012
7013 final long identity = Binder.clearCallingIdentity();
7014 try {
7015 final Phone phone = getPhone(subId);
7016 if (phone == null) {
7017 return false;
7018 }
7019 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7020 cdmaNonRoamingList);
7021 } finally {
7022 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007023 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007024 }
7025
7026 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007027 @Deprecated
7028 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7029 enforceModifyPermission();
7030
7031 int returnValue = 0;
7032 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007033 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007034 if(result.exception == null) {
7035 if (result.result != null) {
7036 byte[] responseData = (byte[])(result.result);
7037 if(responseData.length > oemResp.length) {
7038 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7039 responseData.length + "bytes. Buffer Size is " +
7040 oemResp.length + "bytes.");
7041 }
7042 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7043 returnValue = responseData.length;
7044 }
7045 } else {
7046 CommandException ex = (CommandException) result.exception;
7047 returnValue = ex.getCommandError().ordinal();
7048 if(returnValue > 0) returnValue *= -1;
7049 }
7050 } catch (RuntimeException e) {
7051 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7052 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7053 if(returnValue > 0) returnValue *= -1;
7054 }
7055
7056 return returnValue;
7057 }
7058
7059 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007060 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007061 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007062 try {
7063 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007064 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007065 mApp, phone.getSubId(), "getRadioAccessFamily");
7066 } catch (SecurityException e) {
7067 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7068 throw e;
7069 }
chen xub97461a2018-10-26 14:17:57 -07007070 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007071 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007072 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 final long identity = Binder.clearCallingIdentity();
7075 try {
chen xub97461a2018-10-26 14:17:57 -07007076 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007077 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007078 mApp, phone.getSubId(), "getRadioAccessFamily");
7079 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 } finally {
7081 Binder.restoreCallingIdentity(identity);
7082 }
chen xub97461a2018-10-26 14:17:57 -07007083 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007084 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007085
7086 @Override
7087 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007088 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007089 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007090
7091 final long identity = Binder.clearCallingIdentity();
7092 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007093 ImsManager.getInstance(defaultPhone.getContext(),
7094 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 } finally {
7096 Binder.restoreCallingIdentity(identity);
7097 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007098 }
7099
7100 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007101 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007102 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007103 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7104 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007105 return false;
7106 }
Svet Ganovb320e182015-04-16 12:30:10 -07007107
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108 final long identity = Binder.clearCallingIdentity();
7109 try {
7110 // Check the user preference and the system-level IMS setting. Even if the user has
7111 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7112 // In the long run, we may instead need to check if there exists a connection service
7113 // which can support video calling.
7114 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007115 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 return imsManager.isVtEnabledByPlatform()
7117 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7118 && imsManager.isVtEnabledByUser();
7119 } finally {
7120 Binder.restoreCallingIdentity(identity);
7121 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007122 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007123
Andrew Leea1239f22015-03-02 17:44:07 -08007124 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007125 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7126 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007128 mApp, subId, callingPackage, callingFeatureId,
7129 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130 return false;
7131 }
7132
7133 final long identity = Binder.clearCallingIdentity();
7134 try {
7135 CarrierConfigManager configManager =
7136 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007137 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7139 } finally {
7140 Binder.restoreCallingIdentity(identity);
7141 }
Andrew Leea1239f22015-03-02 17:44:07 -08007142 }
7143
7144 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007145 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007147 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148 return false;
7149 }
7150
7151 final long identity = Binder.clearCallingIdentity();
7152 try {
7153 CarrierConfigManager configManager =
7154 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007155 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7157 } finally {
7158 Binder.restoreCallingIdentity(identity);
7159 }
Andrew Leea1239f22015-03-02 17:44:07 -08007160 }
7161
Andrew Lee9431b832015-03-09 18:46:45 -07007162 @Override
7163 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007164 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007165 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007166 }
7167
7168 @Override
7169 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170 final long identity = Binder.clearCallingIdentity();
7171 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007172 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 } finally {
7174 Binder.restoreCallingIdentity(identity);
7175 }
Andrew Lee9431b832015-03-09 18:46:45 -07007176 }
7177
Hall Liuf6668912018-10-31 17:05:23 -07007178 /**
7179 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7180 * support for the feature and device firmware support.
7181 *
7182 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7183 */
7184 @Override
7185 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007186 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007187 final Phone phone = getPhone(subscriptionId);
7188 if (phone == null) {
7189 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7190 return false;
7191 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007193 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7195 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007196 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 return isCarrierSupported && isDeviceSupported;
7198 } finally {
7199 Binder.restoreCallingIdentity(identity);
7200 }
Hall Liu98187582018-01-22 19:15:32 -08007201 }
7202
Hall Liuf6668912018-10-31 17:05:23 -07007203 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007204 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7205 * RTT setting, will return true if the device and carrier both support RTT.
7206 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007207 */
7208 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 final long identity = Binder.clearCallingIdentity();
7210 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007211 boolean isRttSupported = isRttSupported(subscriptionId);
7212 boolean isUserRttSettingOn = Settings.Secure.getInt(
7213 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7214 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7215 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7216 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 } finally {
7218 Binder.restoreCallingIdentity(identity);
7219 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007220 }
7221
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007222 @Deprecated
7223 @Override
7224 public String getDeviceId(String callingPackage) {
7225 return getDeviceIdWithFeature(callingPackage, null);
7226 }
7227
Sanket Padawe7310cc72015-01-14 09:53:20 -08007228 /**
7229 * Returns the unique device ID of phone, for example, the IMEI for
7230 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7231 *
7232 * <p>Requires Permission:
7233 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7234 */
7235 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007236 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007237 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007238 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007239 return null;
7240 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007241 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007242 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007243 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007244 return null;
7245 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246
7247 final long identity = Binder.clearCallingIdentity();
7248 try {
7249 return phone.getDeviceId();
7250 } finally {
7251 Binder.restoreCallingIdentity(identity);
7252 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007253 }
7254
Ping Sunc67b7c22016-03-02 19:16:45 +08007255 /**
7256 * {@hide}
7257 * Returns the IMS Registration Status on a particular subid
7258 *
7259 * @param subId
7260 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007261 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007262 Phone phone = getPhone(subId);
7263 if (phone != null) {
7264 return phone.isImsRegistered();
7265 } else {
7266 return false;
7267 }
7268 }
7269
Santos Cordon7a1885b2015-02-03 11:15:19 -08007270 @Override
7271 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 final long identity = Binder.clearCallingIdentity();
7273 try {
7274 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7275 } finally {
7276 Binder.restoreCallingIdentity(identity);
7277 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007278 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007279
Tyler Gunnf70ed162019-04-03 15:28:53 -07007280 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007281 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007282 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007284 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007285 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7286 }
7287 final long identity = Binder.clearCallingIdentity();
7288 try {
7289 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292 }
7293 }
7294
7295 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007296 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007297 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7298 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007299 final long identity = Binder.clearCallingIdentity();
7300 try {
7301 Phone phone = getPhone(subscriptionId);
7302 if (phone == null) {
7303 return null;
7304 }
7305 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7306 } finally {
7307 Binder.restoreCallingIdentity(identity);
7308 }
7309 }
7310
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007311 /**
7312 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007313 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007314 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 Phone phone = getPhone(subId);
7318 if (phone != null) {
7319 return phone.isWifiCallingEnabled();
7320 } else {
7321 return false;
7322 }
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007325 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007326 }
7327
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007328 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007329 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007330 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007331 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332 final long identity = Binder.clearCallingIdentity();
7333 try {
7334 Phone phone = getPhone(subId);
7335 if (phone != null) {
7336 return phone.isVideoEnabled();
7337 } else {
7338 return false;
7339 }
7340 } finally {
7341 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007342 }
7343 }
7344
7345 /**
7346 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7347 * defined in {@link ImsRegistrationImplBase}.
7348 */
7349 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 final long identity = Binder.clearCallingIdentity();
7351 try {
7352 Phone phone = getPhone(subId);
7353 if (phone != null) {
7354 return phone.getImsRegistrationTech();
7355 } else {
7356 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7357 }
7358 } finally {
7359 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007360 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007361 }
7362
Stuart Scott8eef64f2015-04-08 15:13:54 -07007363 @Override
7364 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007365 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007366 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7367 return;
7368 }
7369
Svet Ganovcc087f82015-05-12 20:35:54 -07007370 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007371
Svet Ganovcc087f82015-05-12 20:35:54 -07007372 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007373 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7374 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007375 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007376 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007377 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007378 Phone phone = getPhone(subId);
SongFerngWang51ee2b12021-05-27 22:44:54 +08007379 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007380 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7381 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007382 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007383 // There has been issues when Sms raw table somehow stores orphan
7384 // fragments. They lead to garbled message when new fragments come
7385 // in and combined with those stale ones. In case this happens again,
7386 // user can reset all network settings which will clean up this table.
7387 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007388 // Clean up IMS settings as well here.
7389 int slotId = getSlotIndex(subId);
7390 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7391 ImsManager.getInstance(mApp, slotId).factoryReset();
7392 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007393
7394 // Erase modem config if erase modem on network setting is enabled.
7395 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7396 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7397 if (configValue != null && Boolean.parseBoolean(configValue)) {
7398 sendEraseModemConfig(getDefaultPhone());
7399 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007400 } finally {
7401 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007402 }
7403 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007404
SongFerngWang51ee2b12021-05-27 22:44:54 +08007405 @VisibleForTesting
7406 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7407 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7408 return;
7409 }
7410 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7411 RILConstants.PREFERRED_NETWORK_MODE);
7412 SubscriptionManager.setSubscriptionProperty(subId,
7413 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7414 "user=" + defaultNetworkType);
7415 phone.loadAllowedNetworksFromSubscriptionDatabase();
7416 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7417 defaultNetworkType, null);
7418 }
7419
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007420 private void cleanUpSmsRawTable(Context context) {
7421 ContentResolver resolver = context.getContentResolver();
7422 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7423 resolver.delete(uri, null, null);
7424 }
7425
Narayan Kamath1c496c22015-04-16 14:40:19 +01007426 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007427 public String getSimLocaleForSubscriber(int subId) {
7428 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7429 final Phone phone = getPhone(subId);
7430 if (phone == null) {
7431 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007432 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007433 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 final long identity = Binder.clearCallingIdentity();
7435 try {
chen xu5d3637b2019-01-21 23:31:38 -08007436 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007437 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007438 if (info == null) {
7439 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7440 return null;
7441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 // Try and fetch the locale from the carrier properties or from the SIM language
7443 // preferences (EF-PL and EF-LI)...
7444 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007446 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7447 if (localeFromDefaultSim != null) {
7448 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7449 if (DBG) log("Using locale from subId: " + subId + " locale: "
7450 + localeFromDefaultSim);
7451 return localeFromDefaultSim.toLanguageTag();
7452 } else {
7453 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 }
7455 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 // The SIM language preferences only store a language (e.g. fr = French), not an
7458 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7459 // the SIM and carrier preferences does not include a country we add the country
7460 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007461 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007463 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 return mccLocale.toLanguageTag();
7465 }
7466
7467 if (DBG) log("No locale found - returning null");
7468 return null;
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007472 }
7473
7474 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007475 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007476 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007477 }
7478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 /**
7480 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7481 */
7482 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007483 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007484 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007485 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007486
Chenjie Yu1ba97252018-01-11 18:16:20 -08007487 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liue8315982020-10-09 19:00:11 -07007488 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007489
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007490 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007491 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7492 * representing the state of the modem.
7493 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007494 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7495 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007496 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007497 */
7498 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007499 public void requestModemActivityInfo(ResultReceiver result) {
7500 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007501 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502
7503 final long identity = Binder.clearCallingIdentity();
7504 try {
sqian1a1be542020-03-05 11:37:28 -08007505 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506 } finally {
7507 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007508 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007509 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007510
Siddharth Rayb8114062018-06-17 15:02:38 -07007511 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7512 // less than total activity duration.
7513 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7514 if (info == null) {
7515 return false;
7516 }
7517 int activityDurationMs =
Hall Liue8315982020-10-09 19:00:11 -07007518 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7519 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7520
Siddharth Rayb8114062018-06-17 15:02:38 -07007521 return (info.isValid()
7522 && (info.getSleepTimeMillis() <= activityDurationMs)
7523 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007524 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007525 && (totalTxTimeMs <= activityDurationMs));
7526 }
7527
Jack Yu85bd38a2015-11-09 11:34:32 -08007528 /**
7529 * {@hide}
7530 * Returns the service state information on specified subscription.
7531 */
7532 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007533 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7534 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007536 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007537 return null;
7538 }
7539
Hall Liuf19c44f2018-11-27 14:38:17 -08007540 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7541 LocationAccessPolicy.checkLocationPermission(mApp,
7542 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7543 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007544 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007545 .setCallingPid(Binder.getCallingPid())
7546 .setCallingUid(Binder.getCallingUid())
7547 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007548 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007549 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007550 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7551 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007552 .build());
7553
7554 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7555 LocationAccessPolicy.checkLocationPermission(mApp,
7556 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7557 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007558 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007559 .setCallingPid(Binder.getCallingPid())
7560 .setCallingUid(Binder.getCallingUid())
7561 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007562 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007563 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007564 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7565 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007566 .build());
7567 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7568 boolean hasFinePermission =
7569 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7570 boolean hasCoarsePermission =
7571 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 final long identity = Binder.clearCallingIdentity();
7574 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007575 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7576 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7577 Rlog.d(LOG_TAG,
7578 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7579 return null;
7580 }
7581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582 final Phone phone = getPhone(subId);
7583 if (phone == null) {
7584 return null;
7585 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007586
Hall Liuf19c44f2018-11-27 14:38:17 -08007587 ServiceState ss = phone.getServiceState();
7588
7589 // Scrub out the location info in ServiceState depending on what level of access
7590 // the caller has.
7591 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007592 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7593 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007594 } finally {
7595 Binder.restoreCallingIdentity(identity);
7596 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007597 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007598
7599 /**
7600 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7601 *
7602 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7603 * voicemail ringtone.
7604 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7605 * PhoneAccount.
7606 */
7607 @Override
7608 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 final long identity = Binder.clearCallingIdentity();
7610 try {
7611 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7612 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007613 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007615
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007616 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
7619 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007620 }
7621
7622 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007623 * Sets the per-account voicemail ringtone.
7624 *
7625 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7626 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7627 *
7628 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7629 * voicemail ringtone.
7630 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7631 * PhoneAccount.
7632 */
7633 @Override
7634 public void setVoicemailRingtoneUri(String callingPackage,
7635 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007636 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007637 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007638 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7639 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7641 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7642 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007644
7645 final long identity = Binder.clearCallingIdentity();
7646 try {
7647 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7648 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007649 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007650 }
7651 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007654 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007655 }
7656
7657 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007658 * Returns whether vibration is set for voicemail notification in Phone settings.
7659 *
7660 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7661 * voicemail vibration setting.
7662 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7663 */
7664 @Override
7665 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 final long identity = Binder.clearCallingIdentity();
7667 try {
7668 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7669 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007670 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7674 } finally {
7675 Binder.restoreCallingIdentity(identity);
7676 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007677 }
7678
Youhan Wange64578a2016-05-02 15:32:42 -07007679 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007680 * Sets the per-account voicemail vibration.
7681 *
7682 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7683 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7684 *
7685 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7686 * voicemail vibration setting.
7687 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7688 * specific PhoneAccount.
7689 */
7690 @Override
7691 public void setVoicemailVibrationEnabled(String callingPackage,
7692 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007693 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007694 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007695 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7696 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7698 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7699 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007700 }
7701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702 final long identity = Binder.clearCallingIdentity();
7703 try {
7704 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7705 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007706 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707 }
7708 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7709 } finally {
7710 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007711 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007712 }
7713
7714 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007715 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7716 *
7717 * @throws SecurityException if the caller does not have the required permission
7718 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007719 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007720 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007721 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007722 }
7723
7724 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007725 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7726 * permission.
7727 *
7728 * @throws SecurityException if the caller does not have the required permission
7729 */
7730 private void enforceSendSmsPermission() {
7731 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7732 }
7733
7734 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007735 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007736 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007737 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007738 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007739 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 final long identity = Binder.clearCallingIdentity();
7741 try {
7742 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007743 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007744 if (componentName == null) {
7745 throw new SecurityException(
7746 "Caller not current active visual voicemail package[null]");
7747 }
7748 String vvmPackage = componentName.getPackageName();
7749 if (!callingPackage.equals(vvmPackage)) {
7750 throw new SecurityException("Caller not current active visual voicemail package["
7751 + vvmPackage + "]");
7752 }
7753 } finally {
7754 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007755 }
7756 }
7757
7758 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007759 * Return the application ID for the app type.
7760 *
7761 * @param subId the subscription ID that this request applies to.
7762 * @param appType the uicc app type.
7763 * @return Application ID for specificied app type, or null if no uicc.
7764 */
7765 @Override
7766 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007767 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007768 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769
7770 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007771 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007772 if (phone == null) {
7773 return null;
7774 }
7775 String aid = null;
7776 try {
7777 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7778 .getApplicationByType(appType).getAid();
7779 } catch (Exception e) {
7780 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7781 }
7782 return aid;
7783 } finally {
7784 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007785 }
Youhan Wange64578a2016-05-02 15:32:42 -07007786 }
7787
Youhan Wang4001d252016-05-11 10:29:41 -07007788 /**
7789 * Return the Electronic Serial Number.
7790 *
7791 * @param subId the subscription ID that this request applies to.
7792 * @return ESN or null if error.
7793 */
7794 @Override
7795 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007796 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007797 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798
7799 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007800 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 if (phone == null) {
7802 return null;
7803 }
7804 String esn = null;
7805 try {
7806 esn = phone.getEsn();
7807 } catch (Exception e) {
7808 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7809 }
7810 return esn;
7811 } finally {
7812 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007813 }
Youhan Wang4001d252016-05-11 10:29:41 -07007814 }
7815
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007816 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007817 * Return the Preferred Roaming List Version.
7818 *
7819 * @param subId the subscription ID that this request applies to.
7820 * @return PRLVersion or null if error.
7821 */
7822 @Override
7823 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007824 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007825 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826
7827 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007828 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829 if (phone == null) {
7830 return null;
7831 }
7832 String cdmaPrlVersion = null;
7833 try {
7834 cdmaPrlVersion = phone.getCdmaPrlVersion();
7835 } catch (Exception e) {
7836 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7837 }
7838 return cdmaPrlVersion;
7839 } finally {
7840 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007841 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007842 }
7843
7844 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007845 * Get snapshot of Telephony histograms
7846 * @return List of Telephony histograms
7847 * @hide
7848 */
7849 @Override
7850 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7852 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853
7854 final long identity = Binder.clearCallingIdentity();
7855 try {
7856 return RIL.getTelephonyRILTimingHistograms();
7857 } finally {
7858 Binder.restoreCallingIdentity(identity);
7859 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007860 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007861
7862 /**
7863 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007864 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7865 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007866 * Require system privileges. In the future we may add this to carrier APIs.
7867 *
Michele Berionne482f8202018-11-27 18:57:59 -08007868 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007869 */
7870 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007871 @TelephonyManager.SetCarrierRestrictionResult
7872 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007873 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007874 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007875
Michele Berionne482f8202018-11-27 18:57:59 -08007876 if (carrierRestrictionRules == null) {
7877 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007878 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 final long identity = Binder.clearCallingIdentity();
7881 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007882 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007883 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007884 } finally {
7885 Binder.restoreCallingIdentity(identity);
7886 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007887 }
7888
7889 /**
7890 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007891 * Get the allowed carrier list and the excluded carrier list, including the priority between
7892 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007893 * Require system privileges. In the future we may add this to carrier APIs.
7894 *
Michele Berionne482f8202018-11-27 18:57:59 -08007895 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007896 */
7897 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007898 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007899 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007900 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901
7902 final long identity = Binder.clearCallingIdentity();
7903 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007904 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7905 if (response instanceof CarrierRestrictionRules) {
7906 return (CarrierRestrictionRules) response;
7907 }
7908 // Response is an Exception of some kind,
7909 // which is signalled to the user as a NULL retval
7910 return null;
7911 } catch (Exception e) {
7912 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7913 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007914 } finally {
7915 Binder.restoreCallingIdentity(identity);
7916 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007917 }
7918
fionaxu59545b42016-05-25 15:53:37 -07007919 /**
fionaxu59545b42016-05-25 15:53:37 -07007920 * Action set from carrier signalling broadcast receivers to enable/disable radio
7921 * @param subId the subscription ID that this action applies to.
7922 * @param enabled control enable or disable radio.
7923 * {@hide}
7924 */
7925 @Override
7926 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7927 enforceModifyPermission();
7928 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007929
7930 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007931 if (phone == null) {
7932 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7933 return;
7934 }
7935 try {
7936 phone.carrierActionSetRadioEnabled(enabled);
7937 } catch (Exception e) {
7938 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939 } finally {
7940 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007941 }
7942 }
7943
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007944 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007945 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7946 * network status based on which carrier apps could apply actions accordingly,
7947 * enable/disable default url handler for example.
7948 *
7949 * @param subId the subscription ID that this action applies to.
7950 * @param report control start/stop reporting the default network status.
7951 * {@hide}
7952 */
7953 @Override
7954 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7955 enforceModifyPermission();
7956 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957
7958 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007959 if (phone == null) {
7960 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7961 return;
7962 }
7963 try {
7964 phone.carrierActionReportDefaultNetworkStatus(report);
7965 } catch (Exception e) {
7966 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967 } finally {
7968 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007969 }
7970 }
7971
7972 /**
fionaxud9622282017-07-17 17:51:30 -07007973 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7974 * @param subId the subscription ID that this action applies to.
7975 * {@hide}
7976 */
7977 @Override
7978 public void carrierActionResetAll(int subId) {
7979 enforceModifyPermission();
7980 final Phone phone = getPhone(subId);
7981 if (phone == null) {
7982 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7983 return;
7984 }
7985 try {
7986 phone.carrierActionResetAll();
7987 } catch (Exception e) {
7988 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7989 }
7990 }
7991
7992 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007993 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7994 * bug report is being generated.
7995 */
7996 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007997 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007998 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7999 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008000 writer.println("Permission Denial: can't dump Phone from pid="
8001 + Binder.getCallingPid()
8002 + ", uid=" + Binder.getCallingUid()
8003 + "without permission "
8004 + android.Manifest.permission.DUMP);
8005 return;
8006 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008007 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008008 }
Jack Yueb89b242016-06-22 13:27:47 -07008009
Brad Ebingerdac2f002018-04-03 15:17:52 -07008010 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008011 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8012 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8013 @NonNull String[] args) {
8014 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8015 this, in.getFileDescriptor(), out.getFileDescriptor(),
8016 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008017 }
8018
Jack Yueb89b242016-06-22 13:27:47 -07008019 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008020 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07008021 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008022 * @param reason the reason the data enable change is taking place
8023 * @param enabled True if enabling the data, otherwise disabling.
8024 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008025 */
8026 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07008027 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008028 boolean enabled) {
8029 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8030 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8031 try {
8032 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07008033 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008034 } catch (SecurityException se) {
8035 enforceModifyPermission();
8036 }
8037 } else {
8038 enforceModifyPermission();
8039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008040
8041 final long identity = Binder.clearCallingIdentity();
8042 try {
8043 Phone phone = getPhone(subId);
8044 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008045 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8046 phone.carrierActionSetMeteredApnsEnabled(enabled);
8047 } else {
8048 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8049 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008050 }
8051 } finally {
8052 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008053 }
8054 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008055
8056 /**
8057 * Get Client request stats
8058 * @return List of Client Request Stats
8059 * @hide
8060 */
8061 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008062 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8063 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008065 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008066 return null;
8067 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008068 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 final long identity = Binder.clearCallingIdentity();
8071 try {
8072 if (phone != null) {
8073 return phone.getClientRequestStats();
8074 }
8075
8076 return null;
8077 } finally {
8078 Binder.restoreCallingIdentity(identity);
8079 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008080 }
8081
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008082 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008083 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008084 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008085 }
Jack Yueb4124c2017-02-16 15:32:43 -08008086
8087 /**
Grace Chen70990072017-03-24 17:21:30 -07008088 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008089 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008090 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008091 * @param state State of SIM (power down, power up, pass through)
8092 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8093 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8094 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008095 *
8096 **/
8097 @Override
Grace Chen70990072017-03-24 17:21:30 -07008098 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008099 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008100 Phone phone = PhoneFactory.getPhone(slotIndex);
8101
vagdeviaf9a5b92018-08-15 16:01:53 -07008102 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 final long identity = Binder.clearCallingIdentity();
8105 try {
8106 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008107 phone.setSimPowerState(state, null, workSource);
8108 }
8109 } finally {
8110 Binder.restoreCallingIdentity(identity);
8111 }
8112 }
8113
8114 /**
8115 * Set SIM card power state.
8116 *
8117 * @param slotIndex SIM slot id.
8118 * @param state State of SIM (power down, power up, pass through)
8119 * @param callback callback to trigger after success or failure
8120 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8121 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8122 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8123 *
8124 **/
8125 @Override
8126 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8127 IIntegerConsumer callback) {
8128 enforceModifyPermission();
8129 Phone phone = PhoneFactory.getPhone(slotIndex);
8130
8131 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8132
8133 final long identity = Binder.clearCallingIdentity();
8134 try {
8135 if (phone != null) {
8136 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8137 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008138 }
8139 } finally {
8140 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008141 }
8142 }
Shuo Qiandd210312017-04-12 22:11:33 +00008143
Tyler Gunn65d45c22017-06-05 11:22:26 -07008144 private boolean isUssdApiAllowed(int subId) {
8145 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008146 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008147 if (configManager == null) {
8148 return false;
8149 }
8150 PersistableBundle pb = configManager.getConfigForSubId(subId);
8151 if (pb == null) {
8152 return false;
8153 }
8154 return pb.getBoolean(
8155 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8156 }
8157
Shuo Qiandd210312017-04-12 22:11:33 +00008158 /**
8159 * Check if phone is in emergency callback mode
8160 * @return true if phone is in emergency callback mode
8161 * @param subId sub id
8162 */
goneil9c5f4872017-12-05 14:07:56 -08008163 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008164 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008165 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008166 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008167
8168 final long identity = Binder.clearCallingIdentity();
8169 try {
8170 if (phone != null) {
8171 return phone.isInEcm();
8172 } else {
8173 return false;
8174 }
8175 } finally {
8176 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008177 }
8178 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008179
8180 /**
8181 * Get the current signal strength information for the given subscription.
8182 * Because this information is not updated when the device is in a low power state
8183 * it should not be relied-upon to be current.
8184 * @param subId Subscription index
8185 * @return the most recent cached signal strength info from the modem
8186 */
8187 @Override
8188 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 final long identity = Binder.clearCallingIdentity();
8190 try {
8191 Phone p = getPhone(subId);
8192 if (p == null) {
8193 return null;
8194 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 return p.getSignalStrength();
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
8199 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008200 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008201
Pengquan Meng77b7f132018-08-22 14:49:57 -07008202 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008203 * Get the current modem radio state for the given slot.
8204 * @param slotIndex slot index.
8205 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008206 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008207 * @return the current radio power state from the modem
8208 */
8209 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008210 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008211 Phone phone = PhoneFactory.getPhone(slotIndex);
8212 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008213 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8214 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008215 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8216 }
8217
8218 final long identity = Binder.clearCallingIdentity();
8219 try {
8220 return phone.getRadioPowerState();
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
8223 }
8224 }
8225 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8226 }
8227
8228 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008229 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8230 *
8231 * <p>Requires one of the following permissions:
8232 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8233 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8234 * privileges.
8235 *
8236 * @param subId subscription id
8237 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8238 * {@code false}.
8239 */
8240 @Override
8241 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008242 try {
8243 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8244 null);
8245 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008246 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008247 mApp, subId, "isDataRoamingEnabled");
8248 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008249
Pengquan Menga1bb6272018-09-06 09:59:22 -07008250 boolean isEnabled = false;
8251 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008252 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008253 Phone phone = getPhone(subId);
8254 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008255 } finally {
8256 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008257 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008258 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008259 }
8260
8261
8262 /**
8263 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8264 *
8265 * <p> Requires permission:
8266 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8267 * privileges.
8268 *
8269 * @param subId subscription id
8270 * @param isEnabled {@code true} means enable, {@code false} means disable.
8271 */
8272 @Override
8273 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8275 mApp, subId, "setDataRoamingEnabled");
8276
Pengquan Menga1bb6272018-09-06 09:59:22 -07008277 final long identity = Binder.clearCallingIdentity();
8278 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008279 Phone phone = getPhone(subId);
8280 if (phone != null) {
8281 phone.setDataRoamingEnabled(isEnabled);
8282 }
8283 } finally {
8284 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008285 }
8286 }
8287
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008288 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008289 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008290 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008291 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008292 mApp, subId, "isManualNetworkSelectionAllowed");
8293
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008294 boolean isAllowed = true;
8295 final long identity = Binder.clearCallingIdentity();
8296 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008297 Phone phone = getPhone(subId);
8298 if (phone != null) {
8299 isAllowed = phone.isCspPlmnEnabled();
8300 }
8301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
8304 return isAllowed;
8305 }
8306
8307 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008308 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008309 // Verify that tha callingPackage belongs to the calling UID
8310 mApp.getSystemService(AppOpsManager.class)
8311 .checkPackage(Binder.getCallingUid(), callingPackage);
8312
Jordan Liu1e142fc2019-04-22 15:10:43 -07008313 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008314 try {
8315 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008316 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008317 } catch (SecurityException e) {
8318 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8319 // has carrier privileges on an active UICC
8320 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8321 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008322 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008323 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008324 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008325
8326 final long identity = Binder.clearCallingIdentity();
8327 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008328 UiccController uiccController = UiccController.getInstance();
8329 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008330 if (hasReadPermission) {
8331 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008332 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008333
8334 // Remove private info if the caller doesn't have access
8335 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8336 for (UiccCardInfo cardInfo : cardInfos) {
8337 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8338 // is available
8339 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8340 if (card == null || card.getUiccProfile() == null) {
8341 // assume no access if the card or profile is unavailable
8342 filteredInfos.add(cardInfo.getUnprivileged());
8343 continue;
8344 }
8345 UiccProfile profile = card.getUiccProfile();
8346 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8347 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8348 filteredInfos.add(cardInfo);
8349 } else {
8350 filteredInfos.add(cardInfo.getUnprivileged());
8351 }
8352 }
8353 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008354 } finally {
8355 Binder.restoreCallingIdentity(identity);
8356 }
8357 }
8358
8359 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008360 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008361 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363 final long identity = Binder.clearCallingIdentity();
8364 try {
8365 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8366 if (slots == null) {
8367 Rlog.i(LOG_TAG, "slots is null.");
8368 return null;
8369 }
8370
8371 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8372 for (int i = 0; i < slots.length; i++) {
8373 UiccSlot slot = slots[i];
8374 if (slot == null) {
8375 continue;
8376 }
8377
Jordan Liu7be7e652019-05-06 18:55:02 +00008378 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379 UiccCard card = slot.getUiccCard();
8380 if (card != null) {
8381 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008382 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008383 cardId = slot.getEid();
8384 if (TextUtils.isEmpty(cardId)) {
8385 cardId = slot.getIccId();
8386 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008387 }
8388
Jordan Liu857451f2019-05-09 16:35:35 -07008389 if (cardId != null) {
8390 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8391 // if cardId is an EID, it's all digits so this is fine
8392 cardId = IccUtils.stripTrailingFs(cardId);
8393 }
8394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008395 int cardState = 0;
8396 switch (slot.getCardState()) {
8397 case CARDSTATE_ABSENT:
8398 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8399 break;
8400 case CARDSTATE_PRESENT:
8401 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8402 break;
8403 case CARDSTATE_ERROR:
8404 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8405 break;
8406 case CARDSTATE_RESTRICTED:
8407 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8408 break;
8409 default:
8410 break;
8411
8412 }
8413
8414 infos[i] = new UiccSlotInfo(
8415 slot.isActive(),
8416 slot.isEuicc(),
8417 cardId,
8418 cardState,
8419 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008420 slot.isExtendedApduSupported(),
8421 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008422 }
8423 return infos;
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008426 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008427 }
8428
8429 @Override
8430 public boolean switchSlots(int[] physicalSlots) {
8431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008432
8433 final long identity = Binder.clearCallingIdentity();
8434 try {
8435 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8436 } finally {
8437 Binder.restoreCallingIdentity(identity);
8438 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008439 }
Jack Yu4c988042018-02-27 15:30:01 -08008440
8441 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008442 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008443 final long identity = Binder.clearCallingIdentity();
8444 try {
8445 return UiccController.getInstance().getCardIdForDefaultEuicc();
8446 } finally {
8447 Binder.restoreCallingIdentity(identity);
8448 }
8449 }
8450
Pengquan Meng85728fb2018-03-12 16:31:21 -07008451 /**
goneil47ffb6e2018-04-06 15:40:58 -07008452 * A test API to reload the UICC profile.
8453 *
8454 * <p>Requires that the calling app has permission
8455 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8456 * @hide
8457 */
8458 @Override
8459 public void refreshUiccProfile(int subId) {
8460 enforceModifyPermission();
8461
8462 final long identity = Binder.clearCallingIdentity();
8463 try {
8464 Phone phone = getPhone(subId);
8465 if (phone == null) {
8466 return;
8467 }
8468 UiccCard uiccCard = phone.getUiccCard();
8469 if (uiccCard == null) {
8470 return;
8471 }
8472 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8473 if (uiccProfile == null) {
8474 return;
8475 }
8476 uiccProfile.refresh();
8477 } finally {
8478 Binder.restoreCallingIdentity(identity);
8479 }
8480 }
8481
8482 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008483 * Returns false if the mobile data is disabled by default, otherwise return true.
8484 */
8485 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008486 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008487 }
8488
8489 /**
8490 * Returns true if the data roaming is enabled by default, i.e the system property
8491 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8492 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8493 */
8494 private boolean getDefaultDataRoamingEnabled(int subId) {
8495 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008496 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008497 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008498 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8499 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8500 return isDataRoamingEnabled;
8501 }
8502
8503 /**
8504 * Returns the default network type for the given {@code subId}, if the default network type is
8505 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8506 */
8507 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008508 List<Integer> list = TelephonyProperties.default_network();
8509 int phoneId = mSubscriptionController.getPhoneId(subId);
8510 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8511 return list.get(phoneId);
8512 }
8513 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008514 }
fionaxua13278b2018-03-21 00:08:13 -07008515
8516 @Override
8517 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008518 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008519 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520
8521 final long identity = Binder.clearCallingIdentity();
8522 try {
8523 final Phone phone = getPhone(subId);
8524 if (phone == null) {
8525 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8526 return;
8527 }
chen xueaba88a2019-03-15 13:15:10 -07008528 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8529 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008530 if (carrierPrivilegeRules == null) {
8531 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8532 } else {
8533 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008535 } finally {
8536 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008537 }
fionaxua13278b2018-03-21 00:08:13 -07008538 }
8539
8540 @Override
8541 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008542 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543
8544 final long identity = Binder.clearCallingIdentity();
8545 try {
8546 final Phone phone = getPhone(subId);
8547 if (phone == null) {
8548 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8549 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8550 }
8551 return phone.getCarrierIdListVersion();
8552 } finally {
8553 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008554 }
fionaxua13278b2018-03-21 00:08:13 -07008555 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008556
8557 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008558 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8559 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008560 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008561 mApp, subId, callingPackage, callingFeatureId,
8562 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008563 return -1;
8564 }
8565
8566 final long identity = Binder.clearCallingIdentity();
8567 try {
8568 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8569 } finally {
8570 Binder.restoreCallingIdentity(identity);
8571 }
8572 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008573
8574 @Override
8575 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008576 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008577 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008578 mApp, subId, "getCdmaRoamingMode");
8579
8580 final long identity = Binder.clearCallingIdentity();
8581 try {
8582 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8583 } finally {
8584 Binder.restoreCallingIdentity(identity);
8585 }
8586 }
8587
8588 @Override
8589 public boolean setCdmaRoamingMode(int subId, int mode) {
8590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8591 mApp, subId, "setCdmaRoamingMode");
8592
8593 final long identity = Binder.clearCallingIdentity();
8594 try {
8595 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8596 } finally {
8597 Binder.restoreCallingIdentity(identity);
8598 }
8599 }
8600
8601 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008602 public int getCdmaSubscriptionMode(int subId) {
8603 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008604 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008605 mApp, subId, "getCdmaSubscriptionMode");
8606
8607 final long identity = Binder.clearCallingIdentity();
8608 try {
8609 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8610 } finally {
8611 Binder.restoreCallingIdentity(identity);
8612 }
8613 }
8614
8615 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008616 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8618 mApp, subId, "setCdmaSubscriptionMode");
8619
8620 final long identity = Binder.clearCallingIdentity();
8621 try {
8622 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8623 } finally {
8624 Binder.restoreCallingIdentity(identity);
8625 }
8626 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008627
sqianc5eccab2018-10-19 18:46:41 -07008628 @Override
sqian8c685422019-02-22 15:55:18 -08008629 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008630 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008632 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8633 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008634 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8635 }
8636 final long identity = Binder.clearCallingIdentity();
8637 try {
sqian854d44b2018-12-12 16:48:18 -08008638 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8639 for (Phone phone: PhoneFactory.getPhones()) {
8640 if (phone.getEmergencyNumberTracker() != null
8641 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8642 emergencyNumberListInternal.put(
8643 phone.getSubId(),
8644 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8645 }
sqian11b7a0e2018-12-05 18:48:28 -08008646 }
sqian854d44b2018-12-12 16:48:18 -08008647 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008648 } finally {
8649 Binder.restoreCallingIdentity(identity);
8650 }
sqianc5eccab2018-10-19 18:46:41 -07008651 }
8652
8653 @Override
sqian8c685422019-02-22 15:55:18 -08008654 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008655 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008656 if (!exactMatch) {
8657 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008658 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008659 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008660 }
8661 final long identity = Binder.clearCallingIdentity();
8662 try {
sqian854d44b2018-12-12 16:48:18 -08008663 for (Phone phone: PhoneFactory.getPhones()) {
8664 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008665 && phone.getEmergencyNumberTracker()
8666 .isEmergencyNumber(number, exactMatch)) {
8667 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008668 }
sqian11b7a0e2018-12-05 18:48:28 -08008669 }
8670 return false;
8671 } finally {
8672 Binder.restoreCallingIdentity(identity);
8673 }
8674 }
8675
sqianf4ca7ed2019-01-15 18:32:07 -08008676 /**
Shuo Qian479dd9e2021-02-22 18:32:21 -08008677 * Start emergency callback mode for GsmCdmaPhone for testing.
8678 */
8679 @Override
8680 public void startEmergencyCallbackMode() {
8681 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8682 "startEmergencyCallbackMode");
8683 enforceModifyPermission();
8684 final long identity = Binder.clearCallingIdentity();
8685 try {
8686 for (Phone phone : PhoneFactory.getPhones()) {
8687 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8688 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8689 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8690 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8691 gsmCdmaPhone.obtainMessage(
8692 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8693 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8694 }
8695 }
8696 } finally {
8697 Binder.restoreCallingIdentity(identity);
8698 }
8699 }
8700
8701 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008702 * Update emergency number list for test mode.
8703 */
8704 @Override
8705 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8706 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8707 "updateEmergencyNumberListTestMode");
8708
8709 final long identity = Binder.clearCallingIdentity();
8710 try {
8711 for (Phone phone: PhoneFactory.getPhones()) {
8712 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8713 if (tracker != null) {
8714 tracker.executeEmergencyNumberTestModeCommand(action, num);
8715 }
8716 }
8717 } finally {
8718 Binder.restoreCallingIdentity(identity);
8719 }
8720 }
8721
8722 /**
8723 * Get the full emergency number list for test mode.
8724 */
8725 @Override
8726 public List<String> getEmergencyNumberListTestMode() {
8727 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8728 "getEmergencyNumberListTestMode");
8729
8730 final long identity = Binder.clearCallingIdentity();
8731 try {
8732 Set<String> emergencyNumbers = new HashSet<>();
8733 for (Phone phone: PhoneFactory.getPhones()) {
8734 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8735 if (tracker != null) {
8736 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8737 emergencyNumbers.add(num.getNumber());
8738 }
8739 }
8740 }
8741 return new ArrayList<>(emergencyNumbers);
8742 } finally {
8743 Binder.restoreCallingIdentity(identity);
8744 }
8745 }
8746
chen xud6b45bd2018-10-30 22:27:10 -07008747 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008748 public int getEmergencyNumberDbVersion(int subId) {
8749 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8750
8751 final long identity = Binder.clearCallingIdentity();
8752 try {
8753 final Phone phone = getPhone(subId);
8754 if (phone == null) {
8755 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8756 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8757 }
8758 return phone.getEmergencyNumberDbVersion();
8759 } finally {
8760 Binder.restoreCallingIdentity(identity);
8761 }
8762 }
8763
8764 @Override
8765 public void notifyOtaEmergencyNumberDbInstalled() {
8766 enforceModifyPermission();
8767
8768 final long identity = Binder.clearCallingIdentity();
8769 try {
8770 for (Phone phone: PhoneFactory.getPhones()) {
8771 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8772 if (tracker != null) {
8773 tracker.updateOtaEmergencyNumberDatabase();
8774 }
8775 }
8776 } finally {
8777 Binder.restoreCallingIdentity(identity);
8778 }
8779 }
8780
8781 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008782 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008783 enforceActiveEmergencySessionPermission();
8784
8785 final long identity = Binder.clearCallingIdentity();
8786 try {
8787 for (Phone phone: PhoneFactory.getPhones()) {
8788 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8789 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008790 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8791 }
8792 }
8793 } finally {
8794 Binder.restoreCallingIdentity(identity);
8795 }
8796 }
8797
8798 @Override
8799 public void resetOtaEmergencyNumberDbFilePath() {
8800 enforceActiveEmergencySessionPermission();
8801
8802 final long identity = Binder.clearCallingIdentity();
8803 try {
8804 for (Phone phone: PhoneFactory.getPhones()) {
8805 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8806 if (tracker != null) {
8807 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008808 }
8809 }
8810 } finally {
8811 Binder.restoreCallingIdentity(identity);
8812 }
8813 }
8814
8815 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008816 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8817 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8818 Phone phone = getPhone(subId);
8819 if (phone == null) {
8820 return null;
8821 }
8822 final long identity = Binder.clearCallingIdentity();
8823 try {
8824 UiccProfile profile = UiccController.getInstance()
8825 .getUiccProfileForPhone(phone.getPhoneId());
8826 if (profile != null) {
8827 return profile.getCertsFromCarrierPrivilegeAccessRules();
8828 }
8829 } finally {
8830 Binder.restoreCallingIdentity(identity);
8831 }
8832 return null;
8833 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008834
8835 /**
8836 * Enable or disable a modem stack.
8837 */
8838 @Override
8839 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8840 enforceModifyPermission();
8841
8842 final long identity = Binder.clearCallingIdentity();
8843 try {
8844 Phone phone = PhoneFactory.getPhone(slotIndex);
8845 if (phone == null) {
8846 return false;
8847 } else {
8848 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8849 }
8850 } finally {
8851 Binder.restoreCallingIdentity(identity);
8852 }
8853 }
Michelecea4cf22018-12-21 15:00:11 -08008854
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008855 /**
8856 * Whether a modem stack is enabled or not.
8857 */
8858 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008859 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8860 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008861 Phone phone = PhoneFactory.getPhone(slotIndex);
8862 if (phone == null) return false;
8863
8864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008865 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8866 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008867 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8868 }
8869
8870 final long identity = Binder.clearCallingIdentity();
8871 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008872 try {
8873 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8874 } catch (NoSuchElementException ex) {
8875 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8876 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008877 } finally {
8878 Binder.restoreCallingIdentity(identity);
8879 }
8880 }
8881
Michelecea4cf22018-12-21 15:00:11 -08008882 @Override
Michele0ea7d782019-03-19 14:58:42 -07008883 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008884 enforceModifyPermission();
8885
8886 final long identity = Binder.clearCallingIdentity();
8887 try {
8888 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008889 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008890 .commit();
8891 } finally {
8892 Binder.restoreCallingIdentity(identity);
8893 }
8894 }
8895
8896 @Override
Michele0ea7d782019-03-19 14:58:42 -07008897 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008898 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008899 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008900 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8901 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008902 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008903 }
Michelecea4cf22018-12-21 15:00:11 -08008904
8905 final long identity = Binder.clearCallingIdentity();
8906 try {
Michele0ea7d782019-03-19 14:58:42 -07008907 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008908 } finally {
8909 Binder.restoreCallingIdentity(identity);
8910 }
8911 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008912
Michele0ea7d782019-03-19 14:58:42 -07008913 @TelephonyManager.IsMultiSimSupportedResult
8914 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008915 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8916 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8917 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008918 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8919 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008920 }
8921 // Check if the hardware supports multisim functionality. If usage of multisim is not
8922 // supported by the modem, indicate that it is restricted.
8923 PhoneCapability staticCapability =
8924 mPhoneConfigurationManager.getStaticPhoneCapability();
8925 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008926 loge("isMultiSimSupportedInternal: no static configuration available");
8927 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008928 }
SongFerngWang2c4309d2021-01-17 21:51:44 +08008929 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008930 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8931 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008932 }
8933 // Check if support of multiple SIMs is restricted by carrier
8934 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008935 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008936 }
8937
Michele0ea7d782019-03-19 14:58:42 -07008938 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008939 }
8940
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008941 /**
8942 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008943 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8944 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8945 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008946 * @param numOfSims number of active sims we want to switch to
8947 */
8948 @Override
8949 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008950 if (numOfSims == 1) {
8951 enforceModifyPermission();
8952 } else {
8953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8954 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8955 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008956 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008957
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008958 try {
Michele30b57b22019-03-01 12:01:14 -08008959 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008960 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008961 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8962 return;
8963 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008964 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8965 } finally {
8966 Binder.restoreCallingIdentity(identity);
8967 }
8968 }
8969
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008970 @Override
8971 public boolean isApplicationOnUicc(int subId, int appType) {
8972 enforceReadPrivilegedPermission("isApplicationOnUicc");
8973 Phone phone = getPhone(subId);
8974 if (phone == null) {
8975 return false;
8976 }
8977 final long identity = Binder.clearCallingIdentity();
8978 try {
8979 UiccCard uiccCard = phone.getUiccCard();
8980 if (uiccCard == null) {
8981 return false;
8982 }
8983 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8984 if (uiccProfile == null) {
8985 return false;
8986 }
8987 if (TelephonyManager.APPTYPE_SIM <= appType
8988 && appType <= TelephonyManager.APPTYPE_ISIM) {
8989 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8990 }
8991 return false;
8992 } finally {
8993 Binder.restoreCallingIdentity(identity);
8994 }
8995 }
8996
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008997 /**
chen xub4baa772019-04-03 10:23:41 -07008998 * Get whether making changes to modem configurations will trigger reboot.
8999 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009000 */
9001 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08009002 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9003 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08009005 mApp, subId, callingPackage, callingFeatureId,
9006 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009007 return false;
9008 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9012 } finally {
9013 Binder.restoreCallingIdentity(identity);
9014 }
9015 }
9016
Nathan Harold29f5f052019-02-15 13:41:57 -08009017 private void updateModemStateMetrics() {
9018 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9019 // TODO: check the state for each modem if the api is ready.
9020 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9021 }
9022
Pengquan Meng3889a572019-01-23 11:16:29 -08009023 @Override
9024 public int[] getSlotsMapping() {
9025 enforceReadPrivilegedPermission("getSlotsMapping");
9026
9027 final long identity = Binder.clearCallingIdentity();
9028 try {
9029 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9030 // All logical slots should have a mapping to a physical slot.
9031 int[] logicalSlotsMapping = new int[phoneCount];
9032 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9033 for (int i = 0; i < slotInfos.length; i++) {
9034 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9035 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9036 }
9037 }
9038 return logicalSlotsMapping;
9039 } finally {
9040 Binder.restoreCallingIdentity(identity);
9041 }
9042 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009043
9044 /**
9045 * Get the IRadio HAL Version
9046 */
9047 @Override
9048 public int getRadioHalVersion() {
9049 Phone phone = getDefaultPhone();
9050 if (phone == null) return -1;
9051 HalVersion hv = phone.getHalVersion();
9052 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9053 return hv.major * 100 + hv.minor;
9054 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009055
9056 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08009057 * Get the current calling package name.
9058 * @return the current calling package name
9059 */
9060 @Override
9061 public String getCurrentPackageName() {
9062 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9063 }
9064
9065 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009066 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9067 * corresponding network requests on a subId.
9068 *
9069 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009070 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009071 * 2) APN is un-metered for this subscription, or
9072 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07009073 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009074 *
9075 * @return whether data is allowed for a apn type.
9076 *
9077 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009078 */
9079 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009080 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009081 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9082 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009083
9084 // Now that all security checks passes, perform the operation as ourselves.
9085 final long identity = Binder.clearCallingIdentity();
9086 try {
9087 Phone phone = getPhone(subId);
9088 if (phone == null) return false;
9089
Jack Yu41407ee2019-05-13 16:54:09 -07009090 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009091 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9092 } finally {
9093 Binder.restoreCallingIdentity(identity);
9094 }
9095 }
9096
9097 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009098 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009099 enforceReadPrivilegedPermission("isApnMetered");
9100
9101 // Now that all security checks passes, perform the operation as ourselves.
9102 final long identity = Binder.clearCallingIdentity();
9103 try {
9104 Phone phone = getPhone(subId);
9105 if (phone == null) return true; // By default return true.
9106
Jack Yu41407ee2019-05-13 16:54:09 -07009107 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009108 } finally {
9109 Binder.restoreCallingIdentity(identity);
9110 }
9111 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009112
9113 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009114 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9115 int subscriptionId, IBooleanConsumer resultCallback) {
9116 enforceModifyPermission();
9117 long token = Binder.clearCallingIdentity();
9118 try {
9119 Phone phone = getPhone(subscriptionId);
9120 if (phone == null) {
9121 try {
9122 if (resultCallback != null) {
9123 resultCallback.accept(false);
9124 }
9125 } catch (RemoteException e) {
9126 // ignore
9127 }
9128 return;
9129 }
9130 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9131 Pair.create(specifiers, (x) -> {
9132 try {
9133 if (resultCallback != null) {
9134 resultCallback.accept(x);
9135 }
9136 } catch (RemoteException e) {
9137 // ignore
9138 }
9139 });
9140 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9141 } finally {
9142 Binder.restoreCallingIdentity(token);
9143 }
9144 }
9145
9146 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009147 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9148 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07009149 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08009150 mApp, subId, "getSystemSelectionChannels");
9151 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9152 final long identity = Binder.clearCallingIdentity();
9153 try {
Sarah Chin58691872021-03-13 03:17:40 -08009154 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9155 if (result instanceof IllegalStateException) {
9156 throw (IllegalStateException) result;
9157 }
9158 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chincc055732020-11-18 13:39:35 -08009159 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9160 return specifiers;
9161 } finally {
9162 Binder.restoreCallingIdentity(identity);
9163 }
9164 }
9165
9166 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009167 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009168 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009169 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9170 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9171 if (iccRecords == null) {
9172 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9173 return false;
9174 }
9175 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9176 }
9177
9178 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009179 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9180 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009181 if (callingPackage == null) {
9182 callingPackage = getCurrentPackageName();
9183 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009184 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9185 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009186 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9187 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009188 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9189 }
9190 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9191 Intent intent = new Intent();
9192 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9193 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9194 // Bring up choose default SMS subscription dialog right now
9195 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9196 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9197 mApp.startActivity(intent);
9198 }
chen xud5ca2d52019-05-28 15:20:57 -07009199
9200 @Override
9201 public String getMmsUAProfUrl(int subId) {
9202 //TODO investigate if this API should require proper permission check in R b/133791609
9203 final long identity = Binder.clearCallingIdentity();
9204 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009205 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9206 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9207 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9208 return carrierUAProfUrl;
9209 }
chen xud5ca2d52019-05-28 15:20:57 -07009210 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9211 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
9215 }
9216
9217 @Override
9218 public String getMmsUserAgent(int subId) {
9219 //TODO investigate if this API should require proper permission check in R b/133791609
9220 final long identity = Binder.clearCallingIdentity();
9221 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009222 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9223 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9224 if (!TextUtils.isEmpty(carrierUserAgent)) {
9225 return carrierUserAgent;
9226 }
chen xud5ca2d52019-05-28 15:20:57 -07009227 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9228 .getString(com.android.internal.R.string.config_mms_user_agent);
9229 } finally {
9230 Binder.restoreCallingIdentity(identity);
9231 }
9232 }
Jack Yub07d4972019-05-28 16:12:25 -07009233
9234 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009235 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9236 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9237
9238 final long identity = Binder.clearCallingIdentity();
9239 try {
9240 Phone phone = getPhone(subscriptionId);
9241 if (phone == null) return false;
9242
9243 switch (policy) {
9244 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9245 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9246 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9247 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9248 default:
9249 throw new IllegalArgumentException(policy + " is not a valid policy");
9250 }
9251 } finally {
9252 Binder.restoreCallingIdentity(identity);
9253 }
9254 }
9255
9256 @Override
9257 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9258 boolean enabled) {
9259 enforceModifyPermission();
9260
9261 final long identity = Binder.clearCallingIdentity();
9262 try {
9263 Phone phone = getPhone(subscriptionId);
9264 if (phone == null) return;
9265
9266 switch (policy) {
9267 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9268 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9269 break;
9270 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9271 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9272 break;
9273 default:
9274 throw new IllegalArgumentException(policy + " is not a valid policy");
9275 }
9276 } finally {
9277 Binder.restoreCallingIdentity(identity);
9278 }
9279 }
9280
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009281 /**
Hall Liub48cf452020-09-25 11:13:49 -07009282 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009283 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9284 * otherwise.
9285 */
9286 @Override
9287 public void setCepEnabled(boolean isCepEnabled) {
9288 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9289
9290 final long identity = Binder.clearCallingIdentity();
9291 try {
9292 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9293 for (Phone phone : PhoneFactory.getPhones()) {
9294 Phone defaultPhone = phone.getImsPhone();
9295 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9296 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9297 ImsPhoneCallTracker imsPhoneCallTracker =
9298 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9299 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9300 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9301 + imsPhone.getMsisdn());
9302 }
9303 }
9304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 }
allenwtsu46dcc572020-01-08 18:24:03 +08009308
9309 /**
9310 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9311 *
9312 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9313 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9314 * before being read.
9315 */
9316 @Override
9317 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9318 isCompressed) {
9319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9320 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009321 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9322 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9323 }
9324 if (!isImsAvailableOnDevice()) {
9325 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9326 "IMS not available on device.");
9327 }
9328
9329 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009330 try {
Hui Wang068ab862020-10-31 05:12:53 +00009331 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9332 } finally {
9333 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009334 }
9335 }
zoey chenf95ca592019-12-30 16:11:23 +08009336
9337 @Override
9338 public boolean isIccLockEnabled(int subId) {
9339 enforceReadPrivilegedPermission("isIccLockEnabled");
9340
9341 // Now that all security checks passes, perform the operation as ourselves.
9342 final long identity = Binder.clearCallingIdentity();
9343 try {
9344 Phone phone = getPhone(subId);
9345 if (phone != null && phone.getIccCard() != null) {
9346 return phone.getIccCard().getIccLockEnabled();
9347 } else {
9348 return false;
9349 }
9350 } finally {
9351 Binder.restoreCallingIdentity(identity);
9352 }
9353 }
9354
9355 /**
zoey chene02881a2019-12-30 16:11:23 +08009356 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009357 *
zoey chene02881a2019-12-30 16:11:23 +08009358 * @return an integer representing the status of IccLock enabled or disabled in the following
9359 * three cases:
9360 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9361 * successfully.
9362 * - Positive number and zero for remaining password attempts.
9363 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009364 *
9365 */
9366 @Override
9367 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9368 enforceModifyPermission();
9369
9370 Phone phone = getPhone(subId);
9371 if (phone == null) {
9372 return 0;
9373 }
9374 // Now that all security checks passes, perform the operation as ourselves.
9375 final long identity = Binder.clearCallingIdentity();
9376 try {
9377 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9378 new Pair<Boolean, String>(enabled, password), phone, null);
9379 return attemptsRemaining;
9380
9381 } catch (Exception e) {
9382 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 return 0;
9387 }
9388
9389 /**
9390 * Change the ICC password used in ICC pin lock.
9391 *
zoey chene02881a2019-12-30 16:11:23 +08009392 * @return an integer representing the status of IccLock changed in the following three cases:
9393 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9394 * - Positive number and zero for remaining password attempts.
9395 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009396 *
9397 */
9398 @Override
9399 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9400 enforceModifyPermission();
9401
9402 Phone phone = getPhone(subId);
9403 if (phone == null) {
9404 return 0;
9405 }
9406 // Now that all security checks passes, perform the operation as ourselves.
9407 final long identity = Binder.clearCallingIdentity();
9408 try {
9409 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9410 new Pair<String, String>(oldPassword, newPassword), phone, null);
9411 return attemptsRemaining;
9412
9413 } catch (Exception e) {
9414 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9415 } finally {
9416 Binder.restoreCallingIdentity(identity);
9417 }
9418 return 0;
9419 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009420
Peter Wangdafb9ac2020-01-15 14:13:38 -08009421 /**
9422 * Request for receiving user activity notification
9423 */
9424 @Override
9425 public void requestUserActivityNotification() {
9426 if (!mNotifyUserActivity.get()
9427 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9428 mNotifyUserActivity.set(true);
9429 }
9430 }
9431
9432 /**
9433 * Called when userActivity is signalled in the power manager.
9434 * This is safe to call from any thread, with any window manager locks held or not.
9435 */
9436 @Override
9437 public void userActivity() {
9438 // ***************************************
9439 // * Inherited from PhoneWindowManager *
9440 // ***************************************
9441 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9442 // WITH ITS LOCKS HELD.
9443 //
9444 // This code must be VERY careful about the locks
9445 // it acquires.
9446 // In fact, the current code acquires way too many,
9447 // and probably has lurking deadlocks.
9448
9449 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9450 throw new SecurityException("Only the OS may call notifyUserActivity()");
9451 }
9452
9453 if (mNotifyUserActivity.getAndSet(false)) {
9454 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9455 USER_ACTIVITY_NOTIFICATION_DELAY);
9456 }
9457 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009458
Malcolm Chen884180b2020-04-13 11:59:40 -07009459 @Override
9460 public boolean canConnectTo5GInDsdsMode() {
9461 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9462 }
Jack Yud10cdd42020-09-28 20:28:01 -07009463
9464 @Override
9465 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9466 String callingFeatureId) {
9467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9468 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9469 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9470 }
9471
9472 Phone phone = getPhone(subId);
9473 if (phone == null) {
9474 throw new RuntimeException("phone is not available");
9475 }
9476 // Now that all security checks passes, perform the operation as ourselves.
9477 final long identity = Binder.clearCallingIdentity();
9478 try {
9479 return phone.getEquivalentHomePlmns();
9480 } finally {
9481 Binder.restoreCallingIdentity(identity);
9482 }
9483 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009484
Hui Wang0866fcc2020-10-12 12:14:23 -07009485 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009486 public boolean isRadioInterfaceCapabilitySupported(
9487 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009488 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009489 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009490 if (radioInterfaceCapabilities == null) {
9491 throw new RuntimeException("radio interface capabilities are not available");
9492 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009493 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009494 }
9495 }
9496
9497 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009498 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9499 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009500 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9501 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9502 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9503 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9504 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009505 if (DBG) {
9506 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9507 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9508 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9509 }
9510
9511 if (!SubscriptionManager.isValidSubscriptionId(subId)
9512 || appType < TelephonyManager.APPTYPE_UNKNOWN
9513 || appType > TelephonyManager.APPTYPE_ISIM
9514 || nafUrl == null || securityProtocol == null || callback == null) {
9515 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9516 if (callback != null) {
9517 try {
9518 callback.onAuthenticationFailure(
9519 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9520 } catch (RemoteException exception) {
9521 log("Fail to notify onAuthenticationFailure due to " + exception);
9522 }
9523 return;
9524 }
9525 }
9526
9527 final long token = Binder.clearCallingIdentity();
9528 try {
9529 getGbaManager(subId).bootstrapAuthenticationRequest(
9530 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9531 forceBootStrapping, callback));
9532 } finally {
9533 Binder.restoreCallingIdentity(token);
9534 }
9535 }
9536
Jack Nudelman24d51a52020-11-24 12:08:04 -08009537 /**
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009538 * Attempts to set the radio power state for all phones for thermal reason.
9539 * This does not guarantee that the
Jack Nudelman24d51a52020-11-24 12:08:04 -08009540 * requested radio power state will actually be set. See {@link
9541 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9542 *
Jack Nudelman24d51a52020-11-24 12:08:04 -08009543 * @param enable {@code true} if trying to turn radio on.
9544 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9545 * false}.
9546 */
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009547 private boolean setRadioPowerForThermal(boolean enable) {
9548 boolean isPhoneAvailable = false;
9549 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9550 Phone phone = PhoneFactory.getPhone(i);
9551 if (phone != null) {
9552 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9553 isPhoneAvailable = true;
9554 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009555 }
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009556
9557 // return true if successfully informed the phone object about the thermal radio power
9558 // request.
9559 return isPhoneAvailable;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009560 }
9561
9562 private int handleDataThrottlingRequest(int subId,
9563 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009564 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9565 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9566 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9567 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9568 throw new IllegalArgumentException("modem does not support data throttling");
9569 }
9570
Jack Nudelman24d51a52020-11-24 12:08:04 -08009571 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9572 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009573 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009574 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9575 }
9576
9577 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9578
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009579 if (isDataThrottlingSupported) {
9580 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009581 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009582 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9583 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9584 } else if (thermalMitigationResult
9585 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman20352592021-05-20 13:57:30 -07009586 log("Modem likely does not support data throttling on secondary carrier. Data " +
9587 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9588 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009589 }
9590 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009591 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009592
9593 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009594 }
9595
Jack Nudelman644b91a2021-03-12 14:09:48 -08009596 private static List<String> getThermalMitigationAllowlist(Context context) {
9597 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9598 for (String pckg : context.getResources()
9599 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9600 sThermalMitigationAllowlistedPackages.add(pckg);
9601 }
9602 }
9603
9604 return sThermalMitigationAllowlistedPackages;
9605 }
9606
Jack Nudelmane634f962021-05-13 10:00:15 -07009607 private boolean isAnyPhoneInEmergencyState() {
9608 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9609 if (tm.isInEmergencyCall()) {
9610 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9611 return true;
9612 }
9613 for (Phone phone : PhoneFactory.getPhones()) {
9614 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9615 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9616 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9617 + phone.isInEcm());
9618 return true;
9619 }
9620 }
9621
9622 return false;
9623 }
9624
Jack Nudelman644b91a2021-03-12 14:09:48 -08009625 /**
9626 * Used by shell commands to add an authorized package name for thermal mitigation.
9627 * @param packageName name of package to be allowlisted
9628 * @param context
9629 */
9630 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9631 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9632 sThermalMitigationAllowlistedPackages.add(packageName);
9633 }
9634
9635 /**
9636 * Used by shell commands to remove an authorized package name for thermal mitigation.
9637 * @param packageName name of package to remove from allowlist
9638 * @param context
9639 */
9640 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9641 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9642 sThermalMitigationAllowlistedPackages.remove(packageName);
9643 }
9644
Jack Nudelman24d51a52020-11-24 12:08:04 -08009645 /**
9646 * Thermal mitigation request to control functionalities at modem.
9647 *
9648 * @param subId the id of the subscription.
9649 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009650 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009651 *
9652 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9653 */
9654 @Override
9655 @ThermalMitigationResult
9656 public int sendThermalMitigationRequest(
9657 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009658 ThermalMitigationRequest thermalMitigationRequest,
9659 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009660 enforceModifyPermission();
9661
Jack Nudelman644b91a2021-03-12 14:09:48 -08009662 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9663 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9664 .contains(callingPackage)) {
9665 throw new SecurityException("Calling package must be configured in the device config. "
9666 + "calling package: " + callingPackage);
9667 }
9668
Jack Nudelman24d51a52020-11-24 12:08:04 -08009669 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9670 final long identity = Binder.clearCallingIdentity();
9671
9672 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9673 try {
9674 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9675 switch (thermalMitigationAction) {
9676 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9677 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009678 handleDataThrottlingRequest(subId,
9679 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009680 break;
9681 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9682 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9683 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9684 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9685 }
9686
9687 // Ensure that radio is on. If not able to power on due to phone being
9688 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009689 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009690 thermalMitigationResult =
9691 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9692 break;
9693 }
9694
9695 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9696 false);
9697 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9698 break;
9699 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9700 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9701 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9702 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9703 }
9704
9705 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9706 if (registry != null) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009707 Phone phone = getPhone(subId);
9708 if (phone == null) {
9709 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009710 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009711 break;
9712 }
9713
Jack Nudelmane634f962021-05-13 10:00:15 -07009714 TelephonyConnectionService service =
9715 registry.getTelephonyConnectionService();
Jack Nudelmana80c0012021-06-17 15:39:58 -07009716 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane634f962021-05-13 10:00:15 -07009717 Log.e(LOG_TAG, "An emergency call is pending");
9718 thermalMitigationResult =
9719 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9720 break;
9721 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009722 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009723 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009724 break;
9725 }
9726 } else {
9727 thermalMitigationResult =
9728 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9729 break;
9730 }
9731
9732 // Turn radio off. If not able to power off due to phone being unavailable,
9733 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009734 if (!setRadioPowerForThermal(false)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009735 thermalMitigationResult =
9736 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9737 break;
9738 }
9739 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009740 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009741 break;
9742 default:
9743 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9744 + "not exist. Requested action: " + thermalMitigationAction);
9745 }
9746 } catch (IllegalArgumentException e) {
9747 throw e;
9748 } catch (Exception e) {
9749 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9750 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9751 } finally {
9752 Binder.restoreCallingIdentity(identity);
9753 }
9754
9755 if (DBG) {
9756 log("thermalMitigationRequest returning with thermalMitigationResult: "
9757 + thermalMitigationResult);
9758 }
9759
9760 return thermalMitigationResult;
9761 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009762
9763 /**
9764 * Set the GbaService Package Name that Telephony will bind to.
9765 *
9766 * @param subId The sim that the GbaService is associated with.
9767 * @param packageName The name of the package to be replaced with.
9768 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9769 */
9770 @Override
9771 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9772 enforceModifyPermission();
9773
9774 final long identity = Binder.clearCallingIdentity();
9775 try {
9776 return getGbaManager(subId).overrideServicePackage(packageName);
9777 } finally {
9778 Binder.restoreCallingIdentity(identity);
9779 }
9780 }
9781
9782 /**
9783 * Return the package name of the currently bound GbaService.
9784 *
9785 * @param subId The sim that the GbaService is associated with.
9786 * @return the package name of the GbaService configuration, null if GBA is not supported.
9787 */
9788 @Override
9789 public String getBoundGbaService(int subId) {
9790 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9791
9792 final long identity = Binder.clearCallingIdentity();
9793 try {
9794 return getGbaManager(subId).getServicePackage();
9795 } finally {
9796 Binder.restoreCallingIdentity(identity);
9797 }
9798 }
9799
9800 /**
9801 * Set the release time for telephony to unbind GbaService.
9802 *
9803 * @param subId The sim that the GbaService is associated with.
9804 * @param interval The release time to unbind GbaService by millisecond.
9805 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9806 */
9807 @Override
9808 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9809 enforceModifyPermission();
9810
9811 final long identity = Binder.clearCallingIdentity();
9812 try {
9813 return getGbaManager(subId).overrideReleaseTime(interval);
9814 } finally {
9815 Binder.restoreCallingIdentity(identity);
9816 }
9817 }
9818
9819 /**
9820 * Return the release time for telephony to unbind GbaService.
9821 *
9822 * @param subId The sim that the GbaService is associated with.
9823 * @return The release time to unbind GbaService by millisecond.
9824 */
9825 @Override
9826 public int getGbaReleaseTime(int subId) {
9827 enforceReadPrivilegedPermission("getGbaReleaseTime");
9828
9829 final long identity = Binder.clearCallingIdentity();
9830 try {
9831 return getGbaManager(subId).getReleaseTime();
9832 } finally {
9833 Binder.restoreCallingIdentity(identity);
9834 }
9835 }
9836
9837 private GbaManager getGbaManager(int subId) {
9838 GbaManager instance = GbaManager.getInstance(subId);
9839 if (instance == null) {
9840 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9841 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9842 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9843 }
9844 return instance;
9845 }
Hui Wang068ab862020-10-31 05:12:53 +00009846
9847 /**
9848 * indicate whether the device and the carrier can support
9849 * RCS VoLTE single registration.
9850 */
9851 @Override
9852 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009853 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9854 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9855 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9856 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009857
9858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9859 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9860 }
9861
9862 final long identity = Binder.clearCallingIdentity();
9863 try {
9864 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9865 if (rpm != null) {
Hui Wang048c10a2021-06-21 18:05:57 +00009866 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
9867 if (isCapable != null) {
9868 return isCapable;
9869 }
Hui Wang068ab862020-10-31 05:12:53 +00009870 }
Hui Wang048c10a2021-06-21 18:05:57 +00009871 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
9872 "service is temporarily unavailable.");
Hui Wang068ab862020-10-31 05:12:53 +00009873 } finally {
9874 Binder.restoreCallingIdentity(identity);
9875 }
9876 }
9877
9878 /**
9879 * Register RCS provisioning callback.
9880 */
9881 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009882 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009883 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009884 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009885 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009886 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9887 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009888
9889 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9890 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9891 }
9892 if (!isImsAvailableOnDevice()) {
9893 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9894 "IMS not available on device.");
9895 }
9896
9897 final long identity = Binder.clearCallingIdentity();
9898 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009899 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009900 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009901 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9902 "Service not available for the subscription.");
9903 }
Hui Wang068ab862020-10-31 05:12:53 +00009904 } finally {
9905 Binder.restoreCallingIdentity(identity);
9906 }
9907 }
9908
9909 /**
9910 * Unregister RCS provisioning callback.
9911 */
9912 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009913 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009914 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009915 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009916 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009917 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9918 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009919
9920 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9921 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9922 }
9923 if (!isImsAvailableOnDevice()) {
9924 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9925 "IMS not available on device.");
9926 }
9927
9928 final long identity = Binder.clearCallingIdentity();
9929 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009930 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009931 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009932 } finally {
9933 Binder.restoreCallingIdentity(identity);
9934 }
9935 }
9936
9937 /**
9938 * trigger RCS reconfiguration.
9939 */
9940 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009941 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9942 "triggerRcsReconfiguration",
9943 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009944
9945 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9946 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9947 }
9948 if (!isImsAvailableOnDevice()) {
9949 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9950 "IMS not available on device.");
9951 }
9952
9953 final long identity = Binder.clearCallingIdentity();
9954 try {
9955 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9956 } finally {
9957 Binder.restoreCallingIdentity(identity);
9958 }
9959 }
9960
9961 /**
9962 * Provide the client configuration parameters of the RCS application.
9963 */
9964 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009965 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9966 "setRcsClientConfiguration",
9967 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009968
9969 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9970 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9971 }
9972 if (!isImsAvailableOnDevice()) {
9973 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9974 "IMS not available on device.");
9975 }
9976
9977 final long identity = Binder.clearCallingIdentity();
9978
9979 try {
9980 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9981 if (configBinder == null) {
9982 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9983 } else {
9984 configBinder.setRcsClientConfiguration(rcc);
9985 }
9986 } catch (RemoteException e) {
9987 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9988 } finally {
9989 Binder.restoreCallingIdentity(identity);
9990 }
9991 }
9992
9993 /**
Hui Wang19a21872021-02-19 20:45:36 -08009994 * Enables or disables the test mode for RCS VoLTE single registration.
9995 */
9996 @Override
9997 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9998 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9999 "setRcsSingleRegistrationTestModeEnabled");
10000
10001 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10002 }
10003
10004 /**
10005 * Gets the test mode for RCS VoLTE single registration.
10006 */
10007 @Override
10008 public boolean getRcsSingleRegistrationTestModeEnabled() {
10009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10010 "getRcsSingleRegistrationTestModeEnabled");
10011
10012 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10013 }
10014
10015 /**
Hui Wang068ab862020-10-31 05:12:53 +000010016 * Overrides the config of RCS VoLTE single registration enabled for the device.
10017 */
10018 @Override
10019 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10020 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10021 "setDeviceSingleRegistrationEnabledOverride");
10022 enforceModifyPermission();
10023
10024 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10025 : Boolean.parseBoolean(enabledStr);
10026 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010027 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +000010028 }
10029
10030 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010031 * Sends a device to device communication message. Only usable via shell.
10032 * @param message message to send.
10033 * @param value message value.
10034 */
10035 @Override
10036 public void sendDeviceToDeviceMessage(int message, int value) {
10037 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10038 "setCarrierSingleRegistrationEnabledOverride");
10039 enforceModifyPermission();
10040
10041 final long identity = Binder.clearCallingIdentity();
10042 try {
10043 TelephonyConnectionService service =
10044 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10045 if (service == null) {
10046 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10047 return;
10048 }
10049 service.sendTestDeviceToDeviceMessage(message, value);
10050 } finally {
10051 Binder.restoreCallingIdentity(identity);
10052 }
10053 }
10054
10055
10056 /**
Hui Wang068ab862020-10-31 05:12:53 +000010057 * Gets the config of RCS VoLTE single registration enabled for the device.
10058 */
10059 @Override
10060 public boolean getDeviceSingleRegistrationEnabled() {
10061 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10062 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10063 }
10064
10065 /**
10066 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10067 */
10068 @Override
10069 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10070 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10071 "setCarrierSingleRegistrationEnabledOverride");
10072 enforceModifyPermission();
10073
10074 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10075 : Boolean.parseBoolean(enabledStr);
10076 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10077 subId, enabled);
10078 }
10079
10080 /**
10081 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10082 */
10083 @Override
10084 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10085 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10086 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10087 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010088
10089 /**
Hui Wangeadb2562021-02-26 09:33:38 -080010090 * Overrides the ims feature validation result
10091 */
10092 @Override
10093 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10094 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10095 "setImsFeatureValidationOverride");
10096
10097 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10098 : Boolean.parseBoolean(enabledStr);
10099 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10100 subId, enabled);
10101 }
10102
10103 /**
10104 * Gets the ims feature validation override value
10105 */
10106 @Override
10107 public boolean getImsFeatureValidationOverride(int subId) {
10108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10109 "getImsFeatureValidationOverride");
10110 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10111 }
10112
10113 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010114 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10115 * their mobile plan.
10116 */
10117 @Override
10118 public String getMobileProvisioningUrl() {
10119 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10120 final long identity = Binder.clearCallingIdentity();
10121 try {
10122 return getDefaultPhone().getMobileProvisioningUrl();
10123 } finally {
10124 Binder.restoreCallingIdentity(identity);
10125 }
10126 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010127
James.cf Linbcdf8b32021-01-14 16:44:13 +080010128 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010129 * Get the EAB contact from the EAB database.
10130 */
10131 @Override
10132 public String getContactFromEab(String contact) {
10133 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10134 enforceModifyPermission();
10135 final long identity = Binder.clearCallingIdentity();
10136 try {
10137 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10138 } finally {
10139 Binder.restoreCallingIdentity(identity);
10140 }
10141 }
10142
10143 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010144 * Remove the EAB contacts from the EAB database.
10145 */
10146 @Override
10147 public int removeContactFromEab(int subId, String contacts) {
10148 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10149 enforceModifyPermission();
10150 final long identity = Binder.clearCallingIdentity();
10151 try {
10152 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10153 } finally {
10154 Binder.restoreCallingIdentity(identity);
10155 }
10156 }
10157
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010158 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010159 public boolean getDeviceUceEnabled() {
10160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10161 final long identity = Binder.clearCallingIdentity();
10162 try {
10163 return mApp.getDeviceUceEnabled();
10164 } finally {
10165 Binder.restoreCallingIdentity(identity);
10166 }
10167 }
10168
10169 @Override
10170 public void setDeviceUceEnabled(boolean isEnabled) {
10171 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10172 final long identity = Binder.clearCallingIdentity();
10173 try {
10174 mApp.setDeviceUceEnabled(isEnabled);
10175 } finally {
10176 Binder.restoreCallingIdentity(identity);
10177 }
10178 }
10179
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010180 /**
10181 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10182 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10183 */
10184 // Used for SHELL command only right now.
10185 @Override
10186 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10187 List<String> featureTags) {
10188 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10189 "addUceRegistrationOverrideShell");
10190 final long identity = Binder.clearCallingIdentity();
10191 try {
10192 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10193 new ArraySet<>(featureTags));
10194 } catch (ImsException e) {
10195 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10196 } finally {
10197 Binder.restoreCallingIdentity(identity);
10198 }
10199 }
10200
10201 /**
10202 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10203 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10204 */
10205 // Used for SHELL command only right now.
10206 @Override
10207 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10208 List<String> featureTags) {
10209 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10210 "removeUceRegistrationOverrideShell");
10211 final long identity = Binder.clearCallingIdentity();
10212 try {
10213 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10214 new ArraySet<>(featureTags));
10215 } catch (ImsException e) {
10216 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10217 } finally {
10218 Binder.restoreCallingIdentity(identity);
10219 }
10220 }
10221
10222 /**
10223 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10224 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10225 */
10226 // Used for SHELL command only right now.
10227 @Override
10228 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10229 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10230 "clearUceRegistrationOverrideShell");
10231 final long identity = Binder.clearCallingIdentity();
10232 try {
10233 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10234 } catch (ImsException e) {
10235 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10236 } finally {
10237 Binder.restoreCallingIdentity(identity);
10238 }
10239 }
10240
10241 /**
10242 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10243 */
10244 // Used for SHELL command only right now.
10245 @Override
10246 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10247 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10248 "getLatestRcsContactUceCapabilityShell");
10249 final long identity = Binder.clearCallingIdentity();
10250 try {
10251 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10252 } catch (ImsException e) {
10253 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10254 } finally {
10255 Binder.restoreCallingIdentity(identity);
10256 }
10257 }
10258
10259 /**
10260 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10261 * device does not have an active PUBLISH.
10262 */
10263 // Used for SHELL command only right now.
10264 @Override
10265 public String getLastUcePidfXmlShell(int subId) {
10266 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10267 final long identity = Binder.clearCallingIdentity();
10268 try {
10269 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10270 } catch (ImsException e) {
10271 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10272 } finally {
10273 Binder.restoreCallingIdentity(identity);
10274 }
10275 }
10276
James.cf Line8713a42021-04-29 16:04:26 +080010277 /**
10278 * Remove UCE requests cannot be sent to the network status.
10279 */
10280 // Used for SHELL command only right now.
10281 @Override
10282 public boolean removeUceRequestDisallowedStatus(int subId) {
10283 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10284 final long identity = Binder.clearCallingIdentity();
10285 try {
10286 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10287 } catch (ImsException e) {
10288 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10289 } finally {
10290 Binder.restoreCallingIdentity(identity);
10291 }
10292 }
10293
James.cf Lin18bb9002021-05-25 01:37:38 +080010294 /**
10295 * Remove UCE requests cannot be sent to the network status.
10296 */
10297 // Used for SHELL command only.
10298 @Override
10299 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10300 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10301 final long identity = Binder.clearCallingIdentity();
10302 try {
10303 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10304 } catch (ImsException e) {
10305 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10306 } finally {
10307 Binder.restoreCallingIdentity(identity);
10308 }
10309 }
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010310
James.cf Lin4b784aa2021-01-31 03:25:15 +080010311 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010312 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10313 String callingPackage) {
10314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10315 mApp, subId, "setSignalStrengthUpdateRequest");
10316
10317 final int callingUid = Binder.getCallingUid();
10318 // Verify that tha callingPackage belongs to the calling UID
10319 mApp.getSystemService(AppOpsManager.class)
10320 .checkPackage(callingUid, callingPackage);
10321
10322 validateSignalStrengthUpdateRequest(request, callingUid);
10323
10324 final long identity = Binder.clearCallingIdentity();
10325 try {
10326 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10327 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10328
10329 if (result instanceof IllegalStateException) {
10330 throw (IllegalStateException) result;
10331 }
10332 } finally {
10333 Binder.restoreCallingIdentity(identity);
10334 }
10335 }
10336
10337 @Override
10338 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10339 String callingPackage) {
10340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10341 mApp, subId, "clearSignalStrengthUpdateRequest");
10342
10343 final int callingUid = Binder.getCallingUid();
10344 // Verify that tha callingPackage belongs to the calling UID
10345 mApp.getSystemService(AppOpsManager.class)
10346 .checkPackage(callingUid, callingPackage);
10347
10348 final long identity = Binder.clearCallingIdentity();
10349 try {
10350 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10351 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10352
10353 if (result instanceof IllegalStateException) {
10354 throw (IllegalStateException) result;
10355 }
10356 } finally {
10357 Binder.restoreCallingIdentity(identity);
10358 }
10359 }
10360
10361 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10362 int callingUid) {
10363 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10364 // phone/system process do not have further restriction on request
10365 return;
10366 }
10367
10368 // Applications has restrictions on how to use the request:
10369 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10370 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10371 // This is not system caller which has been checked above
10372 throw new IllegalArgumentException(
10373 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10374 }
10375
10376 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10377 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10378 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10379 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10380 || info.isEnabled()) {
10381 throw new IllegalArgumentException(
10382 "Only system can set hide fields in SignalThresholdInfo");
10383 }
10384
10385 // Thresholds length for each RAN need in range. This has been validated in
10386 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10387 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10388 final int[] thresholds = info.getThresholds();
10389 Objects.requireNonNull(thresholds);
10390 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10391 || thresholds.length
10392 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10393 throw new IllegalArgumentException(
10394 "thresholds length is out of range: " + thresholds.length);
10395 }
10396 }
10397 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010398
10399 /**
10400 * Prepare TelephonyManager for an unattended reboot. The reboot is
10401 * required to be done shortly after the API is invoked.
10402 */
10403 @Override
10404 @TelephonyManager.PrepareUnattendedRebootResult
10405 public int prepareForUnattendedReboot() {
Rafael Higuera Silvacd3aef22021-08-30 15:16:50 +000010406 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionned9fbae52020-11-13 02:36:59 +000010407 enforceRebootPermission();
10408
10409 final long identity = Binder.clearCallingIdentity();
10410 try {
Rafael Higuera Silvacd3aef22021-08-30 15:16:50 +000010411 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionned9fbae52020-11-13 02:36:59 +000010412 } finally {
10413 Binder.restoreCallingIdentity(identity);
10414 }
10415 }
SongFerngWang2c4309d2021-01-17 21:51:44 +080010416
10417 /**
10418 * Gets the current phone capability.
10419 *
10420 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10421 * @return the PhoneCapability which describes the data connection capability of modem.
10422 * It's used to evaluate possible phone config change, for example from single
10423 * SIM device to multi-SIM device.
10424 */
10425 @Override
10426 public PhoneCapability getPhoneCapability() {
10427 enforceReadPrivilegedPermission("getPhoneCapability");
10428 final long identity = Binder.clearCallingIdentity();
10429 try {
10430 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10431 } finally {
10432 Binder.restoreCallingIdentity(identity);
10433 }
10434 }
Hongbo Zengd31d3a32021-02-08 21:50:28 +080010435
10436 /**
10437 * Request to get the current slicing configuration including URSP rules and
10438 * NSSAIs (configured, allowed and rejected).
10439 *
10440 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10441 */
10442 @Override
10443 public void getSlicingConfig(ResultReceiver callback) {
10444 enforceReadPrivilegedPermission("getSlicingConfig");
10445
10446 final long identity = Binder.clearCallingIdentity();
10447 try {
10448 Phone phone = getDefaultPhone();
10449 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10450 } finally {
10451 Binder.restoreCallingIdentity(identity);
10452 }
10453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010454}