blob: b67b77a1d8b5a6b526592ccae50f47b16e717b0f [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();
3088 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3089 }
3090 return tac;
3091 }
3092
3093 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003094 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003095 Phone phone = PhoneFactory.getPhone(slotIndex);
3096 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003097 return null;
3098 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003099
Jeff Davidson913390f2018-02-23 17:11:49 -08003100 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003101 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003102 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003103 return null;
3104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105
3106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 return phone.getMeid();
3109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
Jack Yu2af8d712017-03-15 17:14:14 -07003112 }
3113
3114 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003115 public String getManufacturerCodeForSlot(int slotIndex) {
3116 Phone phone = PhoneFactory.getPhone(slotIndex);
3117 String manufacturerCode = null;
3118 if (phone != null) {
3119 String meid = phone.getMeid();
3120 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3121 }
3122 return manufacturerCode;
3123 }
3124
3125 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003126 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3127 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003128 Phone phone = PhoneFactory.getPhone(slotIndex);
3129 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003130 return null;
3131 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003132 int subId = phone.getSubId();
3133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003134 mApp, subId, callingPackage, callingFeatureId,
3135 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003136 return null;
3137 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138
3139 final long identity = Binder.clearCallingIdentity();
3140 try {
3141 return phone.getDeviceSvn();
3142 } finally {
3143 Binder.restoreCallingIdentity(identity);
3144 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003145 }
3146
fionaxu43304da2017-11-27 22:51:16 -08003147 @Override
3148 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 final Phone phone = getPhone(subId);
3152 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
3155 }
fionaxu43304da2017-11-27 22:51:16 -08003156 }
3157
3158 @Override
3159 public String getSubscriptionCarrierName(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 ? null : phone.getCarrierName();
3164 } finally {
3165 Binder.restoreCallingIdentity(identity);
3166 }
fionaxu43304da2017-11-27 22:51:16 -08003167 }
3168
calvinpanffe225e2018-11-01 19:43:06 +08003169 @Override
chen xu0026ca62019-03-06 15:28:50 -08003170 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 final Phone phone = getPhone(subId);
3174 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003175 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003176 } finally {
3177 Binder.restoreCallingIdentity(identity);
3178 }
3179 }
3180
3181 @Override
chen xu0026ca62019-03-06 15:28:50 -08003182 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003183 final long identity = Binder.clearCallingIdentity();
3184 try {
3185 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003186 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003187 } finally {
3188 Binder.restoreCallingIdentity(identity);
3189 }
3190 }
3191
chen xu651eec72018-11-11 19:03:44 -08003192 @Override
chen xu864e11c2018-12-06 22:10:03 -08003193 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3194 if (!isSubscriptionMccMnc) {
3195 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3196 }
chen xu651eec72018-11-11 19:03:44 -08003197 final Phone phone = PhoneFactory.getPhone(slotIndex);
3198 if (phone == null) {
3199 return TelephonyManager.UNKNOWN_CARRIER_ID;
3200 }
3201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
3207 }
3208
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 //
3210 // Internal helper methods.
3211 //
3212
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003213 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3215 *
3216 * @throws SecurityException if the caller does not have the required permission
3217 */
3218 private void enforceModifyPermission() {
3219 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3220 }
3221
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003222 /**
3223 * Make sure the caller is system.
3224 *
3225 * @throws SecurityException if the caller is not system.
3226 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003227 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003228 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3229 throw new SecurityException("Caller must be system");
3230 }
3231 }
3232
Shuo Qianf2b2df42019-11-13 17:43:31 -08003233 private void enforceActiveEmergencySessionPermission() {
3234 mApp.enforceCallingOrSelfPermission(
3235 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3236 }
3237
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003238 /**
3239 * Make sure the caller has the CALL_PHONE permission.
3240 *
3241 * @throws SecurityException if the caller does not have the required permission
3242 */
3243 private void enforceCallPermission() {
3244 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3245 }
3246
paulhu423b5f22019-08-23 19:17:33 +08003247 private void enforceSettingsPermission() {
3248 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003249 }
3250
Michele Berionned9fbae52020-11-13 02:36:59 +00003251 private void enforceRebootPermission() {
3252 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3253 }
3254
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003255 private String createTelUrl(String number) {
3256 if (TextUtils.isEmpty(number)) {
3257 return null;
3258 }
3259
Jake Hambye994d462014-02-03 13:10:13 -08003260 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003261 }
3262
Ihab Awadf9e92732013-12-05 18:02:52 -08003263 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003264 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3265 }
3266
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003267 private static void logv(String msg) {
3268 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3269 }
3270
Ihab Awadf9e92732013-12-05 18:02:52 -08003271 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3273 }
3274
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003275 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003276 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003277 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003278 }
3279
Sanket Padawe356d7632015-06-22 14:03:32 -07003280 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003281 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 final Phone phone = PhoneFactory.getPhone(slotIndex);
3285 if (phone == null) {
3286 return PhoneConstants.PHONE_TYPE_NONE;
3287 } else {
3288 return phone.getPhoneType();
3289 }
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003293 }
3294
3295 /**
3296 * Returns the CDMA ERI icon index to display
3297 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003298 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003299 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3300 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3301 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003302 }
3303
Sanket Padawe356d7632015-06-22 14:03:32 -07003304 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003305 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3306 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003308 mApp, subId, callingPackage, callingFeatureId,
3309 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003310 return -1;
3311 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003312
3313 final long identity = Binder.clearCallingIdentity();
3314 try {
3315 final Phone phone = getPhone(subId);
3316 if (phone != null) {
3317 return phone.getCdmaEriIconIndex();
3318 } else {
3319 return -1;
3320 }
3321 } finally {
3322 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003323 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003324 }
3325
3326 /**
3327 * Returns the CDMA ERI icon mode,
3328 * 0 - ON
3329 * 1 - FLASHING
3330 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003331 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003332 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3333 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3334 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003335 }
3336
Sanket Padawe356d7632015-06-22 14:03:32 -07003337 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003338 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3339 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003341 mApp, subId, callingPackage, callingFeatureId,
3342 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003343 return -1;
3344 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345
3346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 final Phone phone = getPhone(subId);
3349 if (phone != null) {
3350 return phone.getCdmaEriIconMode();
3351 } else {
3352 return -1;
3353 }
3354 } finally {
3355 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003357 }
3358
3359 /**
3360 * Returns the CDMA ERI text,
3361 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003362 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003363 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3364 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3365 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003366 }
3367
Sanket Padawe356d7632015-06-22 14:03:32 -07003368 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003369 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3370 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003372 mApp, subId, callingPackage, callingFeatureId,
3373 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003374 return null;
3375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 final Phone phone = getPhone(subId);
3380 if (phone != null) {
3381 return phone.getCdmaEriText();
3382 } else {
3383 return null;
3384 }
3385 } finally {
3386 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003388 }
3389
3390 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003391 * Returns the CDMA MDN.
3392 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003393 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003394 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3396 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397
3398 final long identity = Binder.clearCallingIdentity();
3399 try {
3400 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003401 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402 return phone.getLine1Number();
3403 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003404 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405 return null;
3406 }
3407 } finally {
3408 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003409 }
3410 }
3411
3412 /**
3413 * Returns the CDMA MIN.
3414 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003415 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003416 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3418 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003419
3420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 final Phone phone = getPhone(subId);
3423 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3424 return phone.getCdmaMin();
3425 } else {
3426 return null;
3427 }
3428 } finally {
3429 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003430 }
3431 }
3432
Hall Liud892bec2018-11-30 14:51:45 -08003433 @Override
3434 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3435 INumberVerificationCallback callback, String callingPackage) {
3436 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3437 != PERMISSION_GRANTED) {
3438 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3439 }
3440 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3441
3442 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3443 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003444 throw new SecurityException("Calling package must be configured in the device config: "
3445 + "calling package: " + callingPackage
3446 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003447 }
3448
3449 if (range == null) {
3450 throw new NullPointerException("Range must be non-null");
3451 }
3452
3453 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003454 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003455
3456 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3457 }
3458
Junda Liuca05d5d2014-08-14 22:36:34 -07003459 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003460 * Returns true if CDMA provisioning needs to run.
3461 */
3462 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463 final long identity = Binder.clearCallingIdentity();
3464 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003465 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003469 }
3470
3471 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003472 * Sets the voice mail number of a given subId.
3473 */
3474 @Override
3475 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003476 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3477 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478
3479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3482 new Pair<String, String>(alphaTag, number), new Integer(subId));
3483 return success;
3484 } finally {
3485 Binder.restoreCallingIdentity(identity);
3486 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003487 }
3488
Ta-wei Yen87c49842016-05-13 21:19:52 -07003489 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003490 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3491 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003492 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3493 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003494 if (!TextUtils.equals(callingPackage, systemDialer)) {
3495 throw new SecurityException("caller must be system dialer");
3496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003497
3498 final long identity = Binder.clearCallingIdentity();
3499 try {
3500 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3501 if (phoneAccountHandle == null) {
3502 return null;
3503 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003504 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003505 } finally {
3506 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003507 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003508 }
3509
3510 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003511 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3512 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003513 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003515 mApp, subId, callingPackage, callingFeatureId,
3516 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003517 return null;
3518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003519
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003520 final long identity = Binder.clearCallingIdentity();
3521 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003522 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003526 }
3527
3528 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003529 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3530 VisualVoicemailSmsFilterSettings settings) {
3531 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532
3533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003536 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003540 }
3541
3542 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003543 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3544 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003549 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003550 } finally {
3551 Binder.restoreCallingIdentity(identity);
3552 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003553 }
3554
3555 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003556 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3557 String callingPackage, int subId) {
3558 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559
3560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003563 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003564 } finally {
3565 Binder.restoreCallingIdentity(identity);
3566 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003567 }
3568
3569 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003570 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003571 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003576 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577 } finally {
3578 Binder.restoreCallingIdentity(identity);
3579 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003580 }
3581
3582 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003583 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3584 String callingAttributionTag, int subId, String number, int port, String text,
3585 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003586 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003587 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003588 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003589 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003590 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3591 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003592 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003593
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003594 /**
fionaxu0152e512016-11-14 13:36:14 -08003595 * Sets the voice activation state of a given subId.
3596 */
3597 @Override
3598 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3600 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003601
3602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 final Phone phone = getPhone(subId);
3605 if (phone != null) {
3606 phone.setVoiceActivationState(activationState);
3607 } else {
3608 loge("setVoiceActivationState fails with invalid subId: " + subId);
3609 }
3610 } finally {
3611 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003612 }
3613 }
3614
3615 /**
3616 * Sets the data activation state of a given subId.
3617 */
3618 @Override
3619 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3621 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622
3623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 final Phone phone = getPhone(subId);
3626 if (phone != null) {
3627 phone.setDataActivationState(activationState);
3628 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003629 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630 }
3631 } finally {
3632 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003633 }
3634 }
3635
3636 /**
3637 * Returns the voice activation state of a given subId.
3638 */
3639 @Override
3640 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642
fionaxu0152e512016-11-14 13:36:14 -08003643 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 if (phone != null) {
3647 return phone.getVoiceActivationState();
3648 } else {
3649 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3650 }
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003653 }
3654 }
3655
3656 /**
3657 * Returns the data activation state of a given subId.
3658 */
3659 @Override
3660 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003661 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662
fionaxu0152e512016-11-14 13:36:14 -08003663 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 if (phone != null) {
3667 return phone.getDataActivationState();
3668 } else {
3669 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3670 }
3671 } finally {
3672 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003673 }
3674 }
3675
3676 /**
Wink Saville36469e72014-06-11 15:17:00 -07003677 * Returns the unread count of voicemails for a subId
3678 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003679 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003680 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3681 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003683 mApp, subId, callingPackage, callingFeatureId,
3684 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003685 return 0;
3686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 final Phone phone = getPhone(subId);
3690 if (phone != null) {
3691 return phone.getVoiceMessageCount();
3692 } else {
3693 return 0;
3694 }
3695 } finally {
3696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003698 }
3699
3700 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003701 * returns true, if the device is in a state where both voice and data
3702 * are supported simultaneously. This can change based on location or network condition.
3703 */
3704 @Override
3705 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 final Phone phone = getPhone(subId);
3709 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003713 }
3714
3715 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003716 * Send the dialer code if called from the current default dialer or the caller has
3717 * carrier privilege.
3718 * @param inputCode The dialer code to send
3719 */
3720 @Override
3721 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003722 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003723 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003724 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3725 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003726 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003727 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003728 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003730
3731 final long identity = Binder.clearCallingIdentity();
3732 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003733 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
fionaxu235cc5e2017-03-06 22:25:57 -08003737 }
3738
Pengquan Menga1bb6272018-09-06 09:59:22 -07003739 @Override
3740 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003741 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07003742 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003743 mApp, subId, "getNetworkSelectionMode");
3744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 if (!isActiveSubscription(subId)) {
3747 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3748 }
3749 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3750 } finally {
3751 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003752 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003753 }
3754
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003756 public boolean isInEmergencySmsMode() {
3757 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3758 final long identity = Binder.clearCallingIdentity();
3759 try {
3760 for (Phone phone : PhoneFactory.getPhones()) {
3761 if (phone.isInEmergencySmsMode()) {
3762 return true;
3763 }
3764 }
3765 } finally {
3766 Binder.restoreCallingIdentity(identity);
3767 }
3768 return false;
3769 }
3770
shilu366312e2019-12-17 09:28:10 -08003771 /**
3772 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3773 * @param subId The subscription to use to check the configuration.
3774 * @param c The callback that will be used to send the result.
3775 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003776 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003777 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3778 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003779 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003780 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003781
Brad Ebinger77b832e2019-10-17 17:03:22 -07003782 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3783 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3784 "IMS not available on device.");
3785 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003786 final long token = Binder.clearCallingIdentity();
3787 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003788 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003789 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003790 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003791 } catch (ImsException e) {
3792 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 } finally {
3794 Binder.restoreCallingIdentity(token);
3795 }
3796 }
3797
shilu366312e2019-12-17 09:28:10 -08003798 /**
3799 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3800 * @param subId The subscription to use to check the configuration.
3801 * @param c The callback that will be used to send the result.
3802 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003803 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003804 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003805 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003806 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003807 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3808 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3809 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003810 final long token = Binder.clearCallingIdentity();
3811 try {
3812 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3813 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3814 .removeRegistrationCallbackForSubscription(c, subId);
3815 } catch (ImsException e) {
3816 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3817 + "is inactive, ignoring unregister.");
3818 // If the subscription is no longer active, just return, since the callback
3819 // will already have been removed internally.
3820 } finally {
3821 Binder.restoreCallingIdentity(token);
3822 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003823 }
3824
Brad Ebinger774ba362019-10-22 17:36:18 -07003825 /**
3826 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3827 */
3828 @Override
3829 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3830 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3831 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3832 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3833 "IMS not available on device.");
3834 }
3835 final long token = Binder.clearCallingIdentity();
3836 try {
3837 Phone phone = getPhone(subId);
3838 if (phone == null) {
3839 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3840 + subId + "'");
3841 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3842 }
3843 phone.getImsRegistrationState(regState -> {
3844 try {
3845 consumer.accept((regState == null)
3846 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3847 } catch (RemoteException e) {
3848 // Ignore if the remote process is no longer available to call back.
3849 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3850 }
3851 });
3852 } finally {
3853 Binder.restoreCallingIdentity(token);
3854 }
3855 }
3856
3857 /**
3858 * Get the transport type for the IMS service registration state.
3859 */
3860 @Override
3861 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003862 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003863 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003864 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3865 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3866 "IMS not available on device.");
3867 }
3868 final long token = Binder.clearCallingIdentity();
3869 try {
3870 Phone phone = getPhone(subId);
3871 if (phone == null) {
3872 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3873 + subId + "'");
3874 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3875 }
3876 phone.getImsRegistrationTech(regTech -> {
3877 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3878 int regTechConverted = (regTech == null)
3879 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3880 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3881 regTechConverted);
3882 try {
3883 consumer.accept(regTechConverted);
3884 } catch (RemoteException e) {
3885 // Ignore if the remote process is no longer available to call back.
3886 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3887 }
3888 });
3889 } finally {
3890 Binder.restoreCallingIdentity(token);
3891 }
3892 }
3893
shilu366312e2019-12-17 09:28:10 -08003894 /**
3895 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3896 * @param subId The subscription to use to check the configuration.
3897 * @param c The callback that will be used to send the result.
3898 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003900 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3901 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003902 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003903 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003904 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3905 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3906 "IMS not available on device.");
3907 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3909 final long token = Binder.clearCallingIdentity();
3910 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003911 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003913 } catch (ImsException e) {
3914 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 } finally {
3916 Binder.restoreCallingIdentity(token);
3917 }
3918 }
3919
shilu366312e2019-12-17 09:28:10 -08003920 /**
3921 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3922 * @param subId The subscription to use to check the configuration.
3923 * @param c The callback that will be used to send the result.
3924 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003925 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003926 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003927 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003928 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003929 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3930 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3931 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003932
3933 final long token = Binder.clearCallingIdentity();
3934 try {
3935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3936 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003937 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003938 } catch (ImsException e) {
3939 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3940 + "is inactive, ignoring unregister.");
3941 // If the subscription is no longer active, just return, since the callback
3942 // will already have been removed internally.
3943 } finally {
3944 Binder.restoreCallingIdentity(token);
3945 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003946 }
3947
3948 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003949 public boolean isCapable(int subId, int capability, int regTech) {
3950 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3952 final long token = Binder.clearCallingIdentity();
3953 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003954 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003956 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3958 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003959 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003960 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3961 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 } finally {
3963 Binder.restoreCallingIdentity(token);
3964 }
3965 }
3966
3967 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003968 public boolean isAvailable(int subId, int capability, int regTech) {
3969 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 final long token = Binder.clearCallingIdentity();
3971 try {
3972 Phone phone = getPhone(subId);
3973 if (phone == null) return false;
3974 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003975 } catch (com.android.ims.ImsException e) {
3976 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3977 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003978 } finally {
3979 Binder.restoreCallingIdentity(token);
3980 }
3981 }
3982
Brad Ebinger77b832e2019-10-17 17:03:22 -07003983 /**
3984 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3985 * subscription.
3986 * @param subId The subscription to use to check the configuration.
3987 * @param callback The callback that will be used to send the result.
3988 * @param capability The MmTelFeature capability that will be used to send the result.
3989 * @param transportType The transport type of the MmTelFeature capability.
3990 */
3991 @Override
3992 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3993 int transportType) {
3994 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3995 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3996 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3997 "IMS not available on device.");
3998 }
3999 final long token = Binder.clearCallingIdentity();
4000 try {
4001 int slotId = getSlotIndex(subId);
4002 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4003 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4004 + subId + "'");
4005 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4006 }
4007 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4008 transportType, aBoolean -> {
4009 try {
4010 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4011 } catch (RemoteException e) {
4012 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4013 + "running. Ignore");
4014 }
4015 });
4016 } finally {
4017 Binder.restoreCallingIdentity(token);
4018 }
4019 }
4020
shilu366312e2019-12-17 09:28:10 -08004021 /**
4022 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4023 * @param subId The subscription to use to check the configuration.
4024 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 @Override
4026 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004027 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004028 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004029
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4031 final long token = Binder.clearCallingIdentity();
4032 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004033 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004035 } catch (ImsException e) {
4036 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 } finally {
4038 Binder.restoreCallingIdentity(token);
4039 }
4040 }
4041
4042 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004043 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004045 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004049 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004051 } catch (ImsException e) {
4052 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004053 } finally {
4054 Binder.restoreCallingIdentity(identity);
4055 }
4056 }
4057
shilu366312e2019-12-17 09:28:10 -08004058 /**
4059 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4060 * @param subId The subscription to use to check the configuration.
4061 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004063 public boolean isVtSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004064 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004065 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 final long identity = Binder.clearCallingIdentity();
4067 try {
4068 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004069 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4070 } catch (ImsException e) {
4071 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 } finally {
4073 Binder.restoreCallingIdentity(identity);
4074 }
4075 }
4076
4077 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004078 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004080 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 final long identity = Binder.clearCallingIdentity();
4082 try {
4083 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004084 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004085 } catch (ImsException e) {
4086 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
4090 }
4091
shilu366312e2019-12-17 09:28:10 -08004092 /**
4093 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4094 * @param subId The subscription to use to check the configuration.
4095 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004096 @Override
4097 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004098 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004099 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004103 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004104 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004105 } catch (ImsException e) {
4106 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 } finally {
4108 Binder.restoreCallingIdentity(identity);
4109 }
4110 }
4111
4112 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004113 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004115 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004119 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004120 } catch (ImsException e) {
4121 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
4125 }
4126
shilu366312e2019-12-17 09:28:10 -08004127 /**
4128 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4129 * @param subId The subscription to use to check the configuration.
4130 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 @Override
4132 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004133 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004134 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004138 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004140 } catch (ImsException e) {
4141 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 } finally {
4143 Binder.restoreCallingIdentity(identity);
4144 }
4145 }
4146
4147 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004148 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004150 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004154 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004156 } catch (ImsException e) {
4157 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
4161 }
4162
4163 @Override
4164 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4166 "setVoWiFiNonPersistent");
4167 final long identity = Binder.clearCallingIdentity();
4168 try {
4169 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004170 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004171 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004172 } catch (ImsException e) {
4173 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004174 } finally {
4175 Binder.restoreCallingIdentity(identity);
4176 }
4177 }
4178
shilu366312e2019-12-17 09:28:10 -08004179 /**
4180 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4181 * @param subId The subscription to use to check the configuration.
4182 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004183 @Override
4184 public int getVoWiFiModeSetting(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004185 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004186 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004187 final long identity = Binder.clearCallingIdentity();
4188 try {
4189 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004190 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004192 } catch (ImsException e) {
4193 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 } finally {
4195 Binder.restoreCallingIdentity(identity);
4196 }
4197 }
4198
4199 @Override
4200 public void setVoWiFiModeSetting(int subId, int mode) {
4201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4202 "setVoWiFiModeSetting");
4203 final long identity = Binder.clearCallingIdentity();
4204 try {
4205 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004206 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004208 } catch (ImsException e) {
4209 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 } finally {
4211 Binder.restoreCallingIdentity(identity);
4212 }
4213 }
4214
4215 @Override
4216 public int getVoWiFiRoamingModeSetting(int subId) {
4217 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4218 final long identity = Binder.clearCallingIdentity();
4219 try {
4220 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004221 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004223 } catch (ImsException e) {
4224 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
4228 }
4229
4230 @Override
4231 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4233 "setVoWiFiRoamingModeSetting");
4234 final long identity = Binder.clearCallingIdentity();
4235 try {
4236 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004237 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004238 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004239 } catch (ImsException e) {
4240 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 } finally {
4242 Binder.restoreCallingIdentity(identity);
4243 }
4244 }
4245
4246 @Override
4247 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4249 "setRttCapabilityEnabled");
4250 final long identity = Binder.clearCallingIdentity();
4251 try {
4252 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004253 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4254 } catch (ImsException e) {
4255 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
4259 }
4260
shilu366312e2019-12-17 09:28:10 -08004261 /**
4262 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4263 * @param subId The subscription to use to check the configuration.
4264 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004265 @Override
4266 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004267 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004268 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 final long identity = Binder.clearCallingIdentity();
4270 try {
4271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004272 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004274 } catch (ImsException e) {
4275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
4279 }
4280
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004281 @Override
4282 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4283 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004286 if (!isImsAvailableOnDevice()) {
4287 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4288 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004289 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004290 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004291 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004292 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004293 } catch (ImsException e) {
4294 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004295 } finally {
4296 Binder.restoreCallingIdentity(identity);
4297 }
4298 }
4299
4300 @Override
4301 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4302 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4303 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004304 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4305 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4306 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004307 try {
4308 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004309 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004310 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004311 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004312 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4313 + "is inactive, ignoring unregister.");
4314 // If the subscription is no longer active, just return, since the callback will already
4315 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
4319 }
4320
allenwtsu99c623b2020-01-03 18:24:23 +08004321
4322 private void checkModifyPhoneStatePermission(int subId, String message) {
4323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4324 message);
4325 }
4326
4327 private boolean isImsProvisioningRequired(int subId, int capability,
4328 boolean isMmtelCapability) {
4329 Phone phone = getPhone(subId);
4330 if (phone == null) {
4331 loge("phone instance null for subid " + subId);
4332 return false;
4333 }
4334 if (isMmtelCapability) {
4335 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4336 return false;
4337 }
4338 } else {
4339 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4340 return false;
4341 }
4342 }
4343 return true;
4344 }
4345
4346 @Override
4347 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4348 boolean isProvisioned) {
4349 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4350
4351 final long identity = Binder.clearCallingIdentity();
4352 try {
4353 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4354 if (!isImsProvisioningRequired(subId, capability, false)) {
4355 return;
4356 }
4357
4358 // this capability requires provisioning, route to the correct API.
4359 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4360 switch (capability) {
4361 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4362 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4363 ims.setEabProvisioned(isProvisioned);
4364 break;
4365 default: {
4366 throw new IllegalArgumentException("Tried to set provisioning for "
4367 + "rcs capability '" + capability + "', which does not require "
4368 + "provisioning.");
4369 }
4370 }
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
4374
4375 }
4376
4377
4378 @Override
4379 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4380 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4381 final long identity = Binder.clearCallingIdentity();
4382 try {
4383 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4384 if (!isImsProvisioningRequired(subId, capability, false)) {
4385 return true;
4386 }
4387
4388 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4389 switch (capability) {
4390 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4391 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4392 return ims.isEabProvisionedOnDevice();
4393
4394 default: {
4395 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4396 + "capability '" + capability + "', which does not require "
4397 + "provisioning.");
4398 }
4399 }
4400
4401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
4404 }
4405
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004406 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004407 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4408 boolean isProvisioned) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004409 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4410 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004411 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4412 }
allenwtsu99c623b2020-01-03 18:24:23 +08004413 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004414 final long identity = Binder.clearCallingIdentity();
4415 try {
4416 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004417 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004418 return;
4419 }
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004420 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4421 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4422 loge("setImsProvisioningStatusForCapability: called for technology that does "
4423 + "not support provisioning - " + tech);
4424 return;
4425 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004426
4427 // this capability requires provisioning, route to the correct API.
4428 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4429 switch (capability) {
4430 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4431 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4432 ims.setVolteProvisioned(isProvisioned);
4433 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4434 ims.setWfcProvisioned(isProvisioned);
4435 }
4436 break;
4437 }
4438 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4439 // There is currently no difference in VT provisioning type.
4440 ims.setVtProvisioned(isProvisioned);
4441 break;
4442 }
4443 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4444 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4445 // change the capability of the feature instead if needed.
4446 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4447 == isProvisioned) {
4448 // No change in provisioning.
4449 return;
4450 }
4451 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4452 try {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004453 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004454 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004455 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4456 + ", Exception" + e.getMessage());
4457 }
4458 break;
4459 }
4460 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004461 throw new IllegalArgumentException("Tried to set provisioning for "
4462 + "MmTel capability '" + capability + "', which does not require "
4463 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004464 }
4465 }
4466
4467 } finally {
4468 Binder.restoreCallingIdentity(identity);
4469 }
4470 }
4471
4472 @Override
4473 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004474 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4475 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004476 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4477 }
4478 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4479 final long identity = Binder.clearCallingIdentity();
4480 try {
4481 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004482 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004483 return true;
4484 }
4485
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004486 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4487 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4488 loge("getImsProvisioningStatusForCapability: called for technology that does "
4489 + "not support provisioning - " + tech);
4490 return true;
4491 }
4492
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004493 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4494 switch (capability) {
4495 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4496 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4497 return ims.isVolteProvisionedOnDevice();
4498 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4499 return ims.isWfcProvisionedOnDevice();
4500 }
4501 // This should never happen, since we are checking tech above to make sure it
4502 // is either LTE or IWLAN.
4503 throw new IllegalArgumentException("Invalid radio technology for voice "
4504 + "capability.");
4505 }
4506 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4507 // There is currently no difference in VT provisioning type.
4508 return ims.isVtProvisionedOnDevice();
4509 }
4510 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4511 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4512 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4513 }
4514 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004515 throw new IllegalArgumentException(
4516 "Tried to get provisioning for MmTel capability '" + capability
4517 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004518 }
4519 }
4520
4521 } finally {
4522 Binder.restoreCallingIdentity(identity);
4523 }
4524 }
4525
4526 @Override
4527 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4528 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4529 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4530 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4531 }
4532 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4533 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4534 return (provisionedBits & capability) > 0;
4535 }
4536
4537 @Override
4538 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4539 boolean isProvisioned) {
4540 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4541 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4542 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4543 }
4544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4545 "setProvisioningStatusForCapability");
4546 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4547 // If the current provisioning status for capability already matches isProvisioned,
4548 // do nothing.
4549 if (((provisionedBits & capability) > 0) == isProvisioned) {
4550 return;
4551 }
4552 if (isProvisioned) {
4553 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4554 } else {
4555 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4556 }
4557 }
4558
4559 /**
4560 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4561 * technology. The bitfield should mirror the bitfield defined by
4562 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4563 */
4564 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4565 String key = getMmTelProvisioningKey(subId, tech);
4566 // Default is no capabilities are provisioned.
4567 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4568 }
4569
4570 /**
4571 * Sets the MmTel capability provisioning bitfield (defined by
4572 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4573 * technology specified.
4574 *
4575 * Note: This is a synchronous command and should not be called on UI thread.
4576 */
4577 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4578 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4579 String key = getMmTelProvisioningKey(subId, tech);
4580 editor.putInt(key, newField);
4581 editor.commit();
4582 }
4583
4584 private static String getMmTelProvisioningKey(int subId, int tech) {
4585 // resulting key is provision_ims_mmtel_{subId}_{tech}
4586 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4587 }
4588
4589 /**
4590 * Query CarrierConfig to see if the specified capability requires provisioning for the
4591 * carrier associated with the subscription id.
4592 */
4593 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4594 int capability) {
4595 CarrierConfigManager configManager = new CarrierConfigManager(context);
4596 PersistableBundle c = configManager.getConfigForSubId(subId);
4597 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004598 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004599 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4600 false);
4601 boolean requireVoiceVtProvisioning = c.getBoolean(
4602 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4603
4604 // First check to make sure that the capability requires provisioning.
4605 switch (capability) {
4606 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4607 // intentional fallthrough
4608 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4609 if (requireVoiceVtProvisioning) {
4610 // Voice and Video requires provisioning
4611 return true;
4612 }
4613 break;
4614 }
4615 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4616 if (requireUtProvisioning) {
4617 // UT requires provisioning
4618 return true;
4619 }
4620 break;
4621 }
4622 }
4623 return false;
4624 }
4625
allenwtsu99c623b2020-01-03 18:24:23 +08004626 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4627 int capability) {
4628 CarrierConfigManager configManager = new CarrierConfigManager(context);
4629 PersistableBundle c = configManager.getConfigForSubId(subId);
4630
4631 boolean requireRcsProvisioning = c.getBoolean(
4632 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4633
4634 // First check to make sure that the capability requires provisioning.
4635 switch (capability) {
4636 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4637 // intentional fallthrough
4638 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4639 if (requireRcsProvisioning) {
4640 // OPTION or PRESENCE requires provisioning
4641 return true;
4642 }
4643 break;
4644 }
4645 }
4646 return false;
4647 }
4648
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004649 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004650 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004651 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4652 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4653 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004654 enforceReadPrivilegedPermission("getImsProvisioningInt");
4655 final long identity = Binder.clearCallingIdentity();
4656 try {
4657 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004658 int slotId = getSlotIndex(subId);
4659 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4660 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4661 + subId + "' for key:" + key);
4662 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4663 }
calvinpan9cfff472021-02-08 19:59:36 +08004664 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004665 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004666 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4667 + subId + "' for key:" + key);
4668 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004669 } finally {
4670 Binder.restoreCallingIdentity(identity);
4671 }
4672 }
4673
4674 @Override
4675 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004676 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4677 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4678 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004679 enforceReadPrivilegedPermission("getImsProvisioningString");
4680 final long identity = Binder.clearCallingIdentity();
4681 try {
4682 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004683 int slotId = getSlotIndex(subId);
4684 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4685 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4686 + subId + "' for key:" + key);
4687 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4688 }
calvinpan9cfff472021-02-08 19:59:36 +08004689 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004690 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004691 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4692 + subId + "' for key:" + key);
4693 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004694 } finally {
4695 Binder.restoreCallingIdentity(identity);
4696 }
4697 }
4698
4699 @Override
4700 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004701 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4702 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4703 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4705 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004706 final long identity = Binder.clearCallingIdentity();
4707 try {
4708 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004709 int slotId = getSlotIndex(subId);
4710 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4711 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4712 + subId + "' for key:" + key);
4713 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4714 }
calvinpan9cfff472021-02-08 19:59:36 +08004715 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4716 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004717 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004718 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004719 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004720 } finally {
4721 Binder.restoreCallingIdentity(identity);
4722 }
4723 }
4724
4725 @Override
4726 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004727 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4728 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4729 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4731 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004732 final long identity = Binder.clearCallingIdentity();
4733 try {
4734 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004735 int slotId = getSlotIndex(subId);
4736 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4737 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4738 + subId + "' for key:" + key);
4739 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4740 }
calvinpan9cfff472021-02-08 19:59:36 +08004741 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4742 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004743 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004744 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004745 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004746 } finally {
4747 Binder.restoreCallingIdentity(identity);
4748 }
4749 }
4750
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004751 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004752 int slotId = SubscriptionManager.getSlotIndex(subId);
4753 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004754 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4755 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004756 }
4757 return slotId;
4758 }
4759
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004760 private int getSlotIndex(int subId) {
4761 int slotId = SubscriptionManager.getSlotIndex(subId);
4762 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4763 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4764 }
4765 return slotId;
4766 }
4767
Wink Saville36469e72014-06-11 15:17:00 -07004768 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004769 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004770 */
4771 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004772 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4773 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004774 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004775 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004776 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004777 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004778 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004779 mApp, subId, callingPackage, callingFeatureId,
4780 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004781 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4782 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004783
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 final long identity = Binder.clearCallingIdentity();
4785 try {
4786 final Phone phone = getPhone(subId);
4787 if (phone != null) {
4788 return phone.getServiceState().getDataNetworkType();
4789 } else {
4790 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4791 }
4792 } finally {
4793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004795 }
4796
4797 /**
4798 * Returns the data network type
4799 */
4800 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004801 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004802 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4803 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004804 }
4805
4806 /**
4807 * Returns the data network type for a subId
4808 */
4809 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004810 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4811 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004812 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004813 mApp, subId, callingPackage, callingFeatureId,
4814 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004815 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4816 }
4817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 final long identity = Binder.clearCallingIdentity();
4819 try {
4820 final Phone phone = getPhone(subId);
4821 if (phone != null) {
4822 return phone.getServiceState().getDataNetworkType();
4823 } else {
4824 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4825 }
4826 } finally {
4827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004829 }
4830
4831 /**
Wink Saville36469e72014-06-11 15:17:00 -07004832 * Returns the Voice network type for a subId
4833 */
4834 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004835 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4836 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004838 mApp, subId, callingPackage, callingFeatureId,
4839 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004840 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4841 }
4842
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004843 final long identity = Binder.clearCallingIdentity();
4844 try {
4845 final Phone phone = getPhone(subId);
4846 if (phone != null) {
4847 return phone.getServiceState().getVoiceNetworkType();
4848 } else {
4849 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4850 }
4851 } finally {
4852 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004853 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004854 }
4855
4856 /**
4857 * @return true if a ICC card is present
4858 */
4859 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004860 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004861 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4862 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004863 }
4864
4865 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004866 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004867 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004868 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004869 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 final Phone phone = PhoneFactory.getPhone(slotIndex);
4873 if (phone != null) {
4874 return phone.getIccCard().hasIccCard();
4875 } else {
4876 return false;
4877 }
4878 } finally {
4879 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004881 }
4882
4883 /**
4884 * Return if the current radio is LTE on CDMA. This
4885 * is a tri-state return value as for a period of time
4886 * the mode may be unknown.
4887 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004888 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004889 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004890 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004891 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004892 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004893 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4894 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4895 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004896 }
4897
Sanket Padawe356d7632015-06-22 14:03:32 -07004898 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004899 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4900 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004901 try {
4902 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4903 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004904 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4905 }
4906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 final Phone phone = getPhone(subId);
4910 if (phone == null) {
4911 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4912 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004913 return TelephonyProperties.lte_on_cdma_device()
4914 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004915 }
4916 } finally {
4917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004918 }
Wink Saville36469e72014-06-11 15:17:00 -07004919 }
4920
Wink Saville36469e72014-06-11 15:17:00 -07004921 /**
4922 * {@hide}
4923 * Returns Default subId, 0 in the case of single standby.
4924 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004925 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004926 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004927 }
4928
Shishir Agrawala9f32182016-04-12 12:00:16 -07004929 private int getSlotForDefaultSubscription() {
4930 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4931 }
4932
Wink Savilleb564aae2014-10-23 10:18:09 -07004933 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004934 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004935 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004936
Pengquan Menge92a50d2018-09-21 15:54:48 -07004937 private boolean isActiveSubscription(int subId) {
4938 return mSubscriptionController.isActiveSubId(subId);
4939 }
4940
Ihab Awadf2177b72013-11-25 13:33:23 -08004941 /**
4942 * @see android.telephony.TelephonyManager.WifiCallingChoices
4943 */
4944 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945 final long identity = Binder.clearCallingIdentity();
4946 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004947 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4949 getWhenToMakeWifiCallsDefaultPreference());
4950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004953 }
4954
4955 /**
4956 * @see android.telephony.TelephonyManager.WifiCallingChoices
4957 */
4958 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 final long identity = Binder.clearCallingIdentity();
4960 try {
4961 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004962 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004963 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004967 }
4968
Sailesh Nepald1e68152013-12-12 19:08:02 -08004969 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004970 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004971 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004972 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004973
Jordan Liu4c733742019-02-28 12:03:40 -08004974 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4975 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4976 if (phoneId == -1) {
4977 throw new IllegalArgumentException("Given slot index: " + slotIndex
4978 + " does not correspond to an active phone");
4979 }
4980 return PhoneFactory.getPhone(phoneId);
4981 }
4982
Shishir Agrawal566b7612013-10-28 14:41:00 -07004983 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004984 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4985 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4987 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004989 if (DBG) {
4990 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4991 }
4992 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4993 p2);
4994 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004995
Jordan Liu4c733742019-02-28 12:03:40 -08004996
4997 @Override
4998 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4999 int slotIndex, String callingPackage, String aid, int p2) {
5000 enforceModifyPermission();
5001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5002 if (DBG) {
5003 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5004 }
5005 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5006 callingPackage, aid, p2);
5007 }
5008
5009 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5010 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 final long identity = Binder.clearCallingIdentity();
5012 try {
5013 if (TextUtils.equals(ISDR_AID, aid)) {
5014 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005015 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5016 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 if (bestComponent == null
5018 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5019 loge("The calling package is not allowed to access ISD-R.");
5020 throw new SecurityException(
5021 "The calling package is not allowed to access ISD-R.");
5022 }
Derek Tan740e1672017-06-27 14:56:27 -07005023 }
Derek Tan740e1672017-06-27 14:56:27 -07005024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005026 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5027 null /* workSource */);
5028 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029 return response;
5030 } finally {
5031 Binder.restoreCallingIdentity(identity);
5032 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005033 }
5034
5035 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005036 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5038 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005039 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5040 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5041 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005042
Jordan Liu4c733742019-02-28 12:03:40 -08005043 @Override
5044 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5045 enforceModifyPermission();
5046 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5047 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5048 channel);
5049 }
5050
5051 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 final long identity = Binder.clearCallingIdentity();
5053 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 if (channel < 0) {
5055 return false;
5056 }
Jordan Liu4c733742019-02-28 12:03:40 -08005057 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5058 null /* workSource */);
5059 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005060 return success;
5061 } finally {
5062 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005063 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005064 }
5065
5066 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005067 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005068 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5070 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005071 if (DBG) {
5072 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5073 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5074 + p3 + " data=" + data);
5075 }
5076 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5077 command, p1, p2, p3, data);
5078 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005079
Jordan Liu4c733742019-02-28 12:03:40 -08005080 @Override
5081 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5082 int command, int p1, int p2, int p3, String data) {
5083 enforceModifyPermission();
5084 if (DBG) {
5085 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5086 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5087 + p3 + " data=" + data);
5088 }
5089 return iccTransmitApduLogicalChannelWithPermission(
5090 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5091 data);
5092 }
5093
5094 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5095 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 final long identity = Binder.clearCallingIdentity();
5097 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005098 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005099 return "";
5100 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005103 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5104 null /* workSource */);
5105 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005107 // Append the returned status code to the end of the response payload.
5108 String s = Integer.toHexString(
5109 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5110 if (response.payload != null) {
5111 s = IccUtils.bytesToHexString(response.payload) + s;
5112 }
5113 return s;
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005116 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005117 }
Jake Hambye994d462014-02-03 13:10:13 -08005118
Evan Charltonc66da362014-05-16 14:06:40 -07005119 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005120 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5121 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5123 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005125 if (DBG) {
5126 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5127 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5128 }
5129 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5130 cla, command, p1, p2, p3, data);
5131 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005132
Jordan Liu4c733742019-02-28 12:03:40 -08005133 @Override
5134 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5135 int command, int p1, int p2, int p3, String data) {
5136 enforceModifyPermission();
5137 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5138 if (DBG) {
5139 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5140 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5141 + " data=" + data);
5142 }
5143
5144 return iccTransmitApduBasicChannelWithPermission(
5145 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5146 p2, p3, data);
5147 }
5148
5149 // open APDU basic channel assuming the caller has sufficient permissions
5150 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5151 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152 final long identity = Binder.clearCallingIdentity();
5153 try {
5154 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5155 && TextUtils.equals(ISDR_AID, data)) {
5156 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005157 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5158 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 if (bestComponent == null
5160 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5161 loge("The calling package is not allowed to select ISD-R.");
5162 throw new SecurityException(
5163 "The calling package is not allowed to select ISD-R.");
5164 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005165 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005168 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5169 null /* workSource */);
5170 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005171
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 // Append the returned status code to the end of the response payload.
5173 String s = Integer.toHexString(
5174 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5175 if (response.payload != null) {
5176 s = IccUtils.bytesToHexString(response.payload) + s;
5177 }
5178 return s;
5179 } finally {
5180 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005181 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005182 }
5183
5184 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005185 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005186 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5188 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005189
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 final long identity = Binder.clearCallingIdentity();
5191 try {
5192 if (DBG) {
5193 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5194 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5195 }
5196
5197 IccIoResult response =
5198 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5199 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5200 subId);
5201
5202 if (DBG) {
5203 log("Exchange SIM_IO [R]" + response);
5204 }
5205
5206 byte[] result = null;
5207 int length = 2;
5208 if (response.payload != null) {
5209 length = 2 + response.payload.length;
5210 result = new byte[length];
5211 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5212 } else {
5213 result = new byte[length];
5214 }
5215
5216 result[length - 1] = (byte) response.sw2;
5217 result[length - 2] = (byte) response.sw1;
5218 return result;
5219 } finally {
5220 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005221 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005222 }
5223
Nathan Haroldb3014052017-01-25 15:57:32 -08005224 /**
5225 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5226 * on a particular subscription
5227 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005228 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5229 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005230 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005231 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005232 return null;
5233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234
5235 final long identity = Binder.clearCallingIdentity();
5236 try {
5237 if (appType != TelephonyManager.APPTYPE_USIM
5238 && appType != TelephonyManager.APPTYPE_SIM) {
5239 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5240 return null;
5241 }
5242 Object response = sendRequest(
5243 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5244 if (response instanceof String[]) {
5245 return (String[]) response;
5246 }
yincheng zhaod698b842019-09-06 17:06:54 -07005247 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005248 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005249 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 } finally {
5251 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005252 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005253 }
5254
yincheng zhaod698b842019-09-06 17:06:54 -07005255 /**
5256 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5257 * subscription.
5258 *
5259 * @param subId the id of the subscription.
5260 * @param appType the uicc app type, must be USIM or SIM.
5261 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5262 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005263 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005264 * @return number of fplmns that is successfully written to the SIM.
5265 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005266 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5267 String callingFeatureId) {
5268 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5269 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005270 if (DBG) logv("no permissions for setForbiddenplmns");
5271 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5272 }
5273 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5274 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5275 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5276 }
5277 if (fplmns == null) {
5278 throw new IllegalArgumentException("Fplmn List provided is null");
5279 }
5280 for (String fplmn : fplmns) {
5281 if (!CellIdentity.isValidPlmn(fplmn)) {
5282 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5283 }
5284 }
5285 final long identity = Binder.clearCallingIdentity();
5286 try {
5287 Object response = sendRequest(
5288 CMD_SET_FORBIDDEN_PLMNS,
5289 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5290 subId);
5291 return (int) response;
5292 } finally {
5293 Binder.restoreCallingIdentity(identity);
5294 }
5295 }
5296
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005297 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005298 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5300 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005302 final long identity = Binder.clearCallingIdentity();
5303 try {
5304 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5305 if (response.payload == null) {
5306 return "";
5307 }
Evan Charltonc66da362014-05-16 14:06:40 -07005308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 // Append the returned status code to the end of the response payload.
5310 String s = Integer.toHexString(
5311 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5312 s = IccUtils.bytesToHexString(response.payload) + s;
5313 return s;
5314 } finally {
5315 Binder.restoreCallingIdentity(identity);
5316 }
Evan Charltonc66da362014-05-16 14:06:40 -07005317 }
5318
Jake Hambye994d462014-02-03 13:10:13 -08005319 /**
5320 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5321 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5322 *
5323 * @param itemID the ID of the item to read
5324 * @return the NV item as a String, or null on error.
5325 */
5326 @Override
5327 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005328 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5330 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331
5332 final long identity = Binder.clearCallingIdentity();
5333 try {
5334 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005335 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5337 return value;
5338 } finally {
5339 Binder.restoreCallingIdentity(identity);
5340 }
Jake Hambye994d462014-02-03 13:10:13 -08005341 }
5342
5343 /**
5344 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5345 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5346 *
5347 * @param itemID the ID of the item to read
5348 * @param itemValue the value to write, as a String
5349 * @return true on success; false on any failure
5350 */
5351 @Override
5352 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005353 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5355 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356
5357 final long identity = Binder.clearCallingIdentity();
5358 try {
5359 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5360 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005361 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5363 return success;
5364 } finally {
5365 Binder.restoreCallingIdentity(identity);
5366 }
Jake Hambye994d462014-02-03 13:10:13 -08005367 }
5368
5369 /**
5370 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5371 * Used for device configuration by some CDMA operators.
5372 *
5373 * @param preferredRoamingList byte array containing the new PRL
5374 * @return true on success; false on any failure
5375 */
5376 @Override
5377 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5379 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380
5381 final long identity = Binder.clearCallingIdentity();
5382 try {
5383 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5384 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5385 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5386 return success;
5387 } finally {
5388 Binder.restoreCallingIdentity(identity);
5389 }
Jake Hambye994d462014-02-03 13:10:13 -08005390 }
5391
5392 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005393 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005394 * Used for device configuration by some CDMA operators.
5395 *
chen xu6dac5ab2018-10-26 17:39:23 -07005396 * @param slotIndex - device slot.
5397 *
Jake Hambye994d462014-02-03 13:10:13 -08005398 * @return true on success; false on any failure
5399 */
5400 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005401 public boolean resetModemConfig(int slotIndex) {
5402 Phone phone = PhoneFactory.getPhone(slotIndex);
5403 if (phone != null) {
5404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5405 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406
chen xu6dac5ab2018-10-26 17:39:23 -07005407 final long identity = Binder.clearCallingIdentity();
5408 try {
5409 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5410 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5411 return success;
5412 } finally {
5413 Binder.restoreCallingIdentity(identity);
5414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 }
chen xu6dac5ab2018-10-26 17:39:23 -07005416 return false;
5417 }
5418
5419 /**
5420 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5421 *
5422 * @param slotIndex - device slot.
5423 *
5424 * @return true on success; false on any failure
5425 */
5426 @Override
5427 public boolean rebootModem(int slotIndex) {
5428 Phone phone = PhoneFactory.getPhone(slotIndex);
5429 if (phone != null) {
5430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5431 mApp, phone.getSubId(), "rebootModem");
5432
5433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5436 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5437 return success;
5438 } finally {
5439 Binder.restoreCallingIdentity(identity);
5440 }
5441 }
5442 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005443 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005444
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005445 public String[] getPcscfAddress(String apnType, String callingPackage,
5446 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005447 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005448 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5449 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005450 return new String[0];
5451 }
5452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005453 final long identity = Binder.clearCallingIdentity();
5454 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005455 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456 } finally {
5457 Binder.restoreCallingIdentity(identity);
5458 }
Wink Saville36469e72014-06-11 15:17:00 -07005459 }
5460
Brad Ebinger51f743a2017-01-23 13:50:20 -08005461 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005462 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5463 * {@link #disableIms(int)}.
5464 * @param slotIndex device slot.
5465 */
5466 public void resetIms(int slotIndex) {
5467 enforceModifyPermission();
5468
5469 final long identity = Binder.clearCallingIdentity();
5470 try {
5471 if (mImsResolver == null) {
5472 // may happen if the does not support IMS.
5473 return;
5474 }
5475 mImsResolver.disableIms(slotIndex);
5476 mImsResolver.enableIms(slotIndex);
5477 } finally {
5478 Binder.restoreCallingIdentity(identity);
5479 }
5480 }
5481
5482 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005483 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5484 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005485 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005486 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005487 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488
5489 final long identity = Binder.clearCallingIdentity();
5490 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005491 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005492 // may happen if the device does not support IMS.
5493 return;
5494 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005495 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496 } finally {
5497 Binder.restoreCallingIdentity(identity);
5498 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005499 }
5500
5501 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005502 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5503 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005504 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005505 public void disableIms(int slotId) {
5506 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507
5508 final long identity = Binder.clearCallingIdentity();
5509 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005510 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005511 // may happen if the device does not support IMS.
5512 return;
5513 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005514 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005518 }
5519
5520 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005521 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5522 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005523 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005524 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005525 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527
5528 final long identity = Binder.clearCallingIdentity();
5529 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005530 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005531 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5532 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005533 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005534 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005535 } finally {
5536 Binder.restoreCallingIdentity(identity);
5537 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005538 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005539 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005540 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5541 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005542 @Override
5543 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005544 enforceModifyPermission();
5545
5546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005549 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005550 } finally {
5551 Binder.restoreCallingIdentity(identity);
5552 }
5553 }
5554
5555 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005556 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005557 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005558 */
5559 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5560 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005564 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005565 // may happen if the device does not support IMS.
5566 return null;
5567 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005568 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005572 }
5573
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005574 /**
5575 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005576 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005577 */
5578 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5579 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005583 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005584 // may happen if the device does not support IMS.
5585 return null;
5586 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005587 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005591 }
5592
Brad Ebinger884c07b2018-02-15 16:17:40 -08005593 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005594 * Sets the ImsService Package Name that Telephony will bind to.
5595 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005596 * @param slotIndex the slot ID that the ImsService should bind for.
5597 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005598 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005599 * @param featureTypes An integer array of feature types associated with a packageName.
5600 * @param packageName The name of the package that the current configuration will be replaced
5601 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005602 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005603 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005604 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5605 int[] featureTypes, String packageName) {
5606 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5607 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5609 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005610 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 final long identity = Binder.clearCallingIdentity();
5613 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005614 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005615 // may happen if the device does not support IMS.
5616 return false;
5617 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005618 Map<Integer, String> featureConfig = new HashMap<>();
5619 for (int featureType : featureTypes) {
5620 featureConfig.put(featureType, packageName);
5621 }
5622 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5623 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005627 }
5628
5629 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005630 * Clears any carrier ImsService overrides for the slot index specified that were previously
5631 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5632 *
5633 * This should only be used for testing.
5634 *
5635 * @param slotIndex the slot ID that the ImsService should bind for.
5636 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5637 */
5638 @Override
5639 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5640 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5642 "clearCarrierImsServiceOverride");
5643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5644 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5645 "clearCarrierImsServiceOverride");
5646
5647 final long identity = Binder.clearCallingIdentity();
5648 try {
5649 if (mImsResolver == null) {
5650 // may happen if the device does not support IMS.
5651 return false;
5652 }
5653 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
5657 }
5658
5659 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005660 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005661 *
5662 * @param slotId The slot that the ImsService is associated with.
5663 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5664 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005665 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005666 * @return the package name of the ImsService configuration.
5667 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005668 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5669 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005670 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005671 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005672 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005673 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5674 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 final long identity = Binder.clearCallingIdentity();
5677 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005678 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005679 // may happen if the device does not support IMS.
5680 return "";
5681 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005682 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005683 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5684 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005688 }
5689
Brad Ebinger77b832e2019-10-17 17:03:22 -07005690 /**
5691 * Get the MmTelFeature state associated with the requested subscription id.
5692 * @param subId The subscription that the MmTelFeature is associated with.
5693 * @param callback A callback with an integer containing the
5694 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5695 */
5696 @Override
5697 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5698 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5699 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5700 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5701 "IMS not available on device.");
5702 }
5703 final long token = Binder.clearCallingIdentity();
5704 try {
5705 int slotId = getSlotIndex(subId);
5706 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5707 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5708 + subId + "'");
5709 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5710 }
5711 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5712 try {
5713 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5714 } catch (RemoteException e) {
5715 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5716 + "Ignore");
5717 }
5718 });
5719 } finally {
5720 Binder.restoreCallingIdentity(token);
5721 }
5722 }
5723
Daniel Brightbb5840b2021-01-12 15:48:18 -08005724 /**
5725 * Sets the ims registration state on all valid {@link Phone}s.
5726 */
5727 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005728 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729
5730 final long identity = Binder.clearCallingIdentity();
5731 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005732 // NOTE: Before S, this method only set the default phone.
5733 for (final Phone phone : PhoneFactory.getPhones()) {
5734 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5735 phone.setImsRegistrationState(registered);
5736 }
5737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
Wink Saville36469e72014-06-11 15:17:00 -07005741 }
5742
5743 /**
Stuart Scott54788802015-03-30 13:18:01 -07005744 * Set the network selection mode to automatic.
5745 *
5746 */
5747 @Override
5748 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5750 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751
5752 final long identity = Binder.clearCallingIdentity();
5753 try {
shilufc958392020-01-20 11:36:01 -08005754 if (!isActiveSubscription(subId)) {
5755 return;
5756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005758 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5759 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760 } finally {
5761 Binder.restoreCallingIdentity(identity);
5762 }
Stuart Scott54788802015-03-30 13:18:01 -07005763 }
5764
Jack Yud10cdd42020-09-28 20:28:01 -07005765 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005766 * Ask the radio to connect to the input network and change selection mode to manual.
5767 *
5768 * @param subId the id of the subscription.
5769 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5770 * the operator to attach to.
5771 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5772 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5773 * normal network selection next time.
5774 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005775 */
5776 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005777 public boolean setNetworkSelectionModeManual(
5778 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5780 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005781
5782 if (!isActiveSubscription(subId)) {
5783 return false;
5784 }
5785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 final long identity = Binder.clearCallingIdentity();
5787 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005788 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005790 if (DBG) {
5791 log("setNetworkSelectionModeManual: subId: " + subId
5792 + " operator: " + operatorInfo);
5793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005798 }
shilu84f6e8b2019-12-19 13:58:01 -08005799 /**
5800 * Get the manual network selection
5801 *
5802 * @param subId the id of the subscription.
5803 *
5804 * @return the previously saved user selected PLMN
5805 */
5806 @Override
5807 public String getManualNetworkSelectionPlmn(int subId) {
5808 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005809 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005810 mApp, subId, "getManualNetworkSelectionPlmn");
5811
5812 final long identity = Binder.clearCallingIdentity();
5813 try {
5814 if (!isActiveSubscription(subId)) {
5815 return "";
5816 }
5817
5818 final Phone phone = getPhone(subId);
5819 if (phone == null) {
5820 return "";
5821 }
5822 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5823 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5824 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5825 } finally {
5826 Binder.restoreCallingIdentity(identity);
5827 }
5828 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005829
5830 /**
5831 * Scans for available networks.
5832 */
5833 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005834 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5835 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5837 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005838 LocationAccessPolicy.LocationPermissionResult locationResult =
5839 LocationAccessPolicy.checkLocationPermission(mApp,
5840 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5841 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005842 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005843 .setCallingPid(Binder.getCallingPid())
5844 .setCallingUid(Binder.getCallingUid())
5845 .setMethod("getCellNetworkScanResults")
5846 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07005847 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5848 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005849 .build());
5850 switch (locationResult) {
5851 case DENIED_HARD:
5852 throw new SecurityException("Not allowed to access scan results -- location");
5853 case DENIED_SOFT:
5854 return null;
5855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856
Pengquan Menga1bb6272018-09-06 09:59:22 -07005857 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 try {
5859 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005860 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005865 }
5866
5867 /**
sqian80370722020-01-29 15:02:51 -08005868 * Get the call forwarding info, given the call forwarding reason.
5869 */
5870 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005871 public void getCallForwarding(int subId, int callForwardingReason,
5872 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005873 enforceReadPrivilegedPermission("getCallForwarding");
5874 long identity = Binder.clearCallingIdentity();
5875 try {
5876 if (DBG) {
5877 log("getCallForwarding: subId " + subId
5878 + " callForwardingReason" + callForwardingReason);
5879 }
Hall Liua1acea22020-09-18 19:04:59 -07005880
5881 Phone phone = getPhone(subId);
5882 if (phone == null) {
5883 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005884 callback.onError(
5885 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005886 } catch (RemoteException e) {
5887 // ignore
5888 }
5889 return;
5890 }
5891
5892 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5893 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5894 @Override
5895 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5896 try {
5897 callback.onCallForwardingInfoAvailable(info);
5898 } catch (RemoteException e) {
5899 // ignore
5900 }
5901 }
5902
5903 @Override
5904 public void onError(int error) {
5905 try {
5906 callback.onError(error);
5907 } catch (RemoteException e) {
5908 // ignore
5909 }
5910 }
5911 });
5912 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
5916 }
5917
5918 /**
5919 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5920 * reason, the number to forward, and the timeout before the forwarding is attempted.
5921 */
5922 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005923 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5924 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005925 enforceModifyPermission();
5926 long identity = Binder.clearCallingIdentity();
5927 try {
5928 if (DBG) {
5929 log("setCallForwarding: subId " + subId
5930 + " callForwardingInfo" + callForwardingInfo);
5931 }
Hall Liua1acea22020-09-18 19:04:59 -07005932
5933 Phone phone = getPhone(subId);
5934 if (phone == null) {
5935 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005936 callback.accept(
5937 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005938 } catch (RemoteException e) {
5939 // ignore
5940 }
5941 return;
5942 }
5943
5944 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5945 FunctionalUtils.ignoreRemoteException(callback::accept));
5946
5947 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
5951 }
5952
5953 /**
Hall Liua1acea22020-09-18 19:04:59 -07005954 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005955 */
5956 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005957 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWangc63cf522021-03-31 22:08:45 +08005958 enforceReadPrivilegedPermission("getCallWaitingStatus");
sqian80370722020-01-29 15:02:51 -08005959 long identity = Binder.clearCallingIdentity();
5960 try {
Hall Liua1acea22020-09-18 19:04:59 -07005961 Phone phone = getPhone(subId);
5962 if (phone == null) {
5963 try {
5964 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5965 } catch (RemoteException e) {
5966 // ignore
5967 }
5968 return;
5969 }
SongFerngWangc63cf522021-03-31 22:08:45 +08005970 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5971 PersistableBundle c = configManager.getConfigForSubId(subId);
5972 boolean requireUssd = c.getBoolean(
5973 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005974
sqian80370722020-01-29 15:02:51 -08005975 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWangc63cf522021-03-31 22:08:45 +08005976 if (requireUssd) {
5977 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5978 getSubscriptionCarrierId(subId));
5979 String newUssdCommand = "";
5980 try {
5981 newUssdCommand = carrierXmlParser.getFeature(
5982 CarrierXmlParser.FEATURE_CALL_WAITING)
5983 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
5984 } catch (NullPointerException e) {
5985 loge("Failed to generate USSD number" + e);
5986 }
5987 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5988 mMainThreadHandler, callback, carrierXmlParser,
5989 CarrierXmlParser.SsEntry.SSAction.QUERY);
5990 final String ussdCommand = newUssdCommand;
5991 Executors.newSingleThreadExecutor().execute(() -> {
5992 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5993 });
5994 } else {
5995 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
5996 callback::accept);
5997 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
5998 }
sqian80370722020-01-29 15:02:51 -08005999 } finally {
6000 Binder.restoreCallingIdentity(identity);
6001 }
6002 }
6003
6004 /**
Hall Liua1acea22020-09-18 19:04:59 -07006005 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08006006 */
6007 @Override
Hall Liua1acea22020-09-18 19:04:59 -07006008 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08006009 enforceModifyPermission();
6010 long identity = Binder.clearCallingIdentity();
6011 try {
Hall Liua1acea22020-09-18 19:04:59 -07006012 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6013
6014 Phone phone = getPhone(subId);
6015 if (phone == null) {
6016 try {
6017 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6018 } catch (RemoteException e) {
6019 // ignore
6020 }
6021 return;
6022 }
6023
SongFerngWangc63cf522021-03-31 22:08:45 +08006024 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6025 PersistableBundle c = configManager.getConfigForSubId(subId);
6026 boolean requireUssd = c.getBoolean(
6027 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07006028
SongFerngWangc63cf522021-03-31 22:08:45 +08006029 if (DBG) log("getCallWaitingStatus: subId " + subId);
6030 if (requireUssd) {
6031 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6032 getSubscriptionCarrierId(subId));
6033 CarrierXmlParser.SsEntry.SSAction ssAction =
6034 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6035 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6036 String newUssdCommand = "";
6037 try {
6038 newUssdCommand = carrierXmlParser.getFeature(
6039 CarrierXmlParser.FEATURE_CALL_WAITING)
6040 .makeCommand(ssAction, null);
6041 } catch (NullPointerException e) {
6042 loge("Failed to generate USSD number" + e);
6043 }
6044 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6045 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6046 final String ussdCommand = newUssdCommand;
6047 Executors.newSingleThreadExecutor().execute(() -> {
6048 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6049 });
6050 } else {
6051 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6052 FunctionalUtils.ignoreRemoteException(callback::accept));
6053
6054 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6055 }
sqian80370722020-01-29 15:02:51 -08006056 } finally {
6057 Binder.restoreCallingIdentity(identity);
6058 }
6059 }
6060
6061 /**
yinxub1bed742017-04-17 11:45:04 -07006062 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006063 *
yinxub1bed742017-04-17 11:45:04 -07006064 * @param subId id of the subscription
6065 * @param request contains the radio access networks with bands/channels to scan
6066 * @param messenger callback messenger for scan results or errors
6067 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006068 * @return the id of the requested scan which can be used to stop the scan.
6069 */
6070 @Override
6071 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006072 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6074 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006075 LocationAccessPolicy.LocationPermissionResult locationResult =
6076 LocationAccessPolicy.checkLocationPermission(mApp,
6077 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6078 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006079 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006080 .setCallingPid(Binder.getCallingPid())
6081 .setCallingUid(Binder.getCallingUid())
6082 .setMethod("requestNetworkScan")
6083 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6084 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006085 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07006086 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6087 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006088 if (e != null) {
6089 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6090 throw e;
6091 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006092 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006093 return TelephonyScanManager.INVALID_SCAN_ID;
6094 }
6095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 }
Hall Liu912dfd32019-04-25 14:02:26 -07006097 int callingUid = Binder.getCallingUid();
6098 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006099 final long identity = Binder.clearCallingIdentity();
6100 try {
6101 return mNetworkScanRequestTracker.startNetworkScan(
6102 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006103 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006104 } finally {
6105 Binder.restoreCallingIdentity(identity);
6106 }
yinxu504e1392017-04-12 16:03:22 -07006107 }
6108
Hall Liub2ac8ef2019-02-28 15:56:23 -08006109 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07006110 NetworkScanRequest request, int subId, String callingPackage) {
6111 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006112 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6113 boolean hasNetworkScanPermission =
6114 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6115 == PERMISSION_GRANTED;
6116
6117 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6118 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6119 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006120 }
6121
6122 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6123 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006124 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6125 return new SecurityException("Specific channels must not be"
6126 + " scanned without location access.");
6127 }
6128 }
6129 }
6130
Hall Liub2ac8ef2019-02-28 15:56:23 -08006131 return null;
6132 }
6133
yinxu504e1392017-04-12 16:03:22 -07006134 /**
6135 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006136 *
6137 * @param subId id of the subscription
6138 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006139 */
6140 @Override
6141 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6143 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144
Hall Liu912dfd32019-04-25 14:02:26 -07006145 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006146 final long identity = Binder.clearCallingIdentity();
6147 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006148 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 } finally {
6150 Binder.restoreCallingIdentity(identity);
6151 }
yinxu504e1392017-04-12 16:03:22 -07006152 }
6153
6154 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006155 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006156 *
SongFerngWang9e060372020-12-21 16:41:52 +08006157 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006158 */
6159 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006160 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006161 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006162 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006163 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164
6165 final long identity = Binder.clearCallingIdentity();
6166 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006167 if (DBG) log("getAllowedNetworkTypesBitmask");
6168 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6169 int networkTypesBitmask = (result != null ? result[0] : -1);
6170 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6171 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006175 }
6176
6177 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006178 * Get the allowed network types for certain reason.
6179 *
6180 * @param subId the id of the subscription.
6181 * @param reason the reason the allowed network type change is taking place
6182 * @return the allowed network types.
6183 */
6184 @Override
6185 public long getAllowedNetworkTypesForReason(int subId,
6186 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006187 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006188 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
6195 }
6196
6197 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006198 * Enable/Disable E-UTRA-NR Dual Connectivity
6199 * @param subId subscription id of the sim card
6200 * @param nrDualConnectivityState expected NR dual connectivity state
6201 * This can be passed following states
6202 * <ol>
6203 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6204 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6205 * <li>Disable NR dual connectivity and force secondary cell to be released
6206 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6207 * </ol>
6208 * @return operation result.
6209 */
6210 @Override
6211 public int setNrDualConnectivityState(int subId,
6212 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6214 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006215 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006216 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6217 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6218 }
6219
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006220 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6221 final long identity = Binder.clearCallingIdentity();
6222 try {
6223 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6224 nrDualConnectivityState, subId,
6225 workSource);
6226 if (DBG) log("enableNRDualConnectivity result: " + result);
6227 return result;
6228 } finally {
6229 Binder.restoreCallingIdentity(identity);
6230 }
6231 }
6232
6233 /**
6234 * Is E-UTRA-NR Dual Connectivity enabled
6235 * @return true if dual connectivity is enabled else false
6236 */
6237 @Override
6238 public boolean isNrDualConnectivityEnabled(int subId) {
6239 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006240 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006241 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006242 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006243 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6244 return false;
6245 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006246 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6247 final long identity = Binder.clearCallingIdentity();
6248 try {
6249 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6250 null, subId, workSource);
6251 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6252 return isEnabled;
6253 } finally {
6254 Binder.restoreCallingIdentity(identity);
6255 }
6256 }
6257
6258 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006259 * Set the allowed network types of the device and
6260 * provide the reason triggering the allowed network change.
6261 *
6262 * @param subId the id of the subscription.
6263 * @param reason the reason the allowed network type change is taking place
6264 * @param allowedNetworkTypes the allowed network types.
6265 * @return true on success; false on any failure.
6266 */
6267 @Override
6268 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006269 @TelephonyManager.AllowedNetworkTypesReason int reason,
6270 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6272 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006273 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWangc2d3ccc2021-04-15 19:46:33 +08006274 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6275 return false;
6276 }
6277 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6278 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang9e060372020-12-21 16:41:52 +08006279 return false;
6280 }
6281
SongFerngWang522637d2021-03-02 22:09:29 +08006282 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6283 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6284
6285
6286 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6287 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6288 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006289 }
SongFerngWang522637d2021-03-02 22:09:29 +08006290
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006291 final long identity = Binder.clearCallingIdentity();
6292 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006293 Boolean success = (Boolean) sendRequest(
6294 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6295 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6296
6297 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6298 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006299 } finally {
6300 Binder.restoreCallingIdentity(identity);
6301 }
6302 }
6303
6304 /**
Miaoa84611c2019-03-15 09:21:10 +08006305 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006306 *
Miaoa84611c2019-03-15 09:21:10 +08006307 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006308 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006309 * @hide
6310 */
6311 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006312 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006313 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006315 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 try {
Miaoa84611c2019-03-15 09:21:10 +08006317 if (phone != null) {
6318 return phone.hasMatchedTetherApnSetting();
6319 } else {
6320 return false;
6321 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 } finally {
6323 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006324 }
Junda Liu475951f2014-11-07 16:45:03 -08006325 }
6326
6327 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006328 * Enable or disable always reporting signal strength changes from radio.
6329 *
6330 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6331 */
6332 @Override
6333 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6334 enforceModifyPermission();
6335 enforceSystemCaller();
6336
6337 final long identity = Binder.clearCallingIdentity();
6338 final Phone phone = getPhone(subId);
6339 try {
6340 if (phone != null) {
6341 if (DBG) {
6342 log("setAlwaysReportSignalStrength: subId=" + subId
6343 + " isEnable=" + isEnable);
6344 }
6345 phone.setAlwaysReportSignalStrength(isEnable);
6346 } else {
6347 loge("setAlwaysReportSignalStrength: no phone found for subId="
6348 + subId);
6349 }
6350 } finally {
6351 Binder.restoreCallingIdentity(identity);
6352 }
6353 }
6354
6355 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006356 * Get the user enabled state of Mobile Data.
6357 *
6358 * TODO: remove and use isUserDataEnabled.
6359 * This can't be removed now because some vendor codes
6360 * calls through ITelephony directly while they should
6361 * use TelephonyManager.
6362 *
6363 * @return true on enabled
6364 */
6365 @Override
6366 public boolean getDataEnabled(int subId) {
6367 return isUserDataEnabled(subId);
6368 }
6369
6370 /**
6371 * Get whether mobile data is enabled per user setting.
6372 *
6373 * There are other factors deciding whether mobile data is actually enabled, but they are
6374 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006375 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006376 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006377 *
6378 * @return {@code true} if data is enabled else {@code false}
6379 */
6380 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006381 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006382 try {
6383 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6384 null);
6385 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6387 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389
6390 final long identity = Binder.clearCallingIdentity();
6391 try {
6392 int phoneId = mSubscriptionController.getPhoneId(subId);
6393 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6394 Phone phone = PhoneFactory.getPhone(phoneId);
6395 if (phone != null) {
6396 boolean retVal = phone.isUserDataEnabled();
6397 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6398 return retVal;
6399 } else {
6400 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6401 return false;
6402 }
6403 } finally {
6404 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006405 }
6406 }
6407
6408 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006409 * Checks if the device is capable of mobile data by considering whether whether the
6410 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6411 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006412 *
Shuo Qian985d1232020-01-08 14:30:06 -08006413 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006414 */
6415 @Override
6416 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006417 try {
6418 try {
6419 mApp.enforceCallingOrSelfPermission(
6420 android.Manifest.permission.ACCESS_NETWORK_STATE,
6421 null);
6422 } catch (Exception e) {
6423 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6424 "isDataEnabled");
6425 }
6426 } catch (Exception e) {
6427 enforceReadPrivilegedPermission("isDataEnabled");
6428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429
6430 final long identity = Binder.clearCallingIdentity();
6431 try {
6432 int phoneId = mSubscriptionController.getPhoneId(subId);
6433 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6434 Phone phone = PhoneFactory.getPhone(phoneId);
6435 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006436 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6438 return retVal;
6439 } else {
6440 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6441 return false;
6442 }
6443 } finally {
6444 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006445 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006446 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006447
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006448 /**
6449 * Check if data is enabled for a specific reason
6450 * @param subId Subscription index
6451 * @param reason the reason the data enable change is taking place
6452 * @return {@code true} if the overall data is enabled; {@code false} if not.
6453 */
6454 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006455 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006456 @TelephonyManager.DataEnabledReason int reason) {
6457 try {
6458 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6459 null);
6460 } catch (Exception e) {
6461 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006462 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006463 }
6464
6465
6466 final long identity = Binder.clearCallingIdentity();
6467 try {
6468 int phoneId = mSubscriptionController.getPhoneId(subId);
6469 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006470 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006471 + " reason=" + reason);
6472 }
6473 Phone phone = PhoneFactory.getPhone(phoneId);
6474 if (phone != null) {
6475 boolean retVal;
6476 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6477 retVal = phone.isUserDataEnabled();
6478 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006479 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006480 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006481 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006482 return retVal;
6483 } else {
6484 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006485 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006486 + subId + " retVal=false");
6487 }
6488 return false;
6489 }
6490 } finally {
6491 Binder.restoreCallingIdentity(identity);
6492 }
6493 }
6494
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006495 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006496 Phone phone) {
Sarah Chinca45c312021-04-09 10:37:15 -07006497 if (uid == Process.PHONE_UID) {
6498 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6499 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liuce478d22020-07-13 12:13:03 -07006500 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6501 }
6502
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006503 //load access rules from carrier configs, and check those as well: b/139133814
6504 SubscriptionController subController = SubscriptionController.getInstance();
6505 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6506 || subController == null) return privilegeFromSim;
6507
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006508 PackageManager pkgMgr = phone.getContext().getPackageManager();
6509 String[] packages = pkgMgr.getPackagesForUid(uid);
6510
6511 final long identity = Binder.clearCallingIdentity();
6512 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006513 int subId = phone.getSubId();
6514 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6515 // A test override is in place for the privileges for this subId, so don't try to
6516 // read the subscription privileges.
6517 return privilegeFromSim;
6518 }
6519 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006520 SubscriptionManager subManager = (SubscriptionManager)
6521 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6522 for (String pkg : packages) {
6523 if (subManager.canManageSubscription(subInfo, pkg)) {
6524 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6525 }
6526 }
6527 return privilegeFromSim;
6528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
6531 }
6532
6533 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6534 String pkgName) {
6535 //load access rules from carrier configs, and check those as well: b/139133814
6536 SubscriptionController subController = SubscriptionController.getInstance();
6537 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6538 || subController == null) return privilegeFromSim;
6539
6540 final long identity = Binder.clearCallingIdentity();
6541 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006542 int subId = phone.getSubId();
6543 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6544 // A test override is in place for the privileges for this subId, so don't try to
6545 // read the subscription privileges.
6546 return privilegeFromSim;
6547 }
6548 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006549 SubscriptionManager subManager = (SubscriptionManager)
6550 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6551 return subManager.canManageSubscription(subInfo, pkgName)
6552 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6553 } finally {
6554 Binder.restoreCallingIdentity(identity);
6555 }
6556 }
6557
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006558 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006559 public int getCarrierPrivilegeStatus(int subId) {
6560 final Phone phone = getPhone(subId);
6561 if (phone == null) {
6562 loge("getCarrierPrivilegeStatus: Invalid subId");
6563 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6564 }
6565 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006566 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006567 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006568 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6569 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006570
6571 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6572 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006573 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006574 }
Junda Liu29340342014-07-10 15:23:27 -07006575
6576 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006577 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006578 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006579 final Phone phone = getPhone(subId);
6580 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006581 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006582 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6583 }
6584 UiccProfile profile =
6585 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6586 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006587 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006588 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6589 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006590 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006591 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006592 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006593 }
6594
6595 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006596 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6597 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006598 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006599 }
6600
6601 int phoneId = SubscriptionManager.getPhoneId(subId);
6602 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006603 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006604 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006605 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6606 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006607 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6608 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6609 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006610 }
6611
6612 @Override
6613 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006614 if (TextUtils.isEmpty(pkgName))
6615 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006616 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6617 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6618 UiccCard card = UiccController.getInstance().getUiccCard(i);
6619 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006620 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006621 continue;
6622 }
6623
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006624 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6625 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6626 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006627 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6628 break;
6629 }
6630 }
6631
6632 return result;
Junda Liu29340342014-07-10 15:23:27 -07006633 }
Derek Tan89e89d42014-07-08 17:00:10 -07006634
6635 @Override
Junda Liue64de782015-04-16 17:19:16 -07006636 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6637 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6638 loge("phoneId " + phoneId + " is not valid.");
6639 return null;
6640 }
6641 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006642 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006643 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006644 return null ;
6645 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006646 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006647 }
6648
Amith Yamasani6e118872016-02-19 12:53:51 -08006649 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006650 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006651 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006652 List<String> privilegedPackages = new ArrayList<>();
6653 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006654 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6655 // has UICC in that slot.
6656 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006657 if (card.hasCarrierPrivilegeRules()) {
6658 if (packages == null) {
6659 // Only check packages in user 0 for now
6660 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006661 PackageManager.MATCH_DISABLED_COMPONENTS
6662 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006663 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006664 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006665 }
6666 for (int p = packages.size() - 1; p >= 0; p--) {
6667 PackageInfo pkgInfo = packages.get(p);
6668 if (pkgInfo != null && pkgInfo.packageName != null
6669 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006670 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006671 privilegedPackages.add(pkgInfo.packageName);
6672 }
6673 }
6674 }
6675 }
6676 return privilegedPackages;
6677 }
6678
chen xuf7e9fe82019-05-09 19:31:02 -07006679 @Override
6680 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006681 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6682
6683 final long identity = Binder.clearCallingIdentity();
6684
chen xuf7e9fe82019-05-09 19:31:02 -07006685 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006686 try {
6687 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6688 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6689 }
6690 } finally {
6691 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006692 }
6693 return privilegedPackages;
6694 }
6695
Wink Savilleb564aae2014-10-23 10:18:09 -07006696 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006697 final Phone phone = getPhone(subId);
6698 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006699 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006700 return null;
6701 }
6702 String iccId = card.getIccId();
6703 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006704 return null;
6705 }
6706 return iccId;
6707 }
6708
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006709 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006710 public void setCallComposerStatus(int subId, int status) {
6711 enforceModifyPermission();
6712
6713 final long identity = Binder.clearCallingIdentity();
6714 try {
6715 Phone phone = getPhone(subId);
6716 if (phone != null) {
6717 Phone defaultPhone = phone.getImsPhone();
6718 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6719 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6720 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006721 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6722 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006723 }
6724 }
Shuo Qiand8782462020-12-22 19:10:14 -08006725 } catch (ImsException e) {
6726 throw new ServiceSpecificException(e.getCode());
6727 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006728 Binder.restoreCallingIdentity(identity);
6729 }
6730 }
6731
6732 @Override
6733 public int getCallComposerStatus(int subId) {
6734 enforceReadPrivilegedPermission("getCallComposerStatus");
6735
6736 final long identity = Binder.clearCallingIdentity();
6737 try {
6738 Phone phone = getPhone(subId);
6739 if (phone != null) {
6740 Phone defaultPhone = phone.getImsPhone();
6741 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6742 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6743 return imsPhone.getCallComposerStatus();
6744 }
6745 }
6746 } finally {
6747 Binder.restoreCallingIdentity(identity);
6748 }
6749 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6750 }
6751
6752 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006753 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6754 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006755 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006756 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 final long identity = Binder.clearCallingIdentity();
6759 try {
6760 final String iccId = getIccId(subId);
6761 final Phone phone = getPhone(subId);
6762 if (phone == null) {
6763 return false;
6764 }
6765 final String subscriberId = phone.getSubscriberId();
6766
6767 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006768 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006769 + subscriberId + " to " + number);
6770 }
6771
6772 if (TextUtils.isEmpty(iccId)) {
6773 return false;
6774 }
6775
6776 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6777
6778 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6779 if (alphaTag == null) {
6780 editor.remove(alphaTagPrefKey);
6781 } else {
6782 editor.putString(alphaTagPrefKey, alphaTag);
6783 }
6784
6785 // Record both the line number and IMSI for this ICCID, since we need to
6786 // track all merged IMSIs based on line number
6787 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6788 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6789 if (number == null) {
6790 editor.remove(numberPrefKey);
6791 editor.remove(subscriberPrefKey);
6792 } else {
6793 editor.putString(numberPrefKey, number);
6794 editor.putString(subscriberPrefKey, subscriberId);
6795 }
6796
6797 editor.commit();
6798 return true;
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006801 }
Derek Tan7226c842014-07-02 17:42:23 -07006802 }
6803
6804 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006805 public String getLine1NumberForDisplay(int subId, String callingPackage,
6806 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006807 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006809 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006810 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006811 return null;
6812 }
Derek Tan97ebb422014-09-05 16:55:38 -07006813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006814 final long identity = Binder.clearCallingIdentity();
6815 try {
6816 String iccId = getIccId(subId);
6817 if (iccId != null) {
6818 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6819 if (DBG_MERGE) {
6820 log("getLine1NumberForDisplay returning "
6821 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6822 }
6823 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006824 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6826 return null;
6827 } finally {
6828 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006829 }
Derek Tan7226c842014-07-02 17:42:23 -07006830 }
6831
6832 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006833 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6834 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006836 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006837 return null;
6838 }
Derek Tan97ebb422014-09-05 16:55:38 -07006839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 final long identity = Binder.clearCallingIdentity();
6841 try {
6842 String iccId = getIccId(subId);
6843 if (iccId != null) {
6844 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6845 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6846 }
6847 return null;
6848 } finally {
6849 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006850 }
Derek Tan7226c842014-07-02 17:42:23 -07006851 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006852
6853 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006854 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6855 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006856 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6857 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006859 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006860 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006861 return null;
6862 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006863
Jordan Liub49b04b2019-05-06 14:45:15 -07006864 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6865 // the process, where TelephonyManager was instantiated.
6866 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006867 final long identity = Binder.clearCallingIdentity();
6868 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006869 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006870 final TelephonyManager tele = TelephonyManager.from(context);
6871 final SubscriptionManager sub = SubscriptionManager.from(context);
6872
6873 // Figure out what subscribers are currently active
6874 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006875
Jordan Liub49b04b2019-05-06 14:45:15 -07006876 // Only consider subs which match the current subId
6877 // This logic can be simplified. See b/131189269 for progress.
6878 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006879 activeSubscriberIds.add(tele.getSubscriberId(subId));
6880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881
6882 // First pass, find a number override for an active subscriber
6883 String mergeNumber = null;
6884 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6885 for (String key : prefs.keySet()) {
6886 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6887 final String subscriberId = (String) prefs.get(key);
6888 if (activeSubscriberIds.contains(subscriberId)) {
6889 final String iccId = key.substring(
6890 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6891 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6892 mergeNumber = (String) prefs.get(numberKey);
6893 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006894 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 + " for active subscriber " + subscriberId);
6896 }
6897 if (!TextUtils.isEmpty(mergeNumber)) {
6898 break;
6899 }
6900 }
6901 }
6902 }
6903
6904 // Shortcut when no active merged subscribers
6905 if (TextUtils.isEmpty(mergeNumber)) {
6906 return null;
6907 }
6908
6909 // Second pass, find all subscribers under that line override
6910 final ArraySet<String> result = new ArraySet<>();
6911 for (String key : prefs.keySet()) {
6912 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6913 final String number = (String) prefs.get(key);
6914 if (mergeNumber.equals(number)) {
6915 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6916 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6917 final String subscriberId = (String) prefs.get(subscriberKey);
6918 if (!TextUtils.isEmpty(subscriberId)) {
6919 result.add(subscriberId);
6920 }
6921 }
6922 }
6923 }
6924
6925 final String[] resultArray = result.toArray(new String[result.size()]);
6926 Arrays.sort(resultArray);
6927 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006928 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6930 }
6931 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006932 } finally {
6933 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006934 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006935 }
6936
6937 @Override
zoey chen38003472019-12-13 17:16:31 +08006938 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6939 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006940
6941 final long identity = Binder.clearCallingIdentity();
6942 try {
6943 final TelephonyManager telephonyManager = mApp.getSystemService(
6944 TelephonyManager.class);
6945 String subscriberId = telephonyManager.getSubscriberId(subId);
6946 if (subscriberId == null) {
6947 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006948 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006949 + subId);
6950 }
6951 return null;
6952 }
6953
6954 final SubscriptionInfo info = SubscriptionController.getInstance()
6955 .getSubscriptionInfo(subId);
6956 final ParcelUuid groupUuid = info.getGroupUuid();
6957 // If it doesn't belong to any group, return just subscriberId of itself.
6958 if (groupUuid == null) {
6959 return new String[]{subscriberId};
6960 }
6961
6962 // Get all subscriberIds from the group.
6963 final List<String> mergedSubscriberIds = new ArrayList<>();
6964 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006965 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006966 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006967 for (SubscriptionInfo subInfo : groupInfos) {
6968 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6969 if (subscriberId != null) {
6970 mergedSubscriberIds.add(subscriberId);
6971 }
6972 }
6973
6974 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6975 } finally {
6976 Binder.restoreCallingIdentity(identity);
6977
6978 }
6979 }
6980
6981 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006982 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006983 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006984 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006985
6986 final long identity = Binder.clearCallingIdentity();
6987 try {
6988 final Phone phone = getPhone(subId);
6989 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6990 } finally {
6991 Binder.restoreCallingIdentity(identity);
6992 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006993 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006994
6995 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006996 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006997 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6998 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006999 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7000 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001
7002 final long identity = Binder.clearCallingIdentity();
7003 try {
7004 final Phone phone = getPhone(subId);
7005 if (phone == null) {
7006 return false;
7007 }
7008 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7009 cdmaNonRoamingList);
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007012 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007013 }
7014
7015 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007016 @Deprecated
7017 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7018 enforceModifyPermission();
7019
7020 int returnValue = 0;
7021 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007022 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007023 if(result.exception == null) {
7024 if (result.result != null) {
7025 byte[] responseData = (byte[])(result.result);
7026 if(responseData.length > oemResp.length) {
7027 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7028 responseData.length + "bytes. Buffer Size is " +
7029 oemResp.length + "bytes.");
7030 }
7031 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7032 returnValue = responseData.length;
7033 }
7034 } else {
7035 CommandException ex = (CommandException) result.exception;
7036 returnValue = ex.getCommandError().ordinal();
7037 if(returnValue > 0) returnValue *= -1;
7038 }
7039 } catch (RuntimeException e) {
7040 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7041 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7042 if(returnValue > 0) returnValue *= -1;
7043 }
7044
7045 return returnValue;
7046 }
7047
7048 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007049 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007050 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007051 try {
7052 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007053 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007054 mApp, phone.getSubId(), "getRadioAccessFamily");
7055 } catch (SecurityException e) {
7056 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7057 throw e;
7058 }
chen xub97461a2018-10-26 14:17:57 -07007059 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007060 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007061 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007062 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 final long identity = Binder.clearCallingIdentity();
7064 try {
chen xub97461a2018-10-26 14:17:57 -07007065 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007066 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007067 mApp, phone.getSubId(), "getRadioAccessFamily");
7068 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007069 } finally {
7070 Binder.restoreCallingIdentity(identity);
7071 }
chen xub97461a2018-10-26 14:17:57 -07007072 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007073 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007074
7075 @Override
7076 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007077 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007078 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079
7080 final long identity = Binder.clearCallingIdentity();
7081 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007082 ImsManager.getInstance(defaultPhone.getContext(),
7083 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 } finally {
7085 Binder.restoreCallingIdentity(identity);
7086 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007087 }
7088
7089 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007090 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007091 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7093 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007094 return false;
7095 }
Svet Ganovb320e182015-04-16 12:30:10 -07007096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 final long identity = Binder.clearCallingIdentity();
7098 try {
7099 // Check the user preference and the system-level IMS setting. Even if the user has
7100 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7101 // In the long run, we may instead need to check if there exists a connection service
7102 // which can support video calling.
7103 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007104 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105 return imsManager.isVtEnabledByPlatform()
7106 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7107 && imsManager.isVtEnabledByUser();
7108 } finally {
7109 Binder.restoreCallingIdentity(identity);
7110 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007111 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007112
Andrew Leea1239f22015-03-02 17:44:07 -08007113 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007114 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7115 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007117 mApp, subId, callingPackage, callingFeatureId,
7118 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 return false;
7120 }
7121
7122 final long identity = Binder.clearCallingIdentity();
7123 try {
7124 CarrierConfigManager configManager =
7125 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007126 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007127 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7128 } finally {
7129 Binder.restoreCallingIdentity(identity);
7130 }
Andrew Leea1239f22015-03-02 17:44:07 -08007131 }
7132
7133 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007134 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007136 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 return false;
7138 }
7139
7140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 CarrierConfigManager configManager =
7143 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007144 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7146 } finally {
7147 Binder.restoreCallingIdentity(identity);
7148 }
Andrew Leea1239f22015-03-02 17:44:07 -08007149 }
7150
Andrew Lee9431b832015-03-09 18:46:45 -07007151 @Override
7152 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007153 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007154 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007155 }
7156
7157 @Override
7158 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 final long identity = Binder.clearCallingIdentity();
7160 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007161 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
Andrew Lee9431b832015-03-09 18:46:45 -07007165 }
7166
Hall Liuf6668912018-10-31 17:05:23 -07007167 /**
7168 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7169 * support for the feature and device firmware support.
7170 *
7171 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7172 */
7173 @Override
7174 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007176 final Phone phone = getPhone(subscriptionId);
7177 if (phone == null) {
7178 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7179 return false;
7180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007182 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007183 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7184 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007185 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007186 return isCarrierSupported && isDeviceSupported;
7187 } finally {
7188 Binder.restoreCallingIdentity(identity);
7189 }
Hall Liu98187582018-01-22 19:15:32 -08007190 }
7191
Hall Liuf6668912018-10-31 17:05:23 -07007192 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007193 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7194 * RTT setting, will return true if the device and carrier both support RTT.
7195 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007196 */
7197 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198 final long identity = Binder.clearCallingIdentity();
7199 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007200 boolean isRttSupported = isRttSupported(subscriptionId);
7201 boolean isUserRttSettingOn = Settings.Secure.getInt(
7202 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7203 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7204 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7205 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007209 }
7210
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007211 @Deprecated
7212 @Override
7213 public String getDeviceId(String callingPackage) {
7214 return getDeviceIdWithFeature(callingPackage, null);
7215 }
7216
Sanket Padawe7310cc72015-01-14 09:53:20 -08007217 /**
7218 * Returns the unique device ID of phone, for example, the IMEI for
7219 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7220 *
7221 * <p>Requires Permission:
7222 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7223 */
7224 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007225 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007226 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007227 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007228 return null;
7229 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007230 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007231 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007232 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007233 return null;
7234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235
7236 final long identity = Binder.clearCallingIdentity();
7237 try {
7238 return phone.getDeviceId();
7239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007242 }
7243
Ping Sunc67b7c22016-03-02 19:16:45 +08007244 /**
7245 * {@hide}
7246 * Returns the IMS Registration Status on a particular subid
7247 *
7248 * @param subId
7249 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007250 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007251 Phone phone = getPhone(subId);
7252 if (phone != null) {
7253 return phone.isImsRegistered();
7254 } else {
7255 return false;
7256 }
7257 }
7258
Santos Cordon7a1885b2015-02-03 11:15:19 -08007259 @Override
7260 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007267 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007268
Tyler Gunnf70ed162019-04-03 15:28:53 -07007269 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007270 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007271 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007273 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007274 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7275 }
7276 final long identity = Binder.clearCallingIdentity();
7277 try {
7278 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7279 } finally {
7280 Binder.restoreCallingIdentity(identity);
7281 }
7282 }
7283
7284 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007285 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007286 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7287 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007288 final long identity = Binder.clearCallingIdentity();
7289 try {
7290 Phone phone = getPhone(subscriptionId);
7291 if (phone == null) {
7292 return null;
7293 }
7294 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7295 } finally {
7296 Binder.restoreCallingIdentity(identity);
7297 }
7298 }
7299
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007300 /**
7301 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007302 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007303 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007304 final long identity = Binder.clearCallingIdentity();
7305 try {
7306 Phone phone = getPhone(subId);
7307 if (phone != null) {
7308 return phone.isWifiCallingEnabled();
7309 } else {
7310 return false;
7311 }
7312 } finally {
7313 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007314 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007315 }
7316
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007317 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007318 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007319 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007320 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 final long identity = Binder.clearCallingIdentity();
7322 try {
7323 Phone phone = getPhone(subId);
7324 if (phone != null) {
7325 return phone.isVideoEnabled();
7326 } else {
7327 return false;
7328 }
7329 } finally {
7330 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007331 }
7332 }
7333
7334 /**
7335 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7336 * defined in {@link ImsRegistrationImplBase}.
7337 */
7338 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007339 final long identity = Binder.clearCallingIdentity();
7340 try {
7341 Phone phone = getPhone(subId);
7342 if (phone != null) {
7343 return phone.getImsRegistrationTech();
7344 } else {
7345 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7346 }
7347 } finally {
7348 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007349 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007350 }
7351
Stuart Scott8eef64f2015-04-08 15:13:54 -07007352 @Override
7353 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007354 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007355 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7356 return;
7357 }
7358
Svet Ganovcc087f82015-05-12 20:35:54 -07007359 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007360
Svet Ganovcc087f82015-05-12 20:35:54 -07007361 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007362 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7363 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007364 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007365 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007366 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007367 Phone phone = getPhone(subId);
SongFerngWang51ee2b12021-05-27 22:44:54 +08007368 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007369 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7370 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007371 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007372 // There has been issues when Sms raw table somehow stores orphan
7373 // fragments. They lead to garbled message when new fragments come
7374 // in and combined with those stale ones. In case this happens again,
7375 // user can reset all network settings which will clean up this table.
7376 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007377 // Clean up IMS settings as well here.
7378 int slotId = getSlotIndex(subId);
7379 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7380 ImsManager.getInstance(mApp, slotId).factoryReset();
7381 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007382
7383 // Erase modem config if erase modem on network setting is enabled.
7384 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7385 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7386 if (configValue != null && Boolean.parseBoolean(configValue)) {
7387 sendEraseModemConfig(getDefaultPhone());
7388 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007389 } finally {
7390 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007391 }
7392 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007393
SongFerngWang51ee2b12021-05-27 22:44:54 +08007394 @VisibleForTesting
7395 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7396 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7397 return;
7398 }
7399 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7400 RILConstants.PREFERRED_NETWORK_MODE);
7401 SubscriptionManager.setSubscriptionProperty(subId,
7402 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7403 "user=" + defaultNetworkType);
7404 phone.loadAllowedNetworksFromSubscriptionDatabase();
7405 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7406 defaultNetworkType, null);
7407 }
7408
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007409 private void cleanUpSmsRawTable(Context context) {
7410 ContentResolver resolver = context.getContentResolver();
7411 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7412 resolver.delete(uri, null, null);
7413 }
7414
Narayan Kamath1c496c22015-04-16 14:40:19 +01007415 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007416 public String getSimLocaleForSubscriber(int subId) {
7417 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7418 final Phone phone = getPhone(subId);
7419 if (phone == null) {
7420 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007421 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007422 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423 final long identity = Binder.clearCallingIdentity();
7424 try {
chen xu5d3637b2019-01-21 23:31:38 -08007425 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007426 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007427 if (info == null) {
7428 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7429 return null;
7430 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431 // Try and fetch the locale from the carrier properties or from the SIM language
7432 // preferences (EF-PL and EF-LI)...
7433 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007435 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7436 if (localeFromDefaultSim != null) {
7437 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7438 if (DBG) log("Using locale from subId: " + subId + " locale: "
7439 + localeFromDefaultSim);
7440 return localeFromDefaultSim.toLanguageTag();
7441 } else {
7442 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 }
7444 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 // The SIM language preferences only store a language (e.g. fr = French), not an
7447 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7448 // the SIM and carrier preferences does not include a country we add the country
7449 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007450 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007452 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 return mccLocale.toLanguageTag();
7454 }
7455
7456 if (DBG) log("No locale found - returning null");
7457 return null;
7458 } finally {
7459 Binder.restoreCallingIdentity(identity);
7460 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007461 }
7462
7463 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007464 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007465 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007466 }
7467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 /**
7469 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7470 */
7471 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007472 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007473 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007474 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007475
Chenjie Yu1ba97252018-01-11 18:16:20 -08007476 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liue8315982020-10-09 19:00:11 -07007477 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007478
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007479 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007480 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7481 * representing the state of the modem.
7482 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007483 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7484 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007485 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007486 */
7487 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007488 public void requestModemActivityInfo(ResultReceiver result) {
7489 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007490 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491
7492 final long identity = Binder.clearCallingIdentity();
7493 try {
sqian1a1be542020-03-05 11:37:28 -08007494 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 } finally {
7496 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007497 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007498 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007499
Siddharth Rayb8114062018-06-17 15:02:38 -07007500 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7501 // less than total activity duration.
7502 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7503 if (info == null) {
7504 return false;
7505 }
7506 int activityDurationMs =
Hall Liue8315982020-10-09 19:00:11 -07007507 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7508 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7509
Siddharth Rayb8114062018-06-17 15:02:38 -07007510 return (info.isValid()
7511 && (info.getSleepTimeMillis() <= activityDurationMs)
7512 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007513 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007514 && (totalTxTimeMs <= activityDurationMs));
7515 }
7516
Jack Yu85bd38a2015-11-09 11:34:32 -08007517 /**
7518 * {@hide}
7519 * Returns the service state information on specified subscription.
7520 */
7521 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007522 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7523 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007525 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007526 return null;
7527 }
7528
Hall Liuf19c44f2018-11-27 14:38:17 -08007529 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7530 LocationAccessPolicy.checkLocationPermission(mApp,
7531 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7532 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007533 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007534 .setCallingPid(Binder.getCallingPid())
7535 .setCallingUid(Binder.getCallingUid())
7536 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007537 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007538 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007539 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7540 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007541 .build());
7542
7543 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7544 LocationAccessPolicy.checkLocationPermission(mApp,
7545 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7546 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007547 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007548 .setCallingPid(Binder.getCallingPid())
7549 .setCallingUid(Binder.getCallingUid())
7550 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007551 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007552 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007553 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7554 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007555 .build());
7556 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7557 boolean hasFinePermission =
7558 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7559 boolean hasCoarsePermission =
7560 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 final long identity = Binder.clearCallingIdentity();
7563 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007564 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7565 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7566 Rlog.d(LOG_TAG,
7567 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7568 return null;
7569 }
7570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007571 final Phone phone = getPhone(subId);
7572 if (phone == null) {
7573 return null;
7574 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007575
Hall Liuf19c44f2018-11-27 14:38:17 -08007576 ServiceState ss = phone.getServiceState();
7577
7578 // Scrub out the location info in ServiceState depending on what level of access
7579 // the caller has.
7580 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007581 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7582 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007583 } finally {
7584 Binder.restoreCallingIdentity(identity);
7585 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007586 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007587
7588 /**
7589 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7590 *
7591 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7592 * voicemail ringtone.
7593 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7594 * PhoneAccount.
7595 */
7596 @Override
7597 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007598 final long identity = Binder.clearCallingIdentity();
7599 try {
7600 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7601 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007602 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007603 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007604
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7606 } finally {
7607 Binder.restoreCallingIdentity(identity);
7608 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007609 }
7610
7611 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007612 * Sets the per-account voicemail ringtone.
7613 *
7614 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7615 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7616 *
7617 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7618 * voicemail ringtone.
7619 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7620 * PhoneAccount.
7621 */
7622 @Override
7623 public void setVoicemailRingtoneUri(String callingPackage,
7624 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007625 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007626 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007627 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7628 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7630 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7631 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007633
7634 final long identity = Binder.clearCallingIdentity();
7635 try {
7636 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7637 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007638 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007639 }
7640 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7641 } finally {
7642 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007643 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007644 }
7645
7646 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007647 * Returns whether vibration is set for voicemail notification in Phone settings.
7648 *
7649 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7650 * voicemail vibration setting.
7651 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7652 */
7653 @Override
7654 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007655 final long identity = Binder.clearCallingIdentity();
7656 try {
7657 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7658 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007659 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007661
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7663 } finally {
7664 Binder.restoreCallingIdentity(identity);
7665 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007666 }
7667
Youhan Wange64578a2016-05-02 15:32:42 -07007668 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007669 * Sets the per-account voicemail vibration.
7670 *
7671 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7672 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7673 *
7674 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7675 * voicemail vibration setting.
7676 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7677 * specific PhoneAccount.
7678 */
7679 @Override
7680 public void setVoicemailVibrationEnabled(String callingPackage,
7681 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007682 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007684 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7685 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7687 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7688 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007689 }
7690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 final long identity = Binder.clearCallingIdentity();
7692 try {
7693 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7694 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007695 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696 }
7697 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7698 } finally {
7699 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007700 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007701 }
7702
7703 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007704 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7705 *
7706 * @throws SecurityException if the caller does not have the required permission
7707 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007708 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007709 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007710 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007711 }
7712
7713 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007714 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7715 * permission.
7716 *
7717 * @throws SecurityException if the caller does not have the required permission
7718 */
7719 private void enforceSendSmsPermission() {
7720 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7721 }
7722
7723 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007724 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007725 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007726 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007727 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007728 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729 final long identity = Binder.clearCallingIdentity();
7730 try {
7731 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007732 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007733 if (componentName == null) {
7734 throw new SecurityException(
7735 "Caller not current active visual voicemail package[null]");
7736 }
7737 String vvmPackage = componentName.getPackageName();
7738 if (!callingPackage.equals(vvmPackage)) {
7739 throw new SecurityException("Caller not current active visual voicemail package["
7740 + vvmPackage + "]");
7741 }
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007744 }
7745 }
7746
7747 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007748 * Return the application ID for the app type.
7749 *
7750 * @param subId the subscription ID that this request applies to.
7751 * @param appType the uicc app type.
7752 * @return Application ID for specificied app type, or null if no uicc.
7753 */
7754 @Override
7755 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007756 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007757 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758
7759 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007760 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 if (phone == null) {
7762 return null;
7763 }
7764 String aid = null;
7765 try {
7766 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7767 .getApplicationByType(appType).getAid();
7768 } catch (Exception e) {
7769 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7770 }
7771 return aid;
7772 } finally {
7773 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007774 }
Youhan Wange64578a2016-05-02 15:32:42 -07007775 }
7776
Youhan Wang4001d252016-05-11 10:29:41 -07007777 /**
7778 * Return the Electronic Serial Number.
7779 *
7780 * @param subId the subscription ID that this request applies to.
7781 * @return ESN or null if error.
7782 */
7783 @Override
7784 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007785 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007786 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007787
7788 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007789 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790 if (phone == null) {
7791 return null;
7792 }
7793 String esn = null;
7794 try {
7795 esn = phone.getEsn();
7796 } catch (Exception e) {
7797 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7798 }
7799 return esn;
7800 } finally {
7801 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007802 }
Youhan Wang4001d252016-05-11 10:29:41 -07007803 }
7804
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007805 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007806 * Return the Preferred Roaming List Version.
7807 *
7808 * @param subId the subscription ID that this request applies to.
7809 * @return PRLVersion or null if error.
7810 */
7811 @Override
7812 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007813 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007814 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815
7816 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007817 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 if (phone == null) {
7819 return null;
7820 }
7821 String cdmaPrlVersion = null;
7822 try {
7823 cdmaPrlVersion = phone.getCdmaPrlVersion();
7824 } catch (Exception e) {
7825 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7826 }
7827 return cdmaPrlVersion;
7828 } finally {
7829 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007830 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007831 }
7832
7833 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007834 * Get snapshot of Telephony histograms
7835 * @return List of Telephony histograms
7836 * @hide
7837 */
7838 @Override
7839 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7841 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007842
7843 final long identity = Binder.clearCallingIdentity();
7844 try {
7845 return RIL.getTelephonyRILTimingHistograms();
7846 } finally {
7847 Binder.restoreCallingIdentity(identity);
7848 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007849 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007850
7851 /**
7852 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007853 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7854 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007855 * Require system privileges. In the future we may add this to carrier APIs.
7856 *
Michele Berionne482f8202018-11-27 18:57:59 -08007857 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007858 */
7859 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007860 @TelephonyManager.SetCarrierRestrictionResult
7861 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007862 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007863 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007864
Michele Berionne482f8202018-11-27 18:57:59 -08007865 if (carrierRestrictionRules == null) {
7866 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007867 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007869 final long identity = Binder.clearCallingIdentity();
7870 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007871 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007872 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 } finally {
7874 Binder.restoreCallingIdentity(identity);
7875 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007876 }
7877
7878 /**
7879 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007880 * Get the allowed carrier list and the excluded carrier list, including the priority between
7881 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007882 * Require system privileges. In the future we may add this to carrier APIs.
7883 *
Michele Berionne482f8202018-11-27 18:57:59 -08007884 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007885 */
7886 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007887 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007888 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007890
7891 final long identity = Binder.clearCallingIdentity();
7892 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007893 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7894 if (response instanceof CarrierRestrictionRules) {
7895 return (CarrierRestrictionRules) response;
7896 }
7897 // Response is an Exception of some kind,
7898 // which is signalled to the user as a NULL retval
7899 return null;
7900 } catch (Exception e) {
7901 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7902 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007903 } finally {
7904 Binder.restoreCallingIdentity(identity);
7905 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007906 }
7907
fionaxu59545b42016-05-25 15:53:37 -07007908 /**
fionaxu59545b42016-05-25 15:53:37 -07007909 * Action set from carrier signalling broadcast receivers to enable/disable radio
7910 * @param subId the subscription ID that this action applies to.
7911 * @param enabled control enable or disable radio.
7912 * {@hide}
7913 */
7914 @Override
7915 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7916 enforceModifyPermission();
7917 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007918
7919 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007920 if (phone == null) {
7921 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7922 return;
7923 }
7924 try {
7925 phone.carrierActionSetRadioEnabled(enabled);
7926 } catch (Exception e) {
7927 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007928 } finally {
7929 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007930 }
7931 }
7932
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007933 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007934 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7935 * network status based on which carrier apps could apply actions accordingly,
7936 * enable/disable default url handler for example.
7937 *
7938 * @param subId the subscription ID that this action applies to.
7939 * @param report control start/stop reporting the default network status.
7940 * {@hide}
7941 */
7942 @Override
7943 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7944 enforceModifyPermission();
7945 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007946
7947 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007948 if (phone == null) {
7949 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7950 return;
7951 }
7952 try {
7953 phone.carrierActionReportDefaultNetworkStatus(report);
7954 } catch (Exception e) {
7955 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956 } finally {
7957 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007958 }
7959 }
7960
7961 /**
fionaxud9622282017-07-17 17:51:30 -07007962 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7963 * @param subId the subscription ID that this action applies to.
7964 * {@hide}
7965 */
7966 @Override
7967 public void carrierActionResetAll(int subId) {
7968 enforceModifyPermission();
7969 final Phone phone = getPhone(subId);
7970 if (phone == null) {
7971 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7972 return;
7973 }
7974 try {
7975 phone.carrierActionResetAll();
7976 } catch (Exception e) {
7977 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7978 }
7979 }
7980
7981 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007982 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7983 * bug report is being generated.
7984 */
7985 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007986 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007987 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7988 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007989 writer.println("Permission Denial: can't dump Phone from pid="
7990 + Binder.getCallingPid()
7991 + ", uid=" + Binder.getCallingUid()
7992 + "without permission "
7993 + android.Manifest.permission.DUMP);
7994 return;
7995 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007996 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007997 }
Jack Yueb89b242016-06-22 13:27:47 -07007998
Brad Ebingerdac2f002018-04-03 15:17:52 -07007999 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008000 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8001 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8002 @NonNull String[] args) {
8003 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8004 this, in.getFileDescriptor(), out.getFileDescriptor(),
8005 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008006 }
8007
Jack Yueb89b242016-06-22 13:27:47 -07008008 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008009 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07008010 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008011 * @param reason the reason the data enable change is taking place
8012 * @param enabled True if enabling the data, otherwise disabling.
8013 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008014 */
8015 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07008016 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008017 boolean enabled) {
8018 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8019 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8020 try {
8021 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07008022 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008023 } catch (SecurityException se) {
8024 enforceModifyPermission();
8025 }
8026 } else {
8027 enforceModifyPermission();
8028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008029
8030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 Phone phone = getPhone(subId);
8033 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008034 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8035 phone.carrierActionSetMeteredApnsEnabled(enabled);
8036 } else {
8037 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039 }
8040 } finally {
8041 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008042 }
8043 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008044
8045 /**
8046 * Get Client request stats
8047 * @return List of Client Request Stats
8048 * @hide
8049 */
8050 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008051 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8052 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008054 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008055 return null;
8056 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008057 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008059 final long identity = Binder.clearCallingIdentity();
8060 try {
8061 if (phone != null) {
8062 return phone.getClientRequestStats();
8063 }
8064
8065 return null;
8066 } finally {
8067 Binder.restoreCallingIdentity(identity);
8068 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008069 }
8070
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008071 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008072 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008073 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008074 }
Jack Yueb4124c2017-02-16 15:32:43 -08008075
8076 /**
Grace Chen70990072017-03-24 17:21:30 -07008077 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008078 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008079 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008080 * @param state State of SIM (power down, power up, pass through)
8081 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8082 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8083 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008084 *
8085 **/
8086 @Override
Grace Chen70990072017-03-24 17:21:30 -07008087 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008088 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008089 Phone phone = PhoneFactory.getPhone(slotIndex);
8090
vagdeviaf9a5b92018-08-15 16:01:53 -07008091 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093 final long identity = Binder.clearCallingIdentity();
8094 try {
8095 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008096 phone.setSimPowerState(state, null, workSource);
8097 }
8098 } finally {
8099 Binder.restoreCallingIdentity(identity);
8100 }
8101 }
8102
8103 /**
8104 * Set SIM card power state.
8105 *
8106 * @param slotIndex SIM slot id.
8107 * @param state State of SIM (power down, power up, pass through)
8108 * @param callback callback to trigger after success or failure
8109 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8110 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8111 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8112 *
8113 **/
8114 @Override
8115 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8116 IIntegerConsumer callback) {
8117 enforceModifyPermission();
8118 Phone phone = PhoneFactory.getPhone(slotIndex);
8119
8120 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8121
8122 final long identity = Binder.clearCallingIdentity();
8123 try {
8124 if (phone != null) {
8125 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8126 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 }
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008130 }
8131 }
Shuo Qiandd210312017-04-12 22:11:33 +00008132
Tyler Gunn65d45c22017-06-05 11:22:26 -07008133 private boolean isUssdApiAllowed(int subId) {
8134 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008135 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008136 if (configManager == null) {
8137 return false;
8138 }
8139 PersistableBundle pb = configManager.getConfigForSubId(subId);
8140 if (pb == null) {
8141 return false;
8142 }
8143 return pb.getBoolean(
8144 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8145 }
8146
Shuo Qiandd210312017-04-12 22:11:33 +00008147 /**
8148 * Check if phone is in emergency callback mode
8149 * @return true if phone is in emergency callback mode
8150 * @param subId sub id
8151 */
goneil9c5f4872017-12-05 14:07:56 -08008152 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008153 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008154 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008155 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008156
8157 final long identity = Binder.clearCallingIdentity();
8158 try {
8159 if (phone != null) {
8160 return phone.isInEcm();
8161 } else {
8162 return false;
8163 }
8164 } finally {
8165 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008166 }
8167 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008168
8169 /**
8170 * Get the current signal strength information for the given subscription.
8171 * Because this information is not updated when the device is in a low power state
8172 * it should not be relied-upon to be current.
8173 * @param subId Subscription index
8174 * @return the most recent cached signal strength info from the modem
8175 */
8176 @Override
8177 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178 final long identity = Binder.clearCallingIdentity();
8179 try {
8180 Phone p = getPhone(subId);
8181 if (p == null) {
8182 return null;
8183 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008185 return p.getSignalStrength();
8186 } finally {
8187 Binder.restoreCallingIdentity(identity);
8188 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008189 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008190
Pengquan Meng77b7f132018-08-22 14:49:57 -07008191 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008192 * Get the current modem radio state for the given slot.
8193 * @param slotIndex slot index.
8194 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008195 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008196 * @return the current radio power state from the modem
8197 */
8198 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008199 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008200 Phone phone = PhoneFactory.getPhone(slotIndex);
8201 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8203 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008204 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8205 }
8206
8207 final long identity = Binder.clearCallingIdentity();
8208 try {
8209 return phone.getRadioPowerState();
8210 } finally {
8211 Binder.restoreCallingIdentity(identity);
8212 }
8213 }
8214 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8215 }
8216
8217 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008218 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8219 *
8220 * <p>Requires one of the following permissions:
8221 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8222 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8223 * privileges.
8224 *
8225 * @param subId subscription id
8226 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8227 * {@code false}.
8228 */
8229 @Override
8230 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008231 try {
8232 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8233 null);
8234 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008235 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008236 mApp, subId, "isDataRoamingEnabled");
8237 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008238
Pengquan Menga1bb6272018-09-06 09:59:22 -07008239 boolean isEnabled = false;
8240 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008241 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008242 Phone phone = getPhone(subId);
8243 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008244 } finally {
8245 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008246 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008247 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008248 }
8249
8250
8251 /**
8252 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8253 *
8254 * <p> Requires permission:
8255 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8256 * privileges.
8257 *
8258 * @param subId subscription id
8259 * @param isEnabled {@code true} means enable, {@code false} means disable.
8260 */
8261 @Override
8262 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8264 mApp, subId, "setDataRoamingEnabled");
8265
Pengquan Menga1bb6272018-09-06 09:59:22 -07008266 final long identity = Binder.clearCallingIdentity();
8267 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008268 Phone phone = getPhone(subId);
8269 if (phone != null) {
8270 phone.setDataRoamingEnabled(isEnabled);
8271 }
8272 } finally {
8273 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008274 }
8275 }
8276
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008277 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008278 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008279 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008280 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008281 mApp, subId, "isManualNetworkSelectionAllowed");
8282
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008283 boolean isAllowed = true;
8284 final long identity = Binder.clearCallingIdentity();
8285 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008286 Phone phone = getPhone(subId);
8287 if (phone != null) {
8288 isAllowed = phone.isCspPlmnEnabled();
8289 }
8290 } finally {
8291 Binder.restoreCallingIdentity(identity);
8292 }
8293 return isAllowed;
8294 }
8295
8296 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008297 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008298 // Verify that tha callingPackage belongs to the calling UID
8299 mApp.getSystemService(AppOpsManager.class)
8300 .checkPackage(Binder.getCallingUid(), callingPackage);
8301
Jordan Liu1e142fc2019-04-22 15:10:43 -07008302 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008303 try {
8304 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008305 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008306 } catch (SecurityException e) {
8307 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8308 // has carrier privileges on an active UICC
8309 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8310 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008311 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008312 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008313 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008314
8315 final long identity = Binder.clearCallingIdentity();
8316 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008317 UiccController uiccController = UiccController.getInstance();
8318 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008319 if (hasReadPermission) {
8320 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008321 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008322
8323 // Remove private info if the caller doesn't have access
8324 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8325 for (UiccCardInfo cardInfo : cardInfos) {
8326 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8327 // is available
8328 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8329 if (card == null || card.getUiccProfile() == null) {
8330 // assume no access if the card or profile is unavailable
8331 filteredInfos.add(cardInfo.getUnprivileged());
8332 continue;
8333 }
8334 UiccProfile profile = card.getUiccProfile();
8335 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8336 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8337 filteredInfos.add(cardInfo);
8338 } else {
8339 filteredInfos.add(cardInfo.getUnprivileged());
8340 }
8341 }
8342 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008343 } finally {
8344 Binder.restoreCallingIdentity(identity);
8345 }
8346 }
8347
8348 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008349 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008350 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008351
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008352 final long identity = Binder.clearCallingIdentity();
8353 try {
8354 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8355 if (slots == null) {
8356 Rlog.i(LOG_TAG, "slots is null.");
8357 return null;
8358 }
8359
8360 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8361 for (int i = 0; i < slots.length; i++) {
8362 UiccSlot slot = slots[i];
8363 if (slot == null) {
8364 continue;
8365 }
8366
Jordan Liu7be7e652019-05-06 18:55:02 +00008367 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368 UiccCard card = slot.getUiccCard();
8369 if (card != null) {
8370 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008371 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008372 cardId = slot.getEid();
8373 if (TextUtils.isEmpty(cardId)) {
8374 cardId = slot.getIccId();
8375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376 }
8377
Jordan Liu857451f2019-05-09 16:35:35 -07008378 if (cardId != null) {
8379 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8380 // if cardId is an EID, it's all digits so this is fine
8381 cardId = IccUtils.stripTrailingFs(cardId);
8382 }
8383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008384 int cardState = 0;
8385 switch (slot.getCardState()) {
8386 case CARDSTATE_ABSENT:
8387 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8388 break;
8389 case CARDSTATE_PRESENT:
8390 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8391 break;
8392 case CARDSTATE_ERROR:
8393 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8394 break;
8395 case CARDSTATE_RESTRICTED:
8396 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8397 break;
8398 default:
8399 break;
8400
8401 }
8402
8403 infos[i] = new UiccSlotInfo(
8404 slot.isActive(),
8405 slot.isEuicc(),
8406 cardId,
8407 cardState,
8408 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008409 slot.isExtendedApduSupported(),
8410 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008411 }
8412 return infos;
8413 } finally {
8414 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008415 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008416 }
8417
8418 @Override
8419 public boolean switchSlots(int[] physicalSlots) {
8420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008421
8422 final long identity = Binder.clearCallingIdentity();
8423 try {
8424 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8425 } finally {
8426 Binder.restoreCallingIdentity(identity);
8427 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008428 }
Jack Yu4c988042018-02-27 15:30:01 -08008429
8430 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008431 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008432 final long identity = Binder.clearCallingIdentity();
8433 try {
8434 return UiccController.getInstance().getCardIdForDefaultEuicc();
8435 } finally {
8436 Binder.restoreCallingIdentity(identity);
8437 }
8438 }
8439
Pengquan Meng85728fb2018-03-12 16:31:21 -07008440 /**
goneil47ffb6e2018-04-06 15:40:58 -07008441 * A test API to reload the UICC profile.
8442 *
8443 * <p>Requires that the calling app has permission
8444 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8445 * @hide
8446 */
8447 @Override
8448 public void refreshUiccProfile(int subId) {
8449 enforceModifyPermission();
8450
8451 final long identity = Binder.clearCallingIdentity();
8452 try {
8453 Phone phone = getPhone(subId);
8454 if (phone == null) {
8455 return;
8456 }
8457 UiccCard uiccCard = phone.getUiccCard();
8458 if (uiccCard == null) {
8459 return;
8460 }
8461 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8462 if (uiccProfile == null) {
8463 return;
8464 }
8465 uiccProfile.refresh();
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
8469 }
8470
8471 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008472 * Returns false if the mobile data is disabled by default, otherwise return true.
8473 */
8474 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008475 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008476 }
8477
8478 /**
8479 * Returns true if the data roaming is enabled by default, i.e the system property
8480 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8481 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8482 */
8483 private boolean getDefaultDataRoamingEnabled(int subId) {
8484 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008485 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008486 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008487 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8488 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8489 return isDataRoamingEnabled;
8490 }
8491
8492 /**
8493 * Returns the default network type for the given {@code subId}, if the default network type is
8494 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8495 */
8496 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008497 List<Integer> list = TelephonyProperties.default_network();
8498 int phoneId = mSubscriptionController.getPhoneId(subId);
8499 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8500 return list.get(phoneId);
8501 }
8502 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008503 }
fionaxua13278b2018-03-21 00:08:13 -07008504
8505 @Override
8506 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008507 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008508 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008509
8510 final long identity = Binder.clearCallingIdentity();
8511 try {
8512 final Phone phone = getPhone(subId);
8513 if (phone == null) {
8514 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8515 return;
8516 }
chen xueaba88a2019-03-15 13:15:10 -07008517 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8518 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008519 if (carrierPrivilegeRules == null) {
8520 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8521 } else {
8522 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008524 } finally {
8525 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008526 }
fionaxua13278b2018-03-21 00:08:13 -07008527 }
8528
8529 @Override
8530 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008531 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008532
8533 final long identity = Binder.clearCallingIdentity();
8534 try {
8535 final Phone phone = getPhone(subId);
8536 if (phone == null) {
8537 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8538 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8539 }
8540 return phone.getCarrierIdListVersion();
8541 } finally {
8542 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008543 }
fionaxua13278b2018-03-21 00:08:13 -07008544 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008545
8546 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008547 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8548 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008549 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008550 mApp, subId, callingPackage, callingFeatureId,
8551 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008552 return -1;
8553 }
8554
8555 final long identity = Binder.clearCallingIdentity();
8556 try {
8557 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8558 } finally {
8559 Binder.restoreCallingIdentity(identity);
8560 }
8561 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008562
8563 @Override
8564 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008565 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008566 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008567 mApp, subId, "getCdmaRoamingMode");
8568
8569 final long identity = Binder.clearCallingIdentity();
8570 try {
8571 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8572 } finally {
8573 Binder.restoreCallingIdentity(identity);
8574 }
8575 }
8576
8577 @Override
8578 public boolean setCdmaRoamingMode(int subId, int mode) {
8579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8580 mApp, subId, "setCdmaRoamingMode");
8581
8582 final long identity = Binder.clearCallingIdentity();
8583 try {
8584 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8585 } finally {
8586 Binder.restoreCallingIdentity(identity);
8587 }
8588 }
8589
8590 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008591 public int getCdmaSubscriptionMode(int subId) {
8592 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008593 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008594 mApp, subId, "getCdmaSubscriptionMode");
8595
8596 final long identity = Binder.clearCallingIdentity();
8597 try {
8598 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8599 } finally {
8600 Binder.restoreCallingIdentity(identity);
8601 }
8602 }
8603
8604 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008605 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8607 mApp, subId, "setCdmaSubscriptionMode");
8608
8609 final long identity = Binder.clearCallingIdentity();
8610 try {
8611 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8612 } finally {
8613 Binder.restoreCallingIdentity(identity);
8614 }
8615 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008616
sqianc5eccab2018-10-19 18:46:41 -07008617 @Override
sqian8c685422019-02-22 15:55:18 -08008618 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008619 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008621 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8622 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008623 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8624 }
8625 final long identity = Binder.clearCallingIdentity();
8626 try {
sqian854d44b2018-12-12 16:48:18 -08008627 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8628 for (Phone phone: PhoneFactory.getPhones()) {
8629 if (phone.getEmergencyNumberTracker() != null
8630 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8631 emergencyNumberListInternal.put(
8632 phone.getSubId(),
8633 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8634 }
sqian11b7a0e2018-12-05 18:48:28 -08008635 }
sqian854d44b2018-12-12 16:48:18 -08008636 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008637 } finally {
8638 Binder.restoreCallingIdentity(identity);
8639 }
sqianc5eccab2018-10-19 18:46:41 -07008640 }
8641
8642 @Override
sqian8c685422019-02-22 15:55:18 -08008643 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008644 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008645 if (!exactMatch) {
8646 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008647 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008648 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008649 }
8650 final long identity = Binder.clearCallingIdentity();
8651 try {
sqian854d44b2018-12-12 16:48:18 -08008652 for (Phone phone: PhoneFactory.getPhones()) {
8653 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008654 && phone.getEmergencyNumberTracker()
8655 .isEmergencyNumber(number, exactMatch)) {
8656 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008657 }
sqian11b7a0e2018-12-05 18:48:28 -08008658 }
8659 return false;
8660 } finally {
8661 Binder.restoreCallingIdentity(identity);
8662 }
8663 }
8664
sqianf4ca7ed2019-01-15 18:32:07 -08008665 /**
Shuo Qian479dd9e2021-02-22 18:32:21 -08008666 * Start emergency callback mode for GsmCdmaPhone for testing.
8667 */
8668 @Override
8669 public void startEmergencyCallbackMode() {
8670 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8671 "startEmergencyCallbackMode");
8672 enforceModifyPermission();
8673 final long identity = Binder.clearCallingIdentity();
8674 try {
8675 for (Phone phone : PhoneFactory.getPhones()) {
8676 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8677 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8678 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8679 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8680 gsmCdmaPhone.obtainMessage(
8681 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8682 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8683 }
8684 }
8685 } finally {
8686 Binder.restoreCallingIdentity(identity);
8687 }
8688 }
8689
8690 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008691 * Update emergency number list for test mode.
8692 */
8693 @Override
8694 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8695 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8696 "updateEmergencyNumberListTestMode");
8697
8698 final long identity = Binder.clearCallingIdentity();
8699 try {
8700 for (Phone phone: PhoneFactory.getPhones()) {
8701 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8702 if (tracker != null) {
8703 tracker.executeEmergencyNumberTestModeCommand(action, num);
8704 }
8705 }
8706 } finally {
8707 Binder.restoreCallingIdentity(identity);
8708 }
8709 }
8710
8711 /**
8712 * Get the full emergency number list for test mode.
8713 */
8714 @Override
8715 public List<String> getEmergencyNumberListTestMode() {
8716 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8717 "getEmergencyNumberListTestMode");
8718
8719 final long identity = Binder.clearCallingIdentity();
8720 try {
8721 Set<String> emergencyNumbers = new HashSet<>();
8722 for (Phone phone: PhoneFactory.getPhones()) {
8723 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8724 if (tracker != null) {
8725 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8726 emergencyNumbers.add(num.getNumber());
8727 }
8728 }
8729 }
8730 return new ArrayList<>(emergencyNumbers);
8731 } finally {
8732 Binder.restoreCallingIdentity(identity);
8733 }
8734 }
8735
chen xud6b45bd2018-10-30 22:27:10 -07008736 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008737 public int getEmergencyNumberDbVersion(int subId) {
8738 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8739
8740 final long identity = Binder.clearCallingIdentity();
8741 try {
8742 final Phone phone = getPhone(subId);
8743 if (phone == null) {
8744 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8745 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8746 }
8747 return phone.getEmergencyNumberDbVersion();
8748 } finally {
8749 Binder.restoreCallingIdentity(identity);
8750 }
8751 }
8752
8753 @Override
8754 public void notifyOtaEmergencyNumberDbInstalled() {
8755 enforceModifyPermission();
8756
8757 final long identity = Binder.clearCallingIdentity();
8758 try {
8759 for (Phone phone: PhoneFactory.getPhones()) {
8760 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8761 if (tracker != null) {
8762 tracker.updateOtaEmergencyNumberDatabase();
8763 }
8764 }
8765 } finally {
8766 Binder.restoreCallingIdentity(identity);
8767 }
8768 }
8769
8770 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008771 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008772 enforceActiveEmergencySessionPermission();
8773
8774 final long identity = Binder.clearCallingIdentity();
8775 try {
8776 for (Phone phone: PhoneFactory.getPhones()) {
8777 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8778 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008779 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8780 }
8781 }
8782 } finally {
8783 Binder.restoreCallingIdentity(identity);
8784 }
8785 }
8786
8787 @Override
8788 public void resetOtaEmergencyNumberDbFilePath() {
8789 enforceActiveEmergencySessionPermission();
8790
8791 final long identity = Binder.clearCallingIdentity();
8792 try {
8793 for (Phone phone: PhoneFactory.getPhones()) {
8794 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8795 if (tracker != null) {
8796 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008797 }
8798 }
8799 } finally {
8800 Binder.restoreCallingIdentity(identity);
8801 }
8802 }
8803
8804 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008805 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8806 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8807 Phone phone = getPhone(subId);
8808 if (phone == null) {
8809 return null;
8810 }
8811 final long identity = Binder.clearCallingIdentity();
8812 try {
8813 UiccProfile profile = UiccController.getInstance()
8814 .getUiccProfileForPhone(phone.getPhoneId());
8815 if (profile != null) {
8816 return profile.getCertsFromCarrierPrivilegeAccessRules();
8817 }
8818 } finally {
8819 Binder.restoreCallingIdentity(identity);
8820 }
8821 return null;
8822 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008823
8824 /**
8825 * Enable or disable a modem stack.
8826 */
8827 @Override
8828 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8829 enforceModifyPermission();
8830
8831 final long identity = Binder.clearCallingIdentity();
8832 try {
8833 Phone phone = PhoneFactory.getPhone(slotIndex);
8834 if (phone == null) {
8835 return false;
8836 } else {
8837 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8838 }
8839 } finally {
8840 Binder.restoreCallingIdentity(identity);
8841 }
8842 }
Michelecea4cf22018-12-21 15:00:11 -08008843
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008844 /**
8845 * Whether a modem stack is enabled or not.
8846 */
8847 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008848 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8849 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008850 Phone phone = PhoneFactory.getPhone(slotIndex);
8851 if (phone == null) return false;
8852
8853 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008854 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8855 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008856 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8857 }
8858
8859 final long identity = Binder.clearCallingIdentity();
8860 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008861 try {
8862 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8863 } catch (NoSuchElementException ex) {
8864 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8865 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008866 } finally {
8867 Binder.restoreCallingIdentity(identity);
8868 }
8869 }
8870
Michelecea4cf22018-12-21 15:00:11 -08008871 @Override
Michele0ea7d782019-03-19 14:58:42 -07008872 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008873 enforceModifyPermission();
8874
8875 final long identity = Binder.clearCallingIdentity();
8876 try {
8877 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008878 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008879 .commit();
8880 } finally {
8881 Binder.restoreCallingIdentity(identity);
8882 }
8883 }
8884
8885 @Override
Michele0ea7d782019-03-19 14:58:42 -07008886 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008887 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008888 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008889 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8890 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008891 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008892 }
Michelecea4cf22018-12-21 15:00:11 -08008893
8894 final long identity = Binder.clearCallingIdentity();
8895 try {
Michele0ea7d782019-03-19 14:58:42 -07008896 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008897 } finally {
8898 Binder.restoreCallingIdentity(identity);
8899 }
8900 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008901
Michele0ea7d782019-03-19 14:58:42 -07008902 @TelephonyManager.IsMultiSimSupportedResult
8903 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008904 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8905 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8906 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008907 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8908 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008909 }
8910 // Check if the hardware supports multisim functionality. If usage of multisim is not
8911 // supported by the modem, indicate that it is restricted.
8912 PhoneCapability staticCapability =
8913 mPhoneConfigurationManager.getStaticPhoneCapability();
8914 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008915 loge("isMultiSimSupportedInternal: no static configuration available");
8916 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008917 }
SongFerngWang2c4309d2021-01-17 21:51:44 +08008918 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008919 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8920 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008921 }
8922 // Check if support of multiple SIMs is restricted by carrier
8923 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008924 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008925 }
8926
Michele0ea7d782019-03-19 14:58:42 -07008927 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008928 }
8929
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008930 /**
8931 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008932 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8933 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8934 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008935 * @param numOfSims number of active sims we want to switch to
8936 */
8937 @Override
8938 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008939 if (numOfSims == 1) {
8940 enforceModifyPermission();
8941 } else {
8942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8943 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8944 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008945 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008946
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008947 try {
Michele30b57b22019-03-01 12:01:14 -08008948 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008949 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008950 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8951 return;
8952 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008953 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8954 } finally {
8955 Binder.restoreCallingIdentity(identity);
8956 }
8957 }
8958
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008959 @Override
8960 public boolean isApplicationOnUicc(int subId, int appType) {
8961 enforceReadPrivilegedPermission("isApplicationOnUicc");
8962 Phone phone = getPhone(subId);
8963 if (phone == null) {
8964 return false;
8965 }
8966 final long identity = Binder.clearCallingIdentity();
8967 try {
8968 UiccCard uiccCard = phone.getUiccCard();
8969 if (uiccCard == null) {
8970 return false;
8971 }
8972 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8973 if (uiccProfile == null) {
8974 return false;
8975 }
8976 if (TelephonyManager.APPTYPE_SIM <= appType
8977 && appType <= TelephonyManager.APPTYPE_ISIM) {
8978 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8979 }
8980 return false;
8981 } finally {
8982 Binder.restoreCallingIdentity(identity);
8983 }
8984 }
8985
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008986 /**
chen xub4baa772019-04-03 10:23:41 -07008987 * Get whether making changes to modem configurations will trigger reboot.
8988 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008989 */
8990 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008991 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8992 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008993 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008994 mApp, subId, callingPackage, callingFeatureId,
8995 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008996 return false;
8997 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008998 final long identity = Binder.clearCallingIdentity();
8999 try {
9000 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9001 } finally {
9002 Binder.restoreCallingIdentity(identity);
9003 }
9004 }
9005
Nathan Harold29f5f052019-02-15 13:41:57 -08009006 private void updateModemStateMetrics() {
9007 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9008 // TODO: check the state for each modem if the api is ready.
9009 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9010 }
9011
Pengquan Meng3889a572019-01-23 11:16:29 -08009012 @Override
9013 public int[] getSlotsMapping() {
9014 enforceReadPrivilegedPermission("getSlotsMapping");
9015
9016 final long identity = Binder.clearCallingIdentity();
9017 try {
9018 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9019 // All logical slots should have a mapping to a physical slot.
9020 int[] logicalSlotsMapping = new int[phoneCount];
9021 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9022 for (int i = 0; i < slotInfos.length; i++) {
9023 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9024 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9025 }
9026 }
9027 return logicalSlotsMapping;
9028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
9031 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009032
9033 /**
9034 * Get the IRadio HAL Version
9035 */
9036 @Override
9037 public int getRadioHalVersion() {
9038 Phone phone = getDefaultPhone();
9039 if (phone == null) return -1;
9040 HalVersion hv = phone.getHalVersion();
9041 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9042 return hv.major * 100 + hv.minor;
9043 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009044
9045 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08009046 * Get the current calling package name.
9047 * @return the current calling package name
9048 */
9049 @Override
9050 public String getCurrentPackageName() {
9051 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9052 }
9053
9054 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009055 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9056 * corresponding network requests on a subId.
9057 *
9058 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009059 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009060 * 2) APN is un-metered for this subscription, or
9061 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07009062 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009063 *
9064 * @return whether data is allowed for a apn type.
9065 *
9066 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009067 */
9068 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009069 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009070 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9071 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009072
9073 // Now that all security checks passes, perform the operation as ourselves.
9074 final long identity = Binder.clearCallingIdentity();
9075 try {
9076 Phone phone = getPhone(subId);
9077 if (phone == null) return false;
9078
Jack Yu41407ee2019-05-13 16:54:09 -07009079 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009080 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9081 } finally {
9082 Binder.restoreCallingIdentity(identity);
9083 }
9084 }
9085
9086 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009087 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009088 enforceReadPrivilegedPermission("isApnMetered");
9089
9090 // Now that all security checks passes, perform the operation as ourselves.
9091 final long identity = Binder.clearCallingIdentity();
9092 try {
9093 Phone phone = getPhone(subId);
9094 if (phone == null) return true; // By default return true.
9095
Jack Yu41407ee2019-05-13 16:54:09 -07009096 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009097 } finally {
9098 Binder.restoreCallingIdentity(identity);
9099 }
9100 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009101
9102 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009103 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9104 int subscriptionId, IBooleanConsumer resultCallback) {
9105 enforceModifyPermission();
9106 long token = Binder.clearCallingIdentity();
9107 try {
9108 Phone phone = getPhone(subscriptionId);
9109 if (phone == null) {
9110 try {
9111 if (resultCallback != null) {
9112 resultCallback.accept(false);
9113 }
9114 } catch (RemoteException e) {
9115 // ignore
9116 }
9117 return;
9118 }
9119 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9120 Pair.create(specifiers, (x) -> {
9121 try {
9122 if (resultCallback != null) {
9123 resultCallback.accept(x);
9124 }
9125 } catch (RemoteException e) {
9126 // ignore
9127 }
9128 });
9129 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9130 } finally {
9131 Binder.restoreCallingIdentity(token);
9132 }
9133 }
9134
9135 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009136 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9137 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07009138 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08009139 mApp, subId, "getSystemSelectionChannels");
9140 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9141 final long identity = Binder.clearCallingIdentity();
9142 try {
Sarah Chin58691872021-03-13 03:17:40 -08009143 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9144 if (result instanceof IllegalStateException) {
9145 throw (IllegalStateException) result;
9146 }
9147 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chincc055732020-11-18 13:39:35 -08009148 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9149 return specifiers;
9150 } finally {
9151 Binder.restoreCallingIdentity(identity);
9152 }
9153 }
9154
9155 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009156 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009157 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009158 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9159 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9160 if (iccRecords == null) {
9161 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9162 return false;
9163 }
9164 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9165 }
9166
9167 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009168 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9169 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009170 if (callingPackage == null) {
9171 callingPackage = getCurrentPackageName();
9172 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009173 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9174 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009175 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9176 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009177 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9178 }
9179 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9180 Intent intent = new Intent();
9181 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9182 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9183 // Bring up choose default SMS subscription dialog right now
9184 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9185 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9186 mApp.startActivity(intent);
9187 }
chen xud5ca2d52019-05-28 15:20:57 -07009188
9189 @Override
9190 public String getMmsUAProfUrl(int subId) {
9191 //TODO investigate if this API should require proper permission check in R b/133791609
9192 final long identity = Binder.clearCallingIdentity();
9193 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009194 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9195 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9196 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9197 return carrierUAProfUrl;
9198 }
chen xud5ca2d52019-05-28 15:20:57 -07009199 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9200 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9201 } finally {
9202 Binder.restoreCallingIdentity(identity);
9203 }
9204 }
9205
9206 @Override
9207 public String getMmsUserAgent(int subId) {
9208 //TODO investigate if this API should require proper permission check in R b/133791609
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009211 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9212 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9213 if (!TextUtils.isEmpty(carrierUserAgent)) {
9214 return carrierUserAgent;
9215 }
chen xud5ca2d52019-05-28 15:20:57 -07009216 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9217 .getString(com.android.internal.R.string.config_mms_user_agent);
9218 } finally {
9219 Binder.restoreCallingIdentity(identity);
9220 }
9221 }
Jack Yub07d4972019-05-28 16:12:25 -07009222
9223 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009224 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9225 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9226
9227 final long identity = Binder.clearCallingIdentity();
9228 try {
9229 Phone phone = getPhone(subscriptionId);
9230 if (phone == null) return false;
9231
9232 switch (policy) {
9233 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9234 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9235 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9236 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9237 default:
9238 throw new IllegalArgumentException(policy + " is not a valid policy");
9239 }
9240 } finally {
9241 Binder.restoreCallingIdentity(identity);
9242 }
9243 }
9244
9245 @Override
9246 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9247 boolean enabled) {
9248 enforceModifyPermission();
9249
9250 final long identity = Binder.clearCallingIdentity();
9251 try {
9252 Phone phone = getPhone(subscriptionId);
9253 if (phone == null) return;
9254
9255 switch (policy) {
9256 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9257 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9258 break;
9259 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9260 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9261 break;
9262 default:
9263 throw new IllegalArgumentException(policy + " is not a valid policy");
9264 }
9265 } finally {
9266 Binder.restoreCallingIdentity(identity);
9267 }
9268 }
9269
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009270 /**
Hall Liub48cf452020-09-25 11:13:49 -07009271 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009272 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9273 * otherwise.
9274 */
9275 @Override
9276 public void setCepEnabled(boolean isCepEnabled) {
9277 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9278
9279 final long identity = Binder.clearCallingIdentity();
9280 try {
9281 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9282 for (Phone phone : PhoneFactory.getPhones()) {
9283 Phone defaultPhone = phone.getImsPhone();
9284 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9285 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9286 ImsPhoneCallTracker imsPhoneCallTracker =
9287 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9288 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9289 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9290 + imsPhone.getMsisdn());
9291 }
9292 }
9293 } finally {
9294 Binder.restoreCallingIdentity(identity);
9295 }
9296 }
allenwtsu46dcc572020-01-08 18:24:03 +08009297
9298 /**
9299 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9300 *
9301 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9302 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9303 * before being read.
9304 */
9305 @Override
9306 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9307 isCompressed) {
9308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9309 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009310 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9311 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9312 }
9313 if (!isImsAvailableOnDevice()) {
9314 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9315 "IMS not available on device.");
9316 }
9317
9318 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009319 try {
Hui Wang068ab862020-10-31 05:12:53 +00009320 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9321 } finally {
9322 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009323 }
9324 }
zoey chenf95ca592019-12-30 16:11:23 +08009325
9326 @Override
9327 public boolean isIccLockEnabled(int subId) {
9328 enforceReadPrivilegedPermission("isIccLockEnabled");
9329
9330 // Now that all security checks passes, perform the operation as ourselves.
9331 final long identity = Binder.clearCallingIdentity();
9332 try {
9333 Phone phone = getPhone(subId);
9334 if (phone != null && phone.getIccCard() != null) {
9335 return phone.getIccCard().getIccLockEnabled();
9336 } else {
9337 return false;
9338 }
9339 } finally {
9340 Binder.restoreCallingIdentity(identity);
9341 }
9342 }
9343
9344 /**
zoey chene02881a2019-12-30 16:11:23 +08009345 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009346 *
zoey chene02881a2019-12-30 16:11:23 +08009347 * @return an integer representing the status of IccLock enabled or disabled in the following
9348 * three cases:
9349 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9350 * successfully.
9351 * - Positive number and zero for remaining password attempts.
9352 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009353 *
9354 */
9355 @Override
9356 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9357 enforceModifyPermission();
9358
9359 Phone phone = getPhone(subId);
9360 if (phone == null) {
9361 return 0;
9362 }
9363 // Now that all security checks passes, perform the operation as ourselves.
9364 final long identity = Binder.clearCallingIdentity();
9365 try {
9366 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9367 new Pair<Boolean, String>(enabled, password), phone, null);
9368 return attemptsRemaining;
9369
9370 } catch (Exception e) {
9371 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9372 } finally {
9373 Binder.restoreCallingIdentity(identity);
9374 }
9375 return 0;
9376 }
9377
9378 /**
9379 * Change the ICC password used in ICC pin lock.
9380 *
zoey chene02881a2019-12-30 16:11:23 +08009381 * @return an integer representing the status of IccLock changed in the following three cases:
9382 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9383 * - Positive number and zero for remaining password attempts.
9384 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009385 *
9386 */
9387 @Override
9388 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9389 enforceModifyPermission();
9390
9391 Phone phone = getPhone(subId);
9392 if (phone == null) {
9393 return 0;
9394 }
9395 // Now that all security checks passes, perform the operation as ourselves.
9396 final long identity = Binder.clearCallingIdentity();
9397 try {
9398 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9399 new Pair<String, String>(oldPassword, newPassword), phone, null);
9400 return attemptsRemaining;
9401
9402 } catch (Exception e) {
9403 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9404 } finally {
9405 Binder.restoreCallingIdentity(identity);
9406 }
9407 return 0;
9408 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009409
Peter Wangdafb9ac2020-01-15 14:13:38 -08009410 /**
9411 * Request for receiving user activity notification
9412 */
9413 @Override
9414 public void requestUserActivityNotification() {
9415 if (!mNotifyUserActivity.get()
9416 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9417 mNotifyUserActivity.set(true);
9418 }
9419 }
9420
9421 /**
9422 * Called when userActivity is signalled in the power manager.
9423 * This is safe to call from any thread, with any window manager locks held or not.
9424 */
9425 @Override
9426 public void userActivity() {
9427 // ***************************************
9428 // * Inherited from PhoneWindowManager *
9429 // ***************************************
9430 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9431 // WITH ITS LOCKS HELD.
9432 //
9433 // This code must be VERY careful about the locks
9434 // it acquires.
9435 // In fact, the current code acquires way too many,
9436 // and probably has lurking deadlocks.
9437
9438 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9439 throw new SecurityException("Only the OS may call notifyUserActivity()");
9440 }
9441
9442 if (mNotifyUserActivity.getAndSet(false)) {
9443 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9444 USER_ACTIVITY_NOTIFICATION_DELAY);
9445 }
9446 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009447
Malcolm Chen884180b2020-04-13 11:59:40 -07009448 @Override
9449 public boolean canConnectTo5GInDsdsMode() {
9450 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9451 }
Jack Yud10cdd42020-09-28 20:28:01 -07009452
9453 @Override
9454 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9455 String callingFeatureId) {
9456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9457 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9458 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9459 }
9460
9461 Phone phone = getPhone(subId);
9462 if (phone == null) {
9463 throw new RuntimeException("phone is not available");
9464 }
9465 // Now that all security checks passes, perform the operation as ourselves.
9466 final long identity = Binder.clearCallingIdentity();
9467 try {
9468 return phone.getEquivalentHomePlmns();
9469 } finally {
9470 Binder.restoreCallingIdentity(identity);
9471 }
9472 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009473
Hui Wang0866fcc2020-10-12 12:14:23 -07009474 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009475 public boolean isRadioInterfaceCapabilitySupported(
9476 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009477 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009478 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009479 if (radioInterfaceCapabilities == null) {
9480 throw new RuntimeException("radio interface capabilities are not available");
9481 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009482 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009483 }
9484 }
9485
9486 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009487 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9488 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009489 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9490 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9491 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9492 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9493 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009494 if (DBG) {
9495 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9496 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9497 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9498 }
9499
9500 if (!SubscriptionManager.isValidSubscriptionId(subId)
9501 || appType < TelephonyManager.APPTYPE_UNKNOWN
9502 || appType > TelephonyManager.APPTYPE_ISIM
9503 || nafUrl == null || securityProtocol == null || callback == null) {
9504 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9505 if (callback != null) {
9506 try {
9507 callback.onAuthenticationFailure(
9508 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9509 } catch (RemoteException exception) {
9510 log("Fail to notify onAuthenticationFailure due to " + exception);
9511 }
9512 return;
9513 }
9514 }
9515
9516 final long token = Binder.clearCallingIdentity();
9517 try {
9518 getGbaManager(subId).bootstrapAuthenticationRequest(
9519 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9520 forceBootStrapping, callback));
9521 } finally {
9522 Binder.restoreCallingIdentity(token);
9523 }
9524 }
9525
Jack Nudelman24d51a52020-11-24 12:08:04 -08009526 /**
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009527 * Attempts to set the radio power state for all phones for thermal reason.
9528 * This does not guarantee that the
Jack Nudelman24d51a52020-11-24 12:08:04 -08009529 * requested radio power state will actually be set. See {@link
9530 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9531 *
Jack Nudelman24d51a52020-11-24 12:08:04 -08009532 * @param enable {@code true} if trying to turn radio on.
9533 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9534 * false}.
9535 */
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009536 private boolean setRadioPowerForThermal(boolean enable) {
9537 boolean isPhoneAvailable = false;
9538 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9539 Phone phone = PhoneFactory.getPhone(i);
9540 if (phone != null) {
9541 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9542 isPhoneAvailable = true;
9543 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009544 }
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009545
9546 // return true if successfully informed the phone object about the thermal radio power
9547 // request.
9548 return isPhoneAvailable;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009549 }
9550
9551 private int handleDataThrottlingRequest(int subId,
9552 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009553 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9554 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9555 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9556 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9557 throw new IllegalArgumentException("modem does not support data throttling");
9558 }
9559
Jack Nudelman24d51a52020-11-24 12:08:04 -08009560 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9561 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009562 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009563 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9564 }
9565
9566 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9567
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009568 if (isDataThrottlingSupported) {
9569 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009570 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009571 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9572 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9573 } else if (thermalMitigationResult
9574 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman20352592021-05-20 13:57:30 -07009575 log("Modem likely does not support data throttling on secondary carrier. Data " +
9576 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9577 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009578 }
9579 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009580 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009581
9582 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009583 }
9584
Jack Nudelman644b91a2021-03-12 14:09:48 -08009585 private static List<String> getThermalMitigationAllowlist(Context context) {
9586 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9587 for (String pckg : context.getResources()
9588 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9589 sThermalMitigationAllowlistedPackages.add(pckg);
9590 }
9591 }
9592
9593 return sThermalMitigationAllowlistedPackages;
9594 }
9595
Jack Nudelmane634f962021-05-13 10:00:15 -07009596 private boolean isAnyPhoneInEmergencyState() {
9597 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9598 if (tm.isInEmergencyCall()) {
9599 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9600 return true;
9601 }
9602 for (Phone phone : PhoneFactory.getPhones()) {
9603 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9604 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9605 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9606 + phone.isInEcm());
9607 return true;
9608 }
9609 }
9610
9611 return false;
9612 }
9613
Jack Nudelman644b91a2021-03-12 14:09:48 -08009614 /**
9615 * Used by shell commands to add an authorized package name for thermal mitigation.
9616 * @param packageName name of package to be allowlisted
9617 * @param context
9618 */
9619 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9620 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9621 sThermalMitigationAllowlistedPackages.add(packageName);
9622 }
9623
9624 /**
9625 * Used by shell commands to remove an authorized package name for thermal mitigation.
9626 * @param packageName name of package to remove from allowlist
9627 * @param context
9628 */
9629 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9630 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9631 sThermalMitigationAllowlistedPackages.remove(packageName);
9632 }
9633
Jack Nudelman24d51a52020-11-24 12:08:04 -08009634 /**
9635 * Thermal mitigation request to control functionalities at modem.
9636 *
9637 * @param subId the id of the subscription.
9638 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009639 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009640 *
9641 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9642 */
9643 @Override
9644 @ThermalMitigationResult
9645 public int sendThermalMitigationRequest(
9646 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009647 ThermalMitigationRequest thermalMitigationRequest,
9648 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009649 enforceModifyPermission();
9650
Jack Nudelman644b91a2021-03-12 14:09:48 -08009651 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9652 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9653 .contains(callingPackage)) {
9654 throw new SecurityException("Calling package must be configured in the device config. "
9655 + "calling package: " + callingPackage);
9656 }
9657
Jack Nudelman24d51a52020-11-24 12:08:04 -08009658 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9659 final long identity = Binder.clearCallingIdentity();
9660
9661 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9662 try {
9663 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9664 switch (thermalMitigationAction) {
9665 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9666 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009667 handleDataThrottlingRequest(subId,
9668 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009669 break;
9670 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9671 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9672 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9673 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9674 }
9675
9676 // Ensure that radio is on. If not able to power on due to phone being
9677 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009678 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009679 thermalMitigationResult =
9680 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9681 break;
9682 }
9683
9684 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9685 false);
9686 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9687 break;
9688 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9689 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9690 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9691 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9692 }
9693
9694 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9695 if (registry != null) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009696 Phone phone = getPhone(subId);
9697 if (phone == null) {
9698 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009699 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009700 break;
9701 }
9702
Jack Nudelmane634f962021-05-13 10:00:15 -07009703 TelephonyConnectionService service =
9704 registry.getTelephonyConnectionService();
Jack Nudelmana80c0012021-06-17 15:39:58 -07009705 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane634f962021-05-13 10:00:15 -07009706 Log.e(LOG_TAG, "An emergency call is pending");
9707 thermalMitigationResult =
9708 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9709 break;
9710 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009711 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009712 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009713 break;
9714 }
9715 } else {
9716 thermalMitigationResult =
9717 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9718 break;
9719 }
9720
9721 // Turn radio off. If not able to power off due to phone being unavailable,
9722 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009723 if (!setRadioPowerForThermal(false)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009724 thermalMitigationResult =
9725 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9726 break;
9727 }
9728 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009729 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009730 break;
9731 default:
9732 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9733 + "not exist. Requested action: " + thermalMitigationAction);
9734 }
9735 } catch (IllegalArgumentException e) {
9736 throw e;
9737 } catch (Exception e) {
9738 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9739 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9740 } finally {
9741 Binder.restoreCallingIdentity(identity);
9742 }
9743
9744 if (DBG) {
9745 log("thermalMitigationRequest returning with thermalMitigationResult: "
9746 + thermalMitigationResult);
9747 }
9748
9749 return thermalMitigationResult;
9750 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009751
9752 /**
9753 * Set the GbaService Package Name that Telephony will bind to.
9754 *
9755 * @param subId The sim that the GbaService is associated with.
9756 * @param packageName The name of the package to be replaced with.
9757 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9758 */
9759 @Override
9760 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9761 enforceModifyPermission();
9762
9763 final long identity = Binder.clearCallingIdentity();
9764 try {
9765 return getGbaManager(subId).overrideServicePackage(packageName);
9766 } finally {
9767 Binder.restoreCallingIdentity(identity);
9768 }
9769 }
9770
9771 /**
9772 * Return the package name of the currently bound GbaService.
9773 *
9774 * @param subId The sim that the GbaService is associated with.
9775 * @return the package name of the GbaService configuration, null if GBA is not supported.
9776 */
9777 @Override
9778 public String getBoundGbaService(int subId) {
9779 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9780
9781 final long identity = Binder.clearCallingIdentity();
9782 try {
9783 return getGbaManager(subId).getServicePackage();
9784 } finally {
9785 Binder.restoreCallingIdentity(identity);
9786 }
9787 }
9788
9789 /**
9790 * Set the release time for telephony to unbind GbaService.
9791 *
9792 * @param subId The sim that the GbaService is associated with.
9793 * @param interval The release time to unbind GbaService by millisecond.
9794 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9795 */
9796 @Override
9797 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9798 enforceModifyPermission();
9799
9800 final long identity = Binder.clearCallingIdentity();
9801 try {
9802 return getGbaManager(subId).overrideReleaseTime(interval);
9803 } finally {
9804 Binder.restoreCallingIdentity(identity);
9805 }
9806 }
9807
9808 /**
9809 * Return the release time for telephony to unbind GbaService.
9810 *
9811 * @param subId The sim that the GbaService is associated with.
9812 * @return The release time to unbind GbaService by millisecond.
9813 */
9814 @Override
9815 public int getGbaReleaseTime(int subId) {
9816 enforceReadPrivilegedPermission("getGbaReleaseTime");
9817
9818 final long identity = Binder.clearCallingIdentity();
9819 try {
9820 return getGbaManager(subId).getReleaseTime();
9821 } finally {
9822 Binder.restoreCallingIdentity(identity);
9823 }
9824 }
9825
9826 private GbaManager getGbaManager(int subId) {
9827 GbaManager instance = GbaManager.getInstance(subId);
9828 if (instance == null) {
9829 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9830 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9831 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9832 }
9833 return instance;
9834 }
Hui Wang068ab862020-10-31 05:12:53 +00009835
9836 /**
9837 * indicate whether the device and the carrier can support
9838 * RCS VoLTE single registration.
9839 */
9840 @Override
9841 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009842 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9843 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9844 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9845 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009846
9847 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9848 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9849 }
9850
9851 final long identity = Binder.clearCallingIdentity();
9852 try {
9853 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9854 if (rpm != null) {
Hui Wang048c10a2021-06-21 18:05:57 +00009855 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
9856 if (isCapable != null) {
9857 return isCapable;
9858 }
Hui Wang068ab862020-10-31 05:12:53 +00009859 }
Hui Wang048c10a2021-06-21 18:05:57 +00009860 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
9861 "service is temporarily unavailable.");
Hui Wang068ab862020-10-31 05:12:53 +00009862 } finally {
9863 Binder.restoreCallingIdentity(identity);
9864 }
9865 }
9866
9867 /**
9868 * Register RCS provisioning callback.
9869 */
9870 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009871 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009872 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009873 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009874 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009875 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9876 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009877
9878 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9879 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9880 }
9881 if (!isImsAvailableOnDevice()) {
9882 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9883 "IMS not available on device.");
9884 }
9885
9886 final long identity = Binder.clearCallingIdentity();
9887 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009888 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009889 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009890 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9891 "Service not available for the subscription.");
9892 }
Hui Wang068ab862020-10-31 05:12:53 +00009893 } finally {
9894 Binder.restoreCallingIdentity(identity);
9895 }
9896 }
9897
9898 /**
9899 * Unregister RCS provisioning callback.
9900 */
9901 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009902 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009903 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009904 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009905 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009906 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9907 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009908
9909 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9910 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9911 }
9912 if (!isImsAvailableOnDevice()) {
9913 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9914 "IMS not available on device.");
9915 }
9916
9917 final long identity = Binder.clearCallingIdentity();
9918 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009919 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009920 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009921 } finally {
9922 Binder.restoreCallingIdentity(identity);
9923 }
9924 }
9925
9926 /**
9927 * trigger RCS reconfiguration.
9928 */
9929 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009930 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9931 "triggerRcsReconfiguration",
9932 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009933
9934 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9935 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9936 }
9937 if (!isImsAvailableOnDevice()) {
9938 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9939 "IMS not available on device.");
9940 }
9941
9942 final long identity = Binder.clearCallingIdentity();
9943 try {
9944 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9945 } finally {
9946 Binder.restoreCallingIdentity(identity);
9947 }
9948 }
9949
9950 /**
9951 * Provide the client configuration parameters of the RCS application.
9952 */
9953 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009954 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9955 "setRcsClientConfiguration",
9956 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009957
9958 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9959 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9960 }
9961 if (!isImsAvailableOnDevice()) {
9962 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9963 "IMS not available on device.");
9964 }
9965
9966 final long identity = Binder.clearCallingIdentity();
9967
9968 try {
9969 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9970 if (configBinder == null) {
9971 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9972 } else {
9973 configBinder.setRcsClientConfiguration(rcc);
9974 }
9975 } catch (RemoteException e) {
9976 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9977 } finally {
9978 Binder.restoreCallingIdentity(identity);
9979 }
9980 }
9981
9982 /**
Hui Wang19a21872021-02-19 20:45:36 -08009983 * Enables or disables the test mode for RCS VoLTE single registration.
9984 */
9985 @Override
9986 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9987 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9988 "setRcsSingleRegistrationTestModeEnabled");
9989
9990 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9991 }
9992
9993 /**
9994 * Gets the test mode for RCS VoLTE single registration.
9995 */
9996 @Override
9997 public boolean getRcsSingleRegistrationTestModeEnabled() {
9998 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9999 "getRcsSingleRegistrationTestModeEnabled");
10000
10001 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10002 }
10003
10004 /**
Hui Wang068ab862020-10-31 05:12:53 +000010005 * Overrides the config of RCS VoLTE single registration enabled for the device.
10006 */
10007 @Override
10008 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10010 "setDeviceSingleRegistrationEnabledOverride");
10011 enforceModifyPermission();
10012
10013 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10014 : Boolean.parseBoolean(enabledStr);
10015 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010016 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +000010017 }
10018
10019 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010020 * Sends a device to device communication message. Only usable via shell.
10021 * @param message message to send.
10022 * @param value message value.
10023 */
10024 @Override
10025 public void sendDeviceToDeviceMessage(int message, int value) {
10026 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10027 "setCarrierSingleRegistrationEnabledOverride");
10028 enforceModifyPermission();
10029
10030 final long identity = Binder.clearCallingIdentity();
10031 try {
10032 TelephonyConnectionService service =
10033 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10034 if (service == null) {
10035 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10036 return;
10037 }
10038 service.sendTestDeviceToDeviceMessage(message, value);
10039 } finally {
10040 Binder.restoreCallingIdentity(identity);
10041 }
10042 }
10043
10044
10045 /**
Hui Wang068ab862020-10-31 05:12:53 +000010046 * Gets the config of RCS VoLTE single registration enabled for the device.
10047 */
10048 @Override
10049 public boolean getDeviceSingleRegistrationEnabled() {
10050 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10051 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10052 }
10053
10054 /**
10055 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10056 */
10057 @Override
10058 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10059 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10060 "setCarrierSingleRegistrationEnabledOverride");
10061 enforceModifyPermission();
10062
10063 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10064 : Boolean.parseBoolean(enabledStr);
10065 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10066 subId, enabled);
10067 }
10068
10069 /**
10070 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10071 */
10072 @Override
10073 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10074 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10075 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10076 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010077
10078 /**
Hui Wangeadb2562021-02-26 09:33:38 -080010079 * Overrides the ims feature validation result
10080 */
10081 @Override
10082 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10083 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10084 "setImsFeatureValidationOverride");
10085
10086 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10087 : Boolean.parseBoolean(enabledStr);
10088 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10089 subId, enabled);
10090 }
10091
10092 /**
10093 * Gets the ims feature validation override value
10094 */
10095 @Override
10096 public boolean getImsFeatureValidationOverride(int subId) {
10097 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10098 "getImsFeatureValidationOverride");
10099 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10100 }
10101
10102 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010103 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10104 * their mobile plan.
10105 */
10106 @Override
10107 public String getMobileProvisioningUrl() {
10108 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10109 final long identity = Binder.clearCallingIdentity();
10110 try {
10111 return getDefaultPhone().getMobileProvisioningUrl();
10112 } finally {
10113 Binder.restoreCallingIdentity(identity);
10114 }
10115 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010116
James.cf Linbcdf8b32021-01-14 16:44:13 +080010117 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010118 * Get the EAB contact from the EAB database.
10119 */
10120 @Override
10121 public String getContactFromEab(String contact) {
10122 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10123 enforceModifyPermission();
10124 final long identity = Binder.clearCallingIdentity();
10125 try {
10126 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10127 } finally {
10128 Binder.restoreCallingIdentity(identity);
10129 }
10130 }
10131
10132 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010133 * Remove the EAB contacts from the EAB database.
10134 */
10135 @Override
10136 public int removeContactFromEab(int subId, String contacts) {
10137 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10138 enforceModifyPermission();
10139 final long identity = Binder.clearCallingIdentity();
10140 try {
10141 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10142 } finally {
10143 Binder.restoreCallingIdentity(identity);
10144 }
10145 }
10146
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010147 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010148 public boolean getDeviceUceEnabled() {
10149 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10150 final long identity = Binder.clearCallingIdentity();
10151 try {
10152 return mApp.getDeviceUceEnabled();
10153 } finally {
10154 Binder.restoreCallingIdentity(identity);
10155 }
10156 }
10157
10158 @Override
10159 public void setDeviceUceEnabled(boolean isEnabled) {
10160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10161 final long identity = Binder.clearCallingIdentity();
10162 try {
10163 mApp.setDeviceUceEnabled(isEnabled);
10164 } finally {
10165 Binder.restoreCallingIdentity(identity);
10166 }
10167 }
10168
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010169 /**
10170 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10171 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10172 */
10173 // Used for SHELL command only right now.
10174 @Override
10175 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10176 List<String> featureTags) {
10177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10178 "addUceRegistrationOverrideShell");
10179 final long identity = Binder.clearCallingIdentity();
10180 try {
10181 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10182 new ArraySet<>(featureTags));
10183 } catch (ImsException e) {
10184 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10185 } finally {
10186 Binder.restoreCallingIdentity(identity);
10187 }
10188 }
10189
10190 /**
10191 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10192 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10193 */
10194 // Used for SHELL command only right now.
10195 @Override
10196 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10197 List<String> featureTags) {
10198 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10199 "removeUceRegistrationOverrideShell");
10200 final long identity = Binder.clearCallingIdentity();
10201 try {
10202 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10203 new ArraySet<>(featureTags));
10204 } catch (ImsException e) {
10205 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10206 } finally {
10207 Binder.restoreCallingIdentity(identity);
10208 }
10209 }
10210
10211 /**
10212 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10213 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10214 */
10215 // Used for SHELL command only right now.
10216 @Override
10217 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10218 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10219 "clearUceRegistrationOverrideShell");
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
10222 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10223 } catch (ImsException e) {
10224 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10225 } finally {
10226 Binder.restoreCallingIdentity(identity);
10227 }
10228 }
10229
10230 /**
10231 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10232 */
10233 // Used for SHELL command only right now.
10234 @Override
10235 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10237 "getLatestRcsContactUceCapabilityShell");
10238 final long identity = Binder.clearCallingIdentity();
10239 try {
10240 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10241 } catch (ImsException e) {
10242 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10243 } finally {
10244 Binder.restoreCallingIdentity(identity);
10245 }
10246 }
10247
10248 /**
10249 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10250 * device does not have an active PUBLISH.
10251 */
10252 // Used for SHELL command only right now.
10253 @Override
10254 public String getLastUcePidfXmlShell(int subId) {
10255 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10256 final long identity = Binder.clearCallingIdentity();
10257 try {
10258 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10259 } catch (ImsException e) {
10260 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10261 } finally {
10262 Binder.restoreCallingIdentity(identity);
10263 }
10264 }
10265
James.cf Line8713a42021-04-29 16:04:26 +080010266 /**
10267 * Remove UCE requests cannot be sent to the network status.
10268 */
10269 // Used for SHELL command only right now.
10270 @Override
10271 public boolean removeUceRequestDisallowedStatus(int subId) {
10272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10273 final long identity = Binder.clearCallingIdentity();
10274 try {
10275 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10276 } catch (ImsException e) {
10277 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10278 } finally {
10279 Binder.restoreCallingIdentity(identity);
10280 }
10281 }
10282
James.cf Lin18bb9002021-05-25 01:37:38 +080010283 /**
10284 * Remove UCE requests cannot be sent to the network status.
10285 */
10286 // Used for SHELL command only.
10287 @Override
10288 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10289 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10290 final long identity = Binder.clearCallingIdentity();
10291 try {
10292 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10293 } catch (ImsException e) {
10294 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10295 } finally {
10296 Binder.restoreCallingIdentity(identity);
10297 }
10298 }
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010299
James.cf Lin4b784aa2021-01-31 03:25:15 +080010300 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010301 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10302 String callingPackage) {
10303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10304 mApp, subId, "setSignalStrengthUpdateRequest");
10305
10306 final int callingUid = Binder.getCallingUid();
10307 // Verify that tha callingPackage belongs to the calling UID
10308 mApp.getSystemService(AppOpsManager.class)
10309 .checkPackage(callingUid, callingPackage);
10310
10311 validateSignalStrengthUpdateRequest(request, callingUid);
10312
10313 final long identity = Binder.clearCallingIdentity();
10314 try {
10315 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10316 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10317
10318 if (result instanceof IllegalStateException) {
10319 throw (IllegalStateException) result;
10320 }
10321 } finally {
10322 Binder.restoreCallingIdentity(identity);
10323 }
10324 }
10325
10326 @Override
10327 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10328 String callingPackage) {
10329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10330 mApp, subId, "clearSignalStrengthUpdateRequest");
10331
10332 final int callingUid = Binder.getCallingUid();
10333 // Verify that tha callingPackage belongs to the calling UID
10334 mApp.getSystemService(AppOpsManager.class)
10335 .checkPackage(callingUid, callingPackage);
10336
10337 final long identity = Binder.clearCallingIdentity();
10338 try {
10339 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10340 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10341
10342 if (result instanceof IllegalStateException) {
10343 throw (IllegalStateException) result;
10344 }
10345 } finally {
10346 Binder.restoreCallingIdentity(identity);
10347 }
10348 }
10349
10350 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10351 int callingUid) {
10352 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10353 // phone/system process do not have further restriction on request
10354 return;
10355 }
10356
10357 // Applications has restrictions on how to use the request:
10358 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10359 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10360 // This is not system caller which has been checked above
10361 throw new IllegalArgumentException(
10362 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10363 }
10364
10365 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10366 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10367 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10368 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10369 || info.isEnabled()) {
10370 throw new IllegalArgumentException(
10371 "Only system can set hide fields in SignalThresholdInfo");
10372 }
10373
10374 // Thresholds length for each RAN need in range. This has been validated in
10375 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10376 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10377 final int[] thresholds = info.getThresholds();
10378 Objects.requireNonNull(thresholds);
10379 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10380 || thresholds.length
10381 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10382 throw new IllegalArgumentException(
10383 "thresholds length is out of range: " + thresholds.length);
10384 }
10385 }
10386 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010387
10388 /**
10389 * Prepare TelephonyManager for an unattended reboot. The reboot is
10390 * required to be done shortly after the API is invoked.
10391 */
10392 @Override
10393 @TelephonyManager.PrepareUnattendedRebootResult
10394 public int prepareForUnattendedReboot() {
Rafael Higuera Silvacd3aef22021-08-30 15:16:50 +000010395 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionned9fbae52020-11-13 02:36:59 +000010396 enforceRebootPermission();
10397
10398 final long identity = Binder.clearCallingIdentity();
10399 try {
Rafael Higuera Silvacd3aef22021-08-30 15:16:50 +000010400 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionned9fbae52020-11-13 02:36:59 +000010401 } finally {
10402 Binder.restoreCallingIdentity(identity);
10403 }
10404 }
SongFerngWang2c4309d2021-01-17 21:51:44 +080010405
10406 /**
10407 * Gets the current phone capability.
10408 *
10409 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10410 * @return the PhoneCapability which describes the data connection capability of modem.
10411 * It's used to evaluate possible phone config change, for example from single
10412 * SIM device to multi-SIM device.
10413 */
10414 @Override
10415 public PhoneCapability getPhoneCapability() {
10416 enforceReadPrivilegedPermission("getPhoneCapability");
10417 final long identity = Binder.clearCallingIdentity();
10418 try {
10419 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10420 } finally {
10421 Binder.restoreCallingIdentity(identity);
10422 }
10423 }
Hongbo Zengd31d3a32021-02-08 21:50:28 +080010424
10425 /**
10426 * Request to get the current slicing configuration including URSP rules and
10427 * NSSAIs (configured, allowed and rejected).
10428 *
10429 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10430 */
10431 @Override
10432 public void getSlicingConfig(ResultReceiver callback) {
10433 enforceReadPrivilegedPermission("getSlicingConfig");
10434
10435 final long identity = Binder.clearCallingIdentity();
10436 try {
10437 Phone phone = getDefaultPhone();
10438 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10439 } finally {
10440 Binder.restoreCallingIdentity(identity);
10441 }
10442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010443}