blob: 5fc8f86b9f7ddf820e41bf9a6166b5bd438536a5 [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 =
1958 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1959 notifyRequester(request);
1960 break;
1961
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 default:
1963 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1964 break;
1965 }
1966 }
Jake Hambye994d462014-02-03 13:10:13 -08001967
Pengquan Menga1bb6272018-09-06 09:59:22 -07001968 private void notifyRequester(MainThreadRequest request) {
1969 synchronized (request) {
1970 request.notifyAll();
1971 }
1972 }
1973
Jake Hambye994d462014-02-03 13:10:13 -08001974 private void handleNullReturnEvent(Message msg, String command) {
1975 AsyncResult ar = (AsyncResult) msg.obj;
1976 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1977 if (ar.exception == null) {
1978 request.result = true;
1979 } else {
1980 request.result = false;
1981 if (ar.exception instanceof CommandException) {
1982 loge(command + ": CommandException: " + ar.exception);
1983 } else {
1984 loge(command + ": Unknown exception");
1985 }
1986 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001987 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
1991 /**
1992 * Posts the specified command to be executed on the main thread,
1993 * waits for the request to complete, and returns the result.
1994 * @see #sendRequestAsync
1995 */
1996 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001997 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1998 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001999 }
2000
2001 /**
2002 * Posts the specified command to be executed on the main thread,
2003 * waits for the request to complete, and returns the result.
2004 * @see #sendRequestAsync
2005 */
2006 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2007 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002008 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002009 }
2010
2011 /**
2012 * Posts the specified command to be executed on the main thread,
2013 * waits for the request to complete, and returns the result.
2014 * @see #sendRequestAsync
2015 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002016 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002017 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2018 }
2019
2020 /**
2021 * Posts the specified command to be executed on the main thread,
2022 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2023 * if not timeout or null otherwise.
2024 * @see #sendRequestAsync
2025 */
2026 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2027 long timeoutInMs) {
2028 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002029 }
2030
2031 /**
2032 * Posts the specified command to be executed on the main thread,
2033 * waits for the request to complete, and returns the result.
2034 * @see #sendRequestAsync
2035 */
Nathan Harold92bed182018-10-12 18:16:49 -07002036 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002037 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002038 }
2039
2040 /**
2041 * Posts the specified command to be executed on the main thread,
2042 * waits for the request to complete, and returns the result.
2043 * @see #sendRequestAsync
2044 */
2045 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002046 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2047 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002048 }
2049
2050 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002051 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2052 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2053 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002054 * @see #sendRequestAsync
2055 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002056 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2057 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2059 throw new RuntimeException("This method will deadlock if called from the main thread.");
2060 }
2061
Nathan Harold92bed182018-10-12 18:16:49 -07002062 MainThreadRequest request = null;
2063 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2064 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2065 } else if (phone != null) {
2066 request = new MainThreadRequest(argument, phone, workSource);
2067 } else {
2068 request = new MainThreadRequest(argument, subId, workSource);
2069 }
2070
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 Message msg = mMainThreadHandler.obtainMessage(command, request);
2072 msg.sendToTarget();
2073
Rambo Wang0f050d82021-02-12 11:43:36 -08002074
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002075 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002076 if (timeoutInMs >= 0) {
2077 // Wait for at least timeoutInMs before returning null request result
2078 long now = SystemClock.elapsedRealtime();
2079 long deadline = now + timeoutInMs;
2080 while (request == null && now < deadline) {
2081 try {
2082 request.wait(deadline - now);
2083 } catch (InterruptedException e) {
2084 // Do nothing, go back and check if request is completed or timeout
2085 } finally {
2086 now = SystemClock.elapsedRealtime();
2087 }
2088 }
2089 } else {
2090 // Wait for the request to complete
2091 while (request.result == null) {
2092 try {
2093 request.wait();
2094 } catch (InterruptedException e) {
2095 // Do nothing, go back and wait until the request is complete
2096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 }
2098 }
2099 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002100 if (request.result == null) {
2101 Log.wtf(LOG_TAG,
2102 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 return request.result;
2105 }
2106
2107 /**
2108 * Asynchronous ("fire and forget") version of sendRequest():
2109 * Posts the specified command to be executed on the main thread, and
2110 * returns immediately.
2111 * @see #sendRequest
2112 */
2113 private void sendRequestAsync(int command) {
2114 mMainThreadHandler.sendEmptyMessage(command);
2115 }
2116
2117 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002118 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002119 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002120 */
2121 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002122 sendRequestAsync(command, argument, null, null);
2123 }
2124
2125 /**
2126 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2127 * @see {@link #sendRequest(int,Object)}
2128 */
2129 private void sendRequestAsync(
2130 int command, Object argument, Phone phone, WorkSource workSource) {
2131 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002132 Message msg = mMainThreadHandler.obtainMessage(command, request);
2133 msg.sendToTarget();
2134 }
2135
2136 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 * Initialize the singleton PhoneInterfaceManager instance.
2138 * This is only done once, at startup, from PhoneApp.onCreate().
2139 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002140 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 synchronized (PhoneInterfaceManager.class) {
2142 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002143 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 } else {
2145 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2146 }
2147 return sInstance;
2148 }
2149 }
2150
2151 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002152 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerc9c432e2021-05-17 20:54:49 +00002155 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002156 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2158 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002159 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002160 mTelephonySharedPreferences =
2161 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002162 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002163 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002164 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002165 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002166
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 publish();
2168 }
2169
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002170 private Phone getDefaultPhone() {
2171 Phone thePhone = getPhone(getDefaultSubscription());
2172 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2173 }
2174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 private void publish() {
2176 if (DBG) log("publish: " + this);
2177
Peter Wangc035ce42020-01-08 21:00:22 -08002178 TelephonyFrameworkInitializer
2179 .getTelephonyServiceManager()
2180 .getTelephonyServiceRegisterer()
2181 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183
Stuart Scott584921c2015-01-15 17:10:34 -08002184 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002185 if (request.phone != null) {
2186 return request.phone;
2187 } else {
2188 return getPhoneFromSubId(request.subId);
2189 }
2190 }
2191
2192 private Phone getPhoneFromSubId(int subId) {
2193 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2194 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002195 }
2196
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002197 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2198 Phone phone = getPhoneFromRequest(request);
2199 return phone == null ? null :
2200 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2201 }
2202
Wink Saville36469e72014-06-11 15:17:00 -07002203 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002204 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002205 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002208 private void sendEraseModemConfig(Phone phone) {
2209 if (phone != null) {
2210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2211 mApp, phone.getSubId(), "eraseModemConfig");
2212 final long identity = Binder.clearCallingIdentity();
2213 try {
2214 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2215 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2216 } finally {
2217 Binder.restoreCallingIdentity(identity);
2218 }
2219 }
2220 }
2221
Peter Wang050bb052020-01-13 23:33:09 -08002222 private boolean isImsAvailableOnDevice() {
2223 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2224 if (pm == null) {
2225 // For some reason package manger is not available.. This will fail internally anyway,
2226 // so do not throw error and allow.
2227 return true;
2228 }
2229 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2230 }
2231
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002233 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002234 }
2235
Wink Savilleb564aae2014-10-23 10:18:09 -07002236 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 if (DBG) log("dial: " + number);
2238 // No permission check needed here: This is just a wrapper around the
2239 // ACTION_DIAL intent, which is available to any app since it puts up
2240 // the UI before it does anything.
2241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 String url = createTelUrl(number);
2245 if (url == null) {
2246 return;
2247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002249 // PENDING: should we just silently fail if phone is offhook or ringing?
2250 PhoneConstants.State state = mCM.getState(subId);
2251 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2252 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2253 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2254 mApp.startActivity(intent);
2255 }
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259 }
2260
2261 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002262 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002263 }
2264
Wink Savilleb564aae2014-10-23 10:18:09 -07002265 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 if (DBG) log("call: " + number);
2267
2268 // This is just a wrapper around the ACTION_CALL intent, but we still
2269 // need to do a permission check since we're calling startActivity()
2270 // from the context of the phone app.
2271 enforceCallPermission();
2272
Jordan Liu1617b712019-07-10 15:06:26 -07002273 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 != AppOpsManager.MODE_ALLOWED) {
2275 return;
2276 }
2277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002278 final long identity = Binder.clearCallingIdentity();
2279 try {
2280 String url = createTelUrl(number);
2281 if (url == null) {
2282 return;
2283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285 boolean isValid = false;
2286 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2287 if (slist != null) {
2288 for (SubscriptionInfo subInfoRecord : slist) {
2289 if (subInfoRecord.getSubscriptionId() == subId) {
2290 isValid = true;
2291 break;
2292 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002293 }
Wink Saville08874612014-08-31 19:19:58 -07002294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295 if (!isValid) {
2296 return;
2297 }
Wink Saville08874612014-08-31 19:19:58 -07002298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002299 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2300 intent.putExtra(SUBSCRIPTION_KEY, subId);
2301 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2302 mApp.startActivity(intent);
2303 } finally {
2304 Binder.restoreCallingIdentity(identity);
2305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307
Wink Savilleb564aae2014-10-23 10:18:09 -07002308 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002309 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002310 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2311 }
2312
Wink Savilleb564aae2014-10-23 10:18:09 -07002313 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002314 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002315 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2316 }
2317
Wink Savilleb564aae2014-10-23 10:18:09 -07002318 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002320
2321 final long identity = Binder.clearCallingIdentity();
2322 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002323 Phone phone = getPhone(subId);
2324 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325 checkSimPin.start();
2326 return checkSimPin.unlockSim(null, pin);
2327 } finally {
2328 Binder.restoreCallingIdentity(identity);
2329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 }
2331
Wink Savilleb564aae2014-10-23 10:18:09 -07002332 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002334
2335 final long identity = Binder.clearCallingIdentity();
2336 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002337 Phone phone = getPhone(subId);
2338 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339 checkSimPuk.start();
2340 return checkSimPuk.unlockSim(puk, pin);
2341 } finally {
2342 Binder.restoreCallingIdentity(identity);
2343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 }
2345
2346 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002347 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 * a synchronous one.
2349 */
2350 private static class UnlockSim extends Thread {
2351
2352 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002353 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354
2355 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002356 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2357 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358
2359 // For replies from SimCard interface
2360 private Handler mHandler;
2361
2362 // For async handler to identify request type
2363 private static final int SUPPLY_PIN_COMPLETE = 100;
2364
Michele Berionned9fbae52020-11-13 02:36:59 +00002365 UnlockSim(int phoneId, IccCard simCard) {
2366 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 mSimCard = simCard;
2368 }
2369
2370 @Override
2371 public void run() {
2372 Looper.prepare();
2373 synchronized (UnlockSim.this) {
2374 mHandler = new Handler() {
2375 @Override
2376 public void handleMessage(Message msg) {
2377 AsyncResult ar = (AsyncResult) msg.obj;
2378 switch (msg.what) {
2379 case SUPPLY_PIN_COMPLETE:
2380 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2381 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002382 mRetryCount = msg.arg1;
2383 if (ar.exception != null) {
2384 if (ar.exception instanceof CommandException &&
2385 ((CommandException)(ar.exception)).getCommandError()
2386 == CommandException.Error.PASSWORD_INCORRECT) {
2387 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002388 } //When UiccCardApp dispose,handle message and return exception
2389 else if (ar.exception instanceof CommandException &&
2390 ((CommandException) (ar.exception)).getCommandError()
2391 == CommandException.Error.ABORTED) {
2392 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002393 } else {
2394 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2395 }
2396 } else {
2397 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 mDone = true;
2400 UnlockSim.this.notifyAll();
2401 }
2402 break;
2403 }
2404 }
2405 };
2406 UnlockSim.this.notifyAll();
2407 }
2408 Looper.loop();
2409 }
2410
2411 /*
2412 * Use PIN or PUK to unlock SIM card
2413 *
2414 * If PUK is null, unlock SIM card with PIN
2415 *
2416 * If PUK is not null, unlock SIM card with PUK and set PIN code
2417 */
Wink Saville9de0f752013-10-22 19:04:03 -07002418 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419
2420 while (mHandler == null) {
2421 try {
2422 wait();
2423 } catch (InterruptedException e) {
2424 Thread.currentThread().interrupt();
2425 }
2426 }
2427 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2428
2429 if (puk == null) {
2430 mSimCard.supplyPin(pin, callback);
2431 } else {
2432 mSimCard.supplyPuk(puk, pin, callback);
2433 }
2434
2435 while (!mDone) {
2436 try {
2437 Log.d(LOG_TAG, "wait for done");
2438 wait();
2439 } catch (InterruptedException e) {
2440 // Restore the interrupted status
2441 Thread.currentThread().interrupt();
2442 }
2443 }
2444 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002445 int[] resultArray = new int[2];
2446 resultArray[0] = mResult;
2447 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002448
2449 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Grace Jia59437e82021-09-21 15:47:32 -07002450 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
2451 pinStorage.storePin(pin, mPhoneId, pinStorage.getIccid(mPhoneId));
Michele Berionned9fbae52020-11-13 02:36:59 +00002452 }
2453
Wink Saville9de0f752013-10-22 19:04:03 -07002454 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455 }
2456 }
2457
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002458 /**
2459 * This method has been removed due to privacy and stability concerns.
2460 */
2461 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002463 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2464 return;
Wink Saville36469e72014-06-11 15:17:00 -07002465 }
2466
Nathan Harold1f889d82020-06-04 17:05:26 -07002467 @Override
2468 public void updateServiceLocationWithPackageName(String callingPackage) {
2469 mApp.getSystemService(AppOpsManager.class)
2470 .checkPackage(Binder.getCallingUid(), callingPackage);
2471
Nathan Haroldf096d982020-11-18 17:18:06 -08002472 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002473 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2474 // Callers targeting S have no business invoking this method.
2475 return;
2476 }
2477
2478 LocationAccessPolicy.LocationPermissionResult locationResult =
2479 LocationAccessPolicy.checkLocationPermission(mApp,
2480 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2481 .setCallingPackage(callingPackage)
2482 .setCallingFeatureId(null)
2483 .setCallingPid(Binder.getCallingPid())
2484 .setCallingUid(Binder.getCallingUid())
2485 .setMethod("updateServiceLocation")
2486 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2487 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2488 .build());
2489 // Apps that lack location permission have no business calling this method;
2490 // however, because no permission was declared in the public API, denials must
2491 // all be "soft".
2492 switch (locationResult) {
2493 case DENIED_HARD: /* fall through */
2494 case DENIED_SOFT:
2495 return;
2496 }
2497
2498 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 final long identity = Binder.clearCallingIdentity();
2500 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002501 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002502 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002503 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504 }
2505 } finally {
2506 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002507 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 }
2509
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002510 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002511 @Override
2512 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002513 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002514 }
2515
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002516
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002517 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002518 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2519 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2520 callingFeatureId);
2521 }
2522
2523 @Deprecated
2524 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002525 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002526 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2527 }
2528
2529 @Override
2530 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2531 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002533 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002534 return false;
2535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536
2537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 return isRadioOnForSubscriber(subId);
2540 } finally {
2541 Binder.restoreCallingIdentity(identity);
2542 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002543 }
2544
2545 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 final Phone phone = getPhone(subId);
2549 if (phone != null) {
2550 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2551 } else {
2552 return false;
2553 }
2554 } finally {
2555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 }
2558
2559 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002560 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 }
Wink Saville36469e72014-06-11 15:17:00 -07002562
Wink Savilleb564aae2014-10-23 10:18:09 -07002563 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565
2566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 final Phone phone = getPhone(subId);
2569 if (phone != null) {
2570 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2571 }
2572 } finally {
2573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002574 }
Wink Saville36469e72014-06-11 15:17:00 -07002575 }
2576
2577 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002578 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002579 }
2580
Wink Savilleb564aae2014-10-23 10:18:09 -07002581 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002582 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 final Phone phone = getPhone(subId);
2587 if (phone == null) {
2588 return false;
2589 }
2590 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2591 toggleRadioOnOffForSubscriber(subId);
2592 }
2593 return true;
2594 } finally {
2595 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002596 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002597 }
Wink Saville36469e72014-06-11 15:17:00 -07002598
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002599 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002600 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002601 /*
2602 * If any of the Radios are available, it will need to be
2603 * shutdown. So return true if any Radio is available.
2604 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2608 Phone phone = PhoneFactory.getPhone(i);
2609 if (phone != null && phone.isRadioAvailable()) return true;
2610 }
2611 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2612 return false;
2613 } finally {
2614 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002615 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002616 }
2617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002618 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002619 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 enforceModifyPermission();
2621
2622 final long identity = Binder.clearCallingIdentity();
2623 try {
2624 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2625 logv("Shutting down Phone " + i);
2626 shutdownRadioUsingPhoneId(i);
2627 }
2628 } finally {
2629 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002630 }
2631 }
2632
2633 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002634 Phone phone = PhoneFactory.getPhone(phoneId);
2635 if (phone != null && phone.isRadioAvailable()) {
2636 phone.shutdownRadio();
2637 }
2638 }
2639
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002641 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642
2643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2646 if (defaultPhone != null) {
2647 defaultPhone.setRadioPower(turnOn);
2648 return true;
2649 } else {
2650 loge("There's no default phone.");
2651 return false;
2652 }
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002655 }
Wink Saville36469e72014-06-11 15:17:00 -07002656 }
2657
Wink Savilleb564aae2014-10-23 10:18:09 -07002658 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660
2661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 final Phone phone = getPhone(subId);
2664 if (phone != null) {
2665 phone.setRadioPower(turnOn);
2666 return true;
2667 } else {
2668 return false;
2669 }
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673 }
2674
Wink Saville36469e72014-06-11 15:17:00 -07002675 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002676 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002677 public boolean enableDataConnectivity() {
2678 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679
2680 final long identity = Binder.clearCallingIdentity();
2681 try {
2682 int subId = mSubscriptionController.getDefaultDataSubId();
2683 final Phone phone = getPhone(subId);
2684 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002685 phone.getDataEnabledSettings().setDataEnabled(
2686 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 return true;
2688 } else {
2689 return false;
2690 }
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 }
2695
Wink Saville36469e72014-06-11 15:17:00 -07002696 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 public boolean disableDataConnectivity() {
2699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 int subId = mSubscriptionController.getDefaultDataSubId();
2704 final Phone phone = getPhone(subId);
2705 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002706 phone.getDataEnabledSettings().setDataEnabled(
2707 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708 return true;
2709 } else {
2710 return false;
2711 }
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 }
2716
Sanket Padawe356d7632015-06-22 14:03:32 -07002717 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002718 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 final Phone phone = getPhone(subId);
2722 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002723 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 } else {
2725 return false;
2726 }
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 }
2731
2732 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002733 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002734 }
2735
pkanwarae03a6b2016-11-06 20:37:09 -08002736 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 enforceCallPermission();
2738
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2742 return;
2743 }
2744 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2745 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2746 } finally {
2747 Binder.restoreCallingIdentity(identity);
2748 }
pkanwar32d516d2016-10-14 19:37:38 -07002749 };
2750
Wink Savilleb564aae2014-10-23 10:18:09 -07002751 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002752 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753
2754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2757 return false;
2758 }
2759 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2760 } finally {
2761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 }
2764
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002766 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002767 }
2768
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002769 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 Phone phone = PhoneFactory.getPhone(slotIndex);
2773 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2774 PhoneConstantConversions.convertCallState(phone.getState());
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
2777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779
Sanket Padawe356d7632015-06-22 14:03:32 -07002780 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002781 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002782 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2783 }
2784
2785 @Override
2786 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 final long identity = Binder.clearCallingIdentity();
2788 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002789 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790 if (phone != null) {
2791 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2792 } else {
2793 return PhoneConstantConversions.convertDataState(
2794 PhoneConstants.DataState.DISCONNECTED);
2795 }
2796 } finally {
2797 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 }
2800
Sanket Padawe356d7632015-06-22 14:03:32 -07002801 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002802 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002803 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2804 }
2805
2806 @Override
2807 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 final long identity = Binder.clearCallingIdentity();
2809 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002810 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 if (phone != null) {
2812 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2813 } else {
2814 return TelephonyManager.DATA_ACTIVITY_NONE;
2815 }
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
2821 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002822 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002823 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002824 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002825
2826 LocationAccessPolicy.LocationPermissionResult locationResult =
2827 LocationAccessPolicy.checkLocationPermission(mApp,
2828 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2829 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002830 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002831 .setCallingPid(Binder.getCallingPid())
2832 .setCallingUid(Binder.getCallingUid())
2833 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002834 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002835 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2836 .build());
2837 switch (locationResult) {
2838 case DENIED_HARD:
2839 throw new SecurityException("Not allowed to access cell location");
2840 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002841 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2842 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 }
2844
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002845 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846 final long identity = Binder.clearCallingIdentity();
2847 try {
2848 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002849 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002850 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 } finally {
2852 Binder.restoreCallingIdentity(identity);
2853 }
Svetoslav64fad262015-04-14 14:35:21 -07002854 }
2855
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856 @Override
Jack Yu01425032020-02-22 19:38:58 -08002857 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002858 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2859 // registered cell info, so return a NULL country instead.
2860 final long identity = Binder.clearCallingIdentity();
2861 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002862 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2863 // Get default phone in this case.
2864 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2865 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002866 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002867 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002868 if (phone == null) return "";
2869 ServiceStateTracker sst = phone.getServiceStateTracker();
2870 if (sst == null) return "";
2871 LocaleTracker lt = sst.getLocaleTracker();
2872 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002873 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002874 } finally {
2875 Binder.restoreCallingIdentity(identity);
2876 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002877 }
2878
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002879 /**
2880 * This method was removed due to potential issues caused by performing partial
2881 * updates of service state, and lack of a credible use case.
2882 *
2883 * This has the ability to break the telephony implementation by disabling notification of
2884 * changes in device connectivity. DO NOT USE THIS!
2885 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002886 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887 public void enableLocationUpdates() {
2888 mApp.enforceCallingOrSelfPermission(
2889 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
2891
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002892 /**
2893 * This method was removed due to potential issues caused by performing partial
2894 * updates of service state, and lack of a credible use case.
2895 *
2896 * This has the ability to break the telephony implementation by disabling notification of
2897 * changes in device connectivity. DO NOT USE THIS!
2898 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002899 @Override
2900 public void disableLocationUpdates() {
2901 mApp.enforceCallingOrSelfPermission(
2902 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002903 }
2904
2905 @Override
2906 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002907 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2908 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002909 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002910 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2911 throw new SecurityException(
2912 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2913 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002914
Jordan Liu1617b712019-07-10 15:06:26 -07002915 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2917 return null;
2918 }
Svetoslav64fad262015-04-14 14:35:21 -07002919
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002920 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002921
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002922 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002923 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924
Nathan Haroldf180aac2018-06-01 18:43:55 -07002925 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2926 for (CellInfo ci : info) {
2927 if (ci instanceof CellInfoGsm) {
2928 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2929 } else if (ci instanceof CellInfoWcdma) {
2930 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2931 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002933 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 }
2935
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002936 private List<CellInfo> getCachedCellInfo() {
2937 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2938 for (Phone phone : PhoneFactory.getPhones()) {
2939 List<CellInfo> info = phone.getAllCellInfo();
2940 if (info != null) cellInfos.addAll(info);
2941 }
2942 return cellInfos;
2943 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002944
2945 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002946 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002947 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002948 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002949
2950 LocationAccessPolicy.LocationPermissionResult locationResult =
2951 LocationAccessPolicy.checkLocationPermission(mApp,
2952 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2953 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002954 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002955 .setCallingPid(Binder.getCallingPid())
2956 .setCallingUid(Binder.getCallingUid())
2957 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002958 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002959 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2960 .build());
2961 switch (locationResult) {
2962 case DENIED_HARD:
2963 throw new SecurityException("Not allowed to access cell info");
2964 case DENIED_SOFT:
2965 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002966 }
2967
Nathan Haroldf096d982020-11-18 17:18:06 -08002968 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002969 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2970 return getCachedCellInfo();
2971 }
2972
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002973 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002974 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2978 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002979 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002980 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 if (info != null) cellInfos.addAll(info);
2982 }
2983 return cellInfos;
2984 } finally {
2985 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002986 }
2987 }
2988
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002989 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002990 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2991 String callingFeatureId) {
2992 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2993 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002994 }
2995
2996 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002997 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2998 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002999 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003000 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003001 }
3002
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003003 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3004 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003005 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003006 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003007
3008 LocationAccessPolicy.LocationPermissionResult locationResult =
3009 LocationAccessPolicy.checkLocationPermission(mApp,
3010 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3011 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003012 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003013 .setCallingPid(Binder.getCallingPid())
3014 .setCallingUid(Binder.getCallingUid())
3015 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07003016 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3017 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003018 .build());
3019 switch (locationResult) {
3020 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003021 if (TelephonyPermissions
3022 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07003023 // Safetynet logging for b/154934934
3024 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3025 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003026 throw new SecurityException("Not allowed to access cell info");
3027 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003028 if (TelephonyPermissions
3029 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07003030 // Safetynet logging for b/154934934
3031 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3032 }
Nathan Harold5320c422019-05-09 10:26:08 -07003033 try {
3034 cb.onCellInfo(new ArrayList<CellInfo>());
3035 } catch (RemoteException re) {
3036 // Drop without consequences
3037 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003038 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003039 }
3040
Nathan Harolda939a962019-05-09 10:13:47 -07003041
3042 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003043 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3044
3045 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3046 }
3047
3048 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003049 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003050 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003051 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052
3053 final long identity = Binder.clearCallingIdentity();
3054 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003055 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 }
3060
Shishir Agrawala9f32182016-04-12 12:00:16 -07003061 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003062 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003063 Phone phone = PhoneFactory.getPhone(slotIndex);
3064 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003065 return null;
3066 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003067 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003068 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003069 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003070 return null;
3071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 return phone.getImei();
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003079 }
3080
3081 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003082 public String getTypeAllocationCodeForSlot(int slotIndex) {
3083 Phone phone = PhoneFactory.getPhone(slotIndex);
3084 String tac = null;
3085 if (phone != null) {
3086 String imei = phone.getImei();
3087 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3088 }
3089 return tac;
3090 }
3091
3092 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003093 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003094 Phone phone = PhoneFactory.getPhone(slotIndex);
3095 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003096 return null;
3097 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003098
Jeff Davidson913390f2018-02-23 17:11:49 -08003099 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003100 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003101 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003102 return null;
3103 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003104
3105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 return phone.getMeid();
3108 } finally {
3109 Binder.restoreCallingIdentity(identity);
3110 }
Jack Yu2af8d712017-03-15 17:14:14 -07003111 }
3112
3113 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003114 public String getManufacturerCodeForSlot(int slotIndex) {
3115 Phone phone = PhoneFactory.getPhone(slotIndex);
3116 String manufacturerCode = null;
3117 if (phone != null) {
3118 String meid = phone.getMeid();
3119 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3120 }
3121 return manufacturerCode;
3122 }
3123
3124 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003125 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3126 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003127 Phone phone = PhoneFactory.getPhone(slotIndex);
3128 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003129 return null;
3130 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003131 int subId = phone.getSubId();
3132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003133 mApp, subId, callingPackage, callingFeatureId,
3134 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003135 return null;
3136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003137
3138 final long identity = Binder.clearCallingIdentity();
3139 try {
3140 return phone.getDeviceSvn();
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
3143 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003144 }
3145
fionaxu43304da2017-11-27 22:51:16 -08003146 @Override
3147 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148 final long identity = Binder.clearCallingIdentity();
3149 try {
3150 final Phone phone = getPhone(subId);
3151 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3152 } finally {
3153 Binder.restoreCallingIdentity(identity);
3154 }
fionaxu43304da2017-11-27 22:51:16 -08003155 }
3156
3157 @Override
3158 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003159 final long identity = Binder.clearCallingIdentity();
3160 try {
3161 final Phone phone = getPhone(subId);
3162 return phone == null ? null : phone.getCarrierName();
3163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
fionaxu43304da2017-11-27 22:51:16 -08003166 }
3167
calvinpanffe225e2018-11-01 19:43:06 +08003168 @Override
chen xu0026ca62019-03-06 15:28:50 -08003169 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003170 final long identity = Binder.clearCallingIdentity();
3171 try {
3172 final Phone phone = getPhone(subId);
3173 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003174 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003175 } finally {
3176 Binder.restoreCallingIdentity(identity);
3177 }
3178 }
3179
3180 @Override
chen xu0026ca62019-03-06 15:28:50 -08003181 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003185 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
3189 }
3190
chen xu651eec72018-11-11 19:03:44 -08003191 @Override
chen xu864e11c2018-12-06 22:10:03 -08003192 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3193 if (!isSubscriptionMccMnc) {
3194 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3195 }
chen xu651eec72018-11-11 19:03:44 -08003196 final Phone phone = PhoneFactory.getPhone(slotIndex);
3197 if (phone == null) {
3198 return TelephonyManager.UNKNOWN_CARRIER_ID;
3199 }
3200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3203 } finally {
3204 Binder.restoreCallingIdentity(identity);
3205 }
3206 }
3207
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003208 //
3209 // Internal helper methods.
3210 //
3211
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003212 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3214 *
3215 * @throws SecurityException if the caller does not have the required permission
3216 */
3217 private void enforceModifyPermission() {
3218 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3219 }
3220
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003221 /**
3222 * Make sure the caller is system.
3223 *
3224 * @throws SecurityException if the caller is not system.
3225 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003226 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003227 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3228 throw new SecurityException("Caller must be system");
3229 }
3230 }
3231
Shuo Qianf2b2df42019-11-13 17:43:31 -08003232 private void enforceActiveEmergencySessionPermission() {
3233 mApp.enforceCallingOrSelfPermission(
3234 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3235 }
3236
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003237 /**
3238 * Make sure the caller has the CALL_PHONE permission.
3239 *
3240 * @throws SecurityException if the caller does not have the required permission
3241 */
3242 private void enforceCallPermission() {
3243 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3244 }
3245
paulhu423b5f22019-08-23 19:17:33 +08003246 private void enforceSettingsPermission() {
3247 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003248 }
3249
Michele Berionned9fbae52020-11-13 02:36:59 +00003250 private void enforceRebootPermission() {
3251 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3252 }
3253
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 private String createTelUrl(String number) {
3255 if (TextUtils.isEmpty(number)) {
3256 return null;
3257 }
3258
Jake Hambye994d462014-02-03 13:10:13 -08003259 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003260 }
3261
Ihab Awadf9e92732013-12-05 18:02:52 -08003262 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3264 }
3265
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003266 private static void logv(String msg) {
3267 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3268 }
3269
Ihab Awadf9e92732013-12-05 18:02:52 -08003270 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003271 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3272 }
3273
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003274 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003276 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003277 }
3278
Sanket Padawe356d7632015-06-22 14:03:32 -07003279 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003280 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281 final long identity = Binder.clearCallingIdentity();
3282 try {
3283 final Phone phone = PhoneFactory.getPhone(slotIndex);
3284 if (phone == null) {
3285 return PhoneConstants.PHONE_TYPE_NONE;
3286 } else {
3287 return phone.getPhoneType();
3288 }
3289 } finally {
3290 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003292 }
3293
3294 /**
3295 * Returns the CDMA ERI icon index to display
3296 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003297 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003298 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3299 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3300 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003301 }
3302
Sanket Padawe356d7632015-06-22 14:03:32 -07003303 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003304 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3305 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003307 mApp, subId, callingPackage, callingFeatureId,
3308 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003309 return -1;
3310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003311
3312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 final Phone phone = getPhone(subId);
3315 if (phone != null) {
3316 return phone.getCdmaEriIconIndex();
3317 } else {
3318 return -1;
3319 }
3320 } finally {
3321 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003323 }
3324
3325 /**
3326 * Returns the CDMA ERI icon mode,
3327 * 0 - ON
3328 * 1 - FLASHING
3329 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003330 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003331 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3332 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3333 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003334 }
3335
Sanket Padawe356d7632015-06-22 14:03:32 -07003336 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003337 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3338 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003339 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003340 mApp, subId, callingPackage, callingFeatureId,
3341 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003342 return -1;
3343 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 final Phone phone = getPhone(subId);
3348 if (phone != null) {
3349 return phone.getCdmaEriIconMode();
3350 } else {
3351 return -1;
3352 }
3353 } finally {
3354 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003356 }
3357
3358 /**
3359 * Returns the CDMA ERI text,
3360 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003361 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003362 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3363 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3364 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003365 }
3366
Sanket Padawe356d7632015-06-22 14:03:32 -07003367 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003368 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3369 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003371 mApp, subId, callingPackage, callingFeatureId,
3372 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003373 return null;
3374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003375
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 final Phone phone = getPhone(subId);
3379 if (phone != null) {
3380 return phone.getCdmaEriText();
3381 } else {
3382 return null;
3383 }
3384 } finally {
3385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003387 }
3388
3389 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003390 * Returns the CDMA MDN.
3391 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003392 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003393 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3395 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003396
3397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003400 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003401 return phone.getLine1Number();
3402 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003403 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 return null;
3405 }
3406 } finally {
3407 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003408 }
3409 }
3410
3411 /**
3412 * Returns the CDMA MIN.
3413 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003414 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003415 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3417 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003418
3419 final long identity = Binder.clearCallingIdentity();
3420 try {
3421 final Phone phone = getPhone(subId);
3422 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3423 return phone.getCdmaMin();
3424 } else {
3425 return null;
3426 }
3427 } finally {
3428 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003429 }
3430 }
3431
Hall Liud892bec2018-11-30 14:51:45 -08003432 @Override
3433 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3434 INumberVerificationCallback callback, String callingPackage) {
3435 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3436 != PERMISSION_GRANTED) {
3437 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3438 }
3439 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3440
3441 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3442 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003443 throw new SecurityException("Calling package must be configured in the device config: "
3444 + "calling package: " + callingPackage
3445 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003446 }
3447
3448 if (range == null) {
3449 throw new NullPointerException("Range must be non-null");
3450 }
3451
3452 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003453 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003454
3455 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3456 }
3457
Junda Liuca05d5d2014-08-14 22:36:34 -07003458 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003459 * Returns true if CDMA provisioning needs to run.
3460 */
3461 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462 final long identity = Binder.clearCallingIdentity();
3463 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003468 }
3469
3470 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003471 * Sets the voice mail number of a given subId.
3472 */
3473 @Override
3474 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003475 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3476 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003477
3478 final long identity = Binder.clearCallingIdentity();
3479 try {
3480 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3481 new Pair<String, String>(alphaTag, number), new Integer(subId));
3482 return success;
3483 } finally {
3484 Binder.restoreCallingIdentity(identity);
3485 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003486 }
3487
Ta-wei Yen87c49842016-05-13 21:19:52 -07003488 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003489 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3490 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003491 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3492 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003493 if (!TextUtils.equals(callingPackage, systemDialer)) {
3494 throw new SecurityException("caller must be system dialer");
3495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003496
3497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3500 if (phoneAccountHandle == null) {
3501 return null;
3502 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003503 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003504 } finally {
3505 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003506 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003507 }
3508
3509 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003510 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3511 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003512 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003513 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003514 mApp, subId, callingPackage, callingFeatureId,
3515 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003516 return null;
3517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003518
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003519 final long identity = Binder.clearCallingIdentity();
3520 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003521 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003522 } finally {
3523 Binder.restoreCallingIdentity(identity);
3524 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003525 }
3526
3527 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003528 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3529 VisualVoicemailSmsFilterSettings settings) {
3530 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003531
3532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003535 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536 } finally {
3537 Binder.restoreCallingIdentity(identity);
3538 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003539 }
3540
3541 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003542 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3543 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003548 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549 } finally {
3550 Binder.restoreCallingIdentity(identity);
3551 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003552 }
3553
3554 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003555 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3556 String callingPackage, int subId) {
3557 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003558
3559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003562 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003563 } finally {
3564 Binder.restoreCallingIdentity(identity);
3565 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003566 }
3567
3568 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003569 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571
3572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003575 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576 } finally {
3577 Binder.restoreCallingIdentity(identity);
3578 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003579 }
3580
3581 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003582 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3583 String callingAttributionTag, int subId, String number, int port, String text,
3584 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003586 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003587 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003588 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003589 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3590 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003591 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003592
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003593 /**
fionaxu0152e512016-11-14 13:36:14 -08003594 * Sets the voice activation state of a given subId.
3595 */
3596 @Override
3597 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3599 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003600
3601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 final Phone phone = getPhone(subId);
3604 if (phone != null) {
3605 phone.setVoiceActivationState(activationState);
3606 } else {
3607 loge("setVoiceActivationState fails with invalid subId: " + subId);
3608 }
3609 } finally {
3610 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003611 }
3612 }
3613
3614 /**
3615 * Sets the data activation state of a given subId.
3616 */
3617 @Override
3618 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3620 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621
3622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 final Phone phone = getPhone(subId);
3625 if (phone != null) {
3626 phone.setDataActivationState(activationState);
3627 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003628 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003632 }
3633 }
3634
3635 /**
3636 * Returns the voice activation state of a given subId.
3637 */
3638 @Override
3639 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003640 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003641
fionaxu0152e512016-11-14 13:36:14 -08003642 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 if (phone != null) {
3646 return phone.getVoiceActivationState();
3647 } else {
3648 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3649 }
3650 } finally {
3651 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003652 }
3653 }
3654
3655 /**
3656 * Returns the data activation state of a given subId.
3657 */
3658 @Override
3659 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003660 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661
fionaxu0152e512016-11-14 13:36:14 -08003662 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 if (phone != null) {
3666 return phone.getDataActivationState();
3667 } else {
3668 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3669 }
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003672 }
3673 }
3674
3675 /**
Wink Saville36469e72014-06-11 15:17:00 -07003676 * Returns the unread count of voicemails for a subId
3677 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003678 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003679 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3680 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003681 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003682 mApp, subId, callingPackage, callingFeatureId,
3683 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003684 return 0;
3685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 final Phone phone = getPhone(subId);
3689 if (phone != null) {
3690 return phone.getVoiceMessageCount();
3691 } else {
3692 return 0;
3693 }
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003697 }
3698
3699 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003700 * returns true, if the device is in a state where both voice and data
3701 * are supported simultaneously. This can change based on location or network condition.
3702 */
3703 @Override
3704 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 final Phone phone = getPhone(subId);
3708 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3709 } finally {
3710 Binder.restoreCallingIdentity(identity);
3711 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003712 }
3713
3714 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003715 * Send the dialer code if called from the current default dialer or the caller has
3716 * carrier privilege.
3717 * @param inputCode The dialer code to send
3718 */
3719 @Override
3720 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003721 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003723 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3724 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003725 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003726 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003727 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729
3730 final long identity = Binder.clearCallingIdentity();
3731 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003732 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733 } finally {
3734 Binder.restoreCallingIdentity(identity);
3735 }
fionaxu235cc5e2017-03-06 22:25:57 -08003736 }
3737
Pengquan Menga1bb6272018-09-06 09:59:22 -07003738 @Override
3739 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003740 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07003741 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003742 mApp, subId, "getNetworkSelectionMode");
3743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 if (!isActiveSubscription(subId)) {
3746 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3747 }
3748 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3749 } finally {
3750 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003751 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003752 }
3753
Brad Ebinger35c841c2018-10-01 10:40:55 -07003754 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003755 public boolean isInEmergencySmsMode() {
3756 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3757 final long identity = Binder.clearCallingIdentity();
3758 try {
3759 for (Phone phone : PhoneFactory.getPhones()) {
3760 if (phone.isInEmergencySmsMode()) {
3761 return true;
3762 }
3763 }
3764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
3767 return false;
3768 }
3769
shilu366312e2019-12-17 09:28:10 -08003770 /**
3771 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3772 * @param subId The subscription to use to check the configuration.
3773 * @param c The callback that will be used to send the result.
3774 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003775 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003776 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3777 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003778 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003779 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003780
Brad Ebinger77b832e2019-10-17 17:03:22 -07003781 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3782 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3783 "IMS not available on device.");
3784 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003785 final long token = Binder.clearCallingIdentity();
3786 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003787 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003788 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003789 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003790 } catch (ImsException e) {
3791 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003792 } finally {
3793 Binder.restoreCallingIdentity(token);
3794 }
3795 }
3796
shilu366312e2019-12-17 09:28:10 -08003797 /**
3798 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3799 * @param subId The subscription to use to check the configuration.
3800 * @param c The callback that will be used to send the result.
3801 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003802 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003803 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003804 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003805 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003806 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3807 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3808 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003809 final long token = Binder.clearCallingIdentity();
3810 try {
3811 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3812 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3813 .removeRegistrationCallbackForSubscription(c, subId);
3814 } catch (ImsException e) {
3815 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3816 + "is inactive, ignoring unregister.");
3817 // If the subscription is no longer active, just return, since the callback
3818 // will already have been removed internally.
3819 } finally {
3820 Binder.restoreCallingIdentity(token);
3821 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003822 }
3823
Brad Ebinger774ba362019-10-22 17:36:18 -07003824 /**
3825 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3826 */
3827 @Override
3828 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3829 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3830 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3831 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3832 "IMS not available on device.");
3833 }
3834 final long token = Binder.clearCallingIdentity();
3835 try {
3836 Phone phone = getPhone(subId);
3837 if (phone == null) {
3838 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3839 + subId + "'");
3840 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3841 }
3842 phone.getImsRegistrationState(regState -> {
3843 try {
3844 consumer.accept((regState == null)
3845 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3846 } catch (RemoteException e) {
3847 // Ignore if the remote process is no longer available to call back.
3848 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3849 }
3850 });
3851 } finally {
3852 Binder.restoreCallingIdentity(token);
3853 }
3854 }
3855
3856 /**
3857 * Get the transport type for the IMS service registration state.
3858 */
3859 @Override
3860 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003861 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003862 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003863 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3864 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3865 "IMS not available on device.");
3866 }
3867 final long token = Binder.clearCallingIdentity();
3868 try {
3869 Phone phone = getPhone(subId);
3870 if (phone == null) {
3871 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3872 + subId + "'");
3873 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3874 }
3875 phone.getImsRegistrationTech(regTech -> {
3876 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3877 int regTechConverted = (regTech == null)
3878 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3879 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3880 regTechConverted);
3881 try {
3882 consumer.accept(regTechConverted);
3883 } catch (RemoteException e) {
3884 // Ignore if the remote process is no longer available to call back.
3885 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3886 }
3887 });
3888 } finally {
3889 Binder.restoreCallingIdentity(token);
3890 }
3891 }
3892
shilu366312e2019-12-17 09:28:10 -08003893 /**
3894 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3895 * @param subId The subscription to use to check the configuration.
3896 * @param c The callback that will be used to send the result.
3897 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003899 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3900 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003901 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003902 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003903 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3904 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3905 "IMS not available on device.");
3906 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3908 final long token = Binder.clearCallingIdentity();
3909 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003910 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003911 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003912 } catch (ImsException e) {
3913 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 } finally {
3915 Binder.restoreCallingIdentity(token);
3916 }
3917 }
3918
shilu366312e2019-12-17 09:28:10 -08003919 /**
3920 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3921 * @param subId The subscription to use to check the configuration.
3922 * @param c The callback that will be used to send the result.
3923 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003924 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003925 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003926 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003927 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003928 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3929 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3930 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003931
3932 final long token = Binder.clearCallingIdentity();
3933 try {
3934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3935 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003936 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003937 } catch (ImsException e) {
3938 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3939 + "is inactive, ignoring unregister.");
3940 // If the subscription is no longer active, just return, since the callback
3941 // will already have been removed internally.
3942 } finally {
3943 Binder.restoreCallingIdentity(token);
3944 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 }
3946
3947 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003948 public boolean isCapable(int subId, int capability, int regTech) {
3949 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003950 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3951 final long token = Binder.clearCallingIdentity();
3952 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003953 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003955 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003956 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3957 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003958 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003959 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3960 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 } finally {
3962 Binder.restoreCallingIdentity(token);
3963 }
3964 }
3965
3966 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003967 public boolean isAvailable(int subId, int capability, int regTech) {
3968 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 final long token = Binder.clearCallingIdentity();
3970 try {
3971 Phone phone = getPhone(subId);
3972 if (phone == null) return false;
3973 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003974 } catch (com.android.ims.ImsException e) {
3975 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3976 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 } finally {
3978 Binder.restoreCallingIdentity(token);
3979 }
3980 }
3981
Brad Ebinger77b832e2019-10-17 17:03:22 -07003982 /**
3983 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3984 * subscription.
3985 * @param subId The subscription to use to check the configuration.
3986 * @param callback The callback that will be used to send the result.
3987 * @param capability The MmTelFeature capability that will be used to send the result.
3988 * @param transportType The transport type of the MmTelFeature capability.
3989 */
3990 @Override
3991 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3992 int transportType) {
3993 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3994 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3995 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3996 "IMS not available on device.");
3997 }
3998 final long token = Binder.clearCallingIdentity();
3999 try {
4000 int slotId = getSlotIndex(subId);
4001 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4002 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4003 + subId + "'");
4004 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4005 }
4006 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4007 transportType, aBoolean -> {
4008 try {
4009 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4010 } catch (RemoteException e) {
4011 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4012 + "running. Ignore");
4013 }
4014 });
4015 } finally {
4016 Binder.restoreCallingIdentity(token);
4017 }
4018 }
4019
shilu366312e2019-12-17 09:28:10 -08004020 /**
4021 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4022 * @param subId The subscription to use to check the configuration.
4023 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 @Override
4025 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004026 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004027 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004028
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4030 final long token = Binder.clearCallingIdentity();
4031 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004032 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004033 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004034 } catch (ImsException e) {
4035 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 } finally {
4037 Binder.restoreCallingIdentity(token);
4038 }
4039 }
4040
4041 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004042 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004044 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004048 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004050 } catch (ImsException e) {
4051 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 } finally {
4053 Binder.restoreCallingIdentity(identity);
4054 }
4055 }
4056
shilu366312e2019-12-17 09:28:10 -08004057 /**
4058 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4059 * @param subId The subscription to use to check the configuration.
4060 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004062 public boolean isVtSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004063 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004064 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004065 final long identity = Binder.clearCallingIdentity();
4066 try {
4067 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004068 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4069 } catch (ImsException e) {
4070 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
4074 }
4075
4076 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004077 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004079 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004083 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004084 } catch (ImsException e) {
4085 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
4089 }
4090
shilu366312e2019-12-17 09:28:10 -08004091 /**
4092 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4093 * @param subId The subscription to use to check the configuration.
4094 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004095 @Override
4096 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004097 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004098 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004099 final long identity = Binder.clearCallingIdentity();
4100 try {
4101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004102 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004104 } catch (ImsException e) {
4105 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 } finally {
4107 Binder.restoreCallingIdentity(identity);
4108 }
4109 }
4110
4111 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004112 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004114 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004118 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004119 } catch (ImsException e) {
4120 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 } finally {
4122 Binder.restoreCallingIdentity(identity);
4123 }
4124 }
4125
shilu366312e2019-12-17 09:28:10 -08004126 /**
4127 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4128 * @param subId The subscription to use to check the configuration.
4129 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 @Override
4131 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004132 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004133 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 final long identity = Binder.clearCallingIdentity();
4135 try {
4136 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004137 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004139 } catch (ImsException e) {
4140 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 } finally {
4142 Binder.restoreCallingIdentity(identity);
4143 }
4144 }
4145
4146 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004147 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004149 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004153 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004155 } catch (ImsException e) {
4156 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
4160 }
4161
4162 @Override
4163 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4165 "setVoWiFiNonPersistent");
4166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004169 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004170 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004171 } catch (ImsException e) {
4172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 } finally {
4174 Binder.restoreCallingIdentity(identity);
4175 }
4176 }
4177
shilu366312e2019-12-17 09:28:10 -08004178 /**
4179 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4180 * @param subId The subscription to use to check the configuration.
4181 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 @Override
4183 public int getVoWiFiModeSetting(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004184 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004185 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004189 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004191 } catch (ImsException e) {
4192 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 } finally {
4194 Binder.restoreCallingIdentity(identity);
4195 }
4196 }
4197
4198 @Override
4199 public void setVoWiFiModeSetting(int subId, int mode) {
4200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4201 "setVoWiFiModeSetting");
4202 final long identity = Binder.clearCallingIdentity();
4203 try {
4204 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004205 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004207 } catch (ImsException e) {
4208 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 } finally {
4210 Binder.restoreCallingIdentity(identity);
4211 }
4212 }
4213
4214 @Override
4215 public int getVoWiFiRoamingModeSetting(int subId) {
4216 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4217 final long identity = Binder.clearCallingIdentity();
4218 try {
4219 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004220 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004222 } catch (ImsException e) {
4223 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 } finally {
4225 Binder.restoreCallingIdentity(identity);
4226 }
4227 }
4228
4229 @Override
4230 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4232 "setVoWiFiRoamingModeSetting");
4233 final long identity = Binder.clearCallingIdentity();
4234 try {
4235 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004236 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004237 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004238 } catch (ImsException e) {
4239 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 } finally {
4241 Binder.restoreCallingIdentity(identity);
4242 }
4243 }
4244
4245 @Override
4246 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4248 "setRttCapabilityEnabled");
4249 final long identity = Binder.clearCallingIdentity();
4250 try {
4251 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004252 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4253 } catch (ImsException e) {
4254 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
4258 }
4259
shilu366312e2019-12-17 09:28:10 -08004260 /**
4261 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4262 * @param subId The subscription to use to check the configuration.
4263 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 @Override
4265 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004266 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004267 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 final long identity = Binder.clearCallingIdentity();
4269 try {
4270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004271 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004273 } catch (ImsException e) {
4274 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 } finally {
4276 Binder.restoreCallingIdentity(identity);
4277 }
4278 }
4279
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004280 @Override
4281 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4282 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4283 final long identity = Binder.clearCallingIdentity();
4284 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004285 if (!isImsAvailableOnDevice()) {
4286 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4287 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004288 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004289 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004290 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004291 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004292 } catch (ImsException e) {
4293 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004294 } finally {
4295 Binder.restoreCallingIdentity(identity);
4296 }
4297 }
4298
4299 @Override
4300 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4301 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4302 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004303 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4304 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4305 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004306 try {
4307 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004308 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004309 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004310 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004311 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4312 + "is inactive, ignoring unregister.");
4313 // If the subscription is no longer active, just return, since the callback will already
4314 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
4318 }
4319
allenwtsu99c623b2020-01-03 18:24:23 +08004320
4321 private void checkModifyPhoneStatePermission(int subId, String message) {
4322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4323 message);
4324 }
4325
4326 private boolean isImsProvisioningRequired(int subId, int capability,
4327 boolean isMmtelCapability) {
4328 Phone phone = getPhone(subId);
4329 if (phone == null) {
4330 loge("phone instance null for subid " + subId);
4331 return false;
4332 }
4333 if (isMmtelCapability) {
4334 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4335 return false;
4336 }
4337 } else {
4338 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4339 return false;
4340 }
4341 }
4342 return true;
4343 }
4344
4345 @Override
4346 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4347 boolean isProvisioned) {
4348 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4349
4350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4353 if (!isImsProvisioningRequired(subId, capability, false)) {
4354 return;
4355 }
4356
4357 // this capability requires provisioning, route to the correct API.
4358 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4359 switch (capability) {
4360 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4361 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4362 ims.setEabProvisioned(isProvisioned);
4363 break;
4364 default: {
4365 throw new IllegalArgumentException("Tried to set provisioning for "
4366 + "rcs capability '" + capability + "', which does not require "
4367 + "provisioning.");
4368 }
4369 }
4370 } finally {
4371 Binder.restoreCallingIdentity(identity);
4372 }
4373
4374 }
4375
4376
4377 @Override
4378 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4379 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4380 final long identity = Binder.clearCallingIdentity();
4381 try {
4382 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4383 if (!isImsProvisioningRequired(subId, capability, false)) {
4384 return true;
4385 }
4386
4387 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4388 switch (capability) {
4389 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4390 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4391 return ims.isEabProvisionedOnDevice();
4392
4393 default: {
4394 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4395 + "capability '" + capability + "', which does not require "
4396 + "provisioning.");
4397 }
4398 }
4399
4400 } finally {
4401 Binder.restoreCallingIdentity(identity);
4402 }
4403 }
4404
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004405 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004406 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4407 boolean isProvisioned) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004408 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4409 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004410 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4411 }
allenwtsu99c623b2020-01-03 18:24:23 +08004412 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004413 final long identity = Binder.clearCallingIdentity();
4414 try {
4415 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004416 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004417 return;
4418 }
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004419 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4420 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4421 loge("setImsProvisioningStatusForCapability: called for technology that does "
4422 + "not support provisioning - " + tech);
4423 return;
4424 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004425
4426 // this capability requires provisioning, route to the correct API.
4427 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4428 switch (capability) {
4429 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4430 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4431 ims.setVolteProvisioned(isProvisioned);
4432 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4433 ims.setWfcProvisioned(isProvisioned);
4434 }
4435 break;
4436 }
4437 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4438 // There is currently no difference in VT provisioning type.
4439 ims.setVtProvisioned(isProvisioned);
4440 break;
4441 }
4442 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4443 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4444 // change the capability of the feature instead if needed.
4445 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4446 == isProvisioned) {
4447 // No change in provisioning.
4448 return;
4449 }
4450 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4451 try {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004452 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004453 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004454 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4455 + ", Exception" + e.getMessage());
4456 }
4457 break;
4458 }
4459 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004460 throw new IllegalArgumentException("Tried to set provisioning for "
4461 + "MmTel capability '" + capability + "', which does not require "
4462 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004463 }
4464 }
4465
4466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
4471 @Override
4472 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004473 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4474 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004475 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4476 }
4477 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4478 final long identity = Binder.clearCallingIdentity();
4479 try {
4480 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004481 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004482 return true;
4483 }
4484
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004485 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4486 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4487 loge("getImsProvisioningStatusForCapability: called for technology that does "
4488 + "not support provisioning - " + tech);
4489 return true;
4490 }
4491
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004492 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4493 switch (capability) {
4494 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4495 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4496 return ims.isVolteProvisionedOnDevice();
4497 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4498 return ims.isWfcProvisionedOnDevice();
4499 }
4500 // This should never happen, since we are checking tech above to make sure it
4501 // is either LTE or IWLAN.
4502 throw new IllegalArgumentException("Invalid radio technology for voice "
4503 + "capability.");
4504 }
4505 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4506 // There is currently no difference in VT provisioning type.
4507 return ims.isVtProvisionedOnDevice();
4508 }
4509 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4510 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4511 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4512 }
4513 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004514 throw new IllegalArgumentException(
4515 "Tried to get provisioning for MmTel capability '" + capability
4516 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004517 }
4518 }
4519
4520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
4523 }
4524
4525 @Override
4526 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4527 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4528 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4529 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4530 }
4531 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4532 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4533 return (provisionedBits & capability) > 0;
4534 }
4535
4536 @Override
4537 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4538 boolean isProvisioned) {
4539 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4540 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4541 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4542 }
4543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4544 "setProvisioningStatusForCapability");
4545 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4546 // If the current provisioning status for capability already matches isProvisioned,
4547 // do nothing.
4548 if (((provisionedBits & capability) > 0) == isProvisioned) {
4549 return;
4550 }
4551 if (isProvisioned) {
4552 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4553 } else {
4554 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4555 }
4556 }
4557
4558 /**
4559 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4560 * technology. The bitfield should mirror the bitfield defined by
4561 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4562 */
4563 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4564 String key = getMmTelProvisioningKey(subId, tech);
4565 // Default is no capabilities are provisioned.
4566 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4567 }
4568
4569 /**
4570 * Sets the MmTel capability provisioning bitfield (defined by
4571 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4572 * technology specified.
4573 *
4574 * Note: This is a synchronous command and should not be called on UI thread.
4575 */
4576 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4577 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4578 String key = getMmTelProvisioningKey(subId, tech);
4579 editor.putInt(key, newField);
4580 editor.commit();
4581 }
4582
4583 private static String getMmTelProvisioningKey(int subId, int tech) {
4584 // resulting key is provision_ims_mmtel_{subId}_{tech}
4585 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4586 }
4587
4588 /**
4589 * Query CarrierConfig to see if the specified capability requires provisioning for the
4590 * carrier associated with the subscription id.
4591 */
4592 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4593 int capability) {
4594 CarrierConfigManager configManager = new CarrierConfigManager(context);
4595 PersistableBundle c = configManager.getConfigForSubId(subId);
4596 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004597 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004598 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4599 false);
4600 boolean requireVoiceVtProvisioning = c.getBoolean(
4601 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4602
4603 // First check to make sure that the capability requires provisioning.
4604 switch (capability) {
4605 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4606 // intentional fallthrough
4607 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4608 if (requireVoiceVtProvisioning) {
4609 // Voice and Video requires provisioning
4610 return true;
4611 }
4612 break;
4613 }
4614 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4615 if (requireUtProvisioning) {
4616 // UT requires provisioning
4617 return true;
4618 }
4619 break;
4620 }
4621 }
4622 return false;
4623 }
4624
allenwtsu99c623b2020-01-03 18:24:23 +08004625 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4626 int capability) {
4627 CarrierConfigManager configManager = new CarrierConfigManager(context);
4628 PersistableBundle c = configManager.getConfigForSubId(subId);
4629
4630 boolean requireRcsProvisioning = c.getBoolean(
4631 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4632
4633 // First check to make sure that the capability requires provisioning.
4634 switch (capability) {
4635 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4636 // intentional fallthrough
4637 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4638 if (requireRcsProvisioning) {
4639 // OPTION or PRESENCE requires provisioning
4640 return true;
4641 }
4642 break;
4643 }
4644 }
4645 return false;
4646 }
4647
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004648 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004649 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004650 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4651 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4652 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004653 enforceReadPrivilegedPermission("getImsProvisioningInt");
4654 final long identity = Binder.clearCallingIdentity();
4655 try {
4656 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 int slotId = getSlotIndex(subId);
4658 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4659 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4660 + subId + "' for key:" + key);
4661 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4662 }
calvinpan9cfff472021-02-08 19:59:36 +08004663 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004664 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4666 + subId + "' for key:" + key);
4667 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004668 } finally {
4669 Binder.restoreCallingIdentity(identity);
4670 }
4671 }
4672
4673 @Override
4674 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004675 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4676 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4677 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004678 enforceReadPrivilegedPermission("getImsProvisioningString");
4679 final long identity = Binder.clearCallingIdentity();
4680 try {
4681 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004682 int slotId = getSlotIndex(subId);
4683 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4684 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4685 + subId + "' for key:" + key);
4686 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4687 }
calvinpan9cfff472021-02-08 19:59:36 +08004688 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004689 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004690 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4691 + subId + "' for key:" + key);
4692 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
4696 }
4697
4698 @Override
4699 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004700 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4701 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4702 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4704 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 int slotId = getSlotIndex(subId);
4709 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4710 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4711 + subId + "' for key:" + key);
4712 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4713 }
calvinpan9cfff472021-02-08 19:59:36 +08004714 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4715 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004716 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004717 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004718 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004719 } finally {
4720 Binder.restoreCallingIdentity(identity);
4721 }
4722 }
4723
4724 @Override
4725 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4727 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4728 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4730 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004731 final long identity = Binder.clearCallingIdentity();
4732 try {
4733 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 int slotId = getSlotIndex(subId);
4735 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4736 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4737 + subId + "' for key:" + key);
4738 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4739 }
calvinpan9cfff472021-02-08 19:59:36 +08004740 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4741 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004742 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004743 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004744 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004745 } finally {
4746 Binder.restoreCallingIdentity(identity);
4747 }
4748 }
4749
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004750 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004751 int slotId = SubscriptionManager.getSlotIndex(subId);
4752 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004753 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4754 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004755 }
4756 return slotId;
4757 }
4758
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004759 private int getSlotIndex(int subId) {
4760 int slotId = SubscriptionManager.getSlotIndex(subId);
4761 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4762 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4763 }
4764 return slotId;
4765 }
4766
Wink Saville36469e72014-06-11 15:17:00 -07004767 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004768 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004769 */
4770 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004771 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4772 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004773 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004774 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004775 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004776 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004777 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004778 mApp, subId, callingPackage, callingFeatureId,
4779 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004780 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4781 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 final long identity = Binder.clearCallingIdentity();
4784 try {
4785 final Phone phone = getPhone(subId);
4786 if (phone != null) {
4787 return phone.getServiceState().getDataNetworkType();
4788 } else {
4789 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4790 }
4791 } finally {
4792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004794 }
4795
4796 /**
4797 * Returns the data network type
4798 */
4799 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004800 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004801 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4802 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004803 }
4804
4805 /**
4806 * Returns the data network type for a subId
4807 */
4808 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004809 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4810 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004812 mApp, subId, callingPackage, callingFeatureId,
4813 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004814 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4815 }
4816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 final long identity = Binder.clearCallingIdentity();
4818 try {
4819 final Phone phone = getPhone(subId);
4820 if (phone != null) {
4821 return phone.getServiceState().getDataNetworkType();
4822 } else {
4823 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4824 }
4825 } finally {
4826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004828 }
4829
4830 /**
Wink Saville36469e72014-06-11 15:17:00 -07004831 * Returns the Voice network type for a subId
4832 */
4833 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004834 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4835 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004836 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004837 mApp, subId, callingPackage, callingFeatureId,
4838 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004839 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4840 }
4841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 final long identity = Binder.clearCallingIdentity();
4843 try {
4844 final Phone phone = getPhone(subId);
4845 if (phone != null) {
4846 return phone.getServiceState().getVoiceNetworkType();
4847 } else {
4848 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4849 }
4850 } finally {
4851 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004852 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004853 }
4854
4855 /**
4856 * @return true if a ICC card is present
4857 */
4858 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004859 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004860 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4861 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004862 }
4863
4864 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004865 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004866 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004867 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004868 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869 final long identity = Binder.clearCallingIdentity();
4870 try {
4871 final Phone phone = PhoneFactory.getPhone(slotIndex);
4872 if (phone != null) {
4873 return phone.getIccCard().hasIccCard();
4874 } else {
4875 return false;
4876 }
4877 } finally {
4878 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004879 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004880 }
4881
4882 /**
4883 * Return if the current radio is LTE on CDMA. This
4884 * is a tri-state return value as for a period of time
4885 * the mode may be unknown.
4886 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004887 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004888 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004889 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004890 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004891 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004892 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4893 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4894 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004895 }
4896
Sanket Padawe356d7632015-06-22 14:03:32 -07004897 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004898 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4899 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004900 try {
4901 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4902 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004903 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4904 }
4905
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 final Phone phone = getPhone(subId);
4909 if (phone == null) {
4910 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4911 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004912 return TelephonyProperties.lte_on_cdma_device()
4913 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 }
4915 } finally {
4916 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004917 }
Wink Saville36469e72014-06-11 15:17:00 -07004918 }
4919
Wink Saville36469e72014-06-11 15:17:00 -07004920 /**
4921 * {@hide}
4922 * Returns Default subId, 0 in the case of single standby.
4923 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004924 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004925 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004926 }
4927
Shishir Agrawala9f32182016-04-12 12:00:16 -07004928 private int getSlotForDefaultSubscription() {
4929 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4930 }
4931
Wink Savilleb564aae2014-10-23 10:18:09 -07004932 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004933 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004934 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004935
Pengquan Menge92a50d2018-09-21 15:54:48 -07004936 private boolean isActiveSubscription(int subId) {
4937 return mSubscriptionController.isActiveSubId(subId);
4938 }
4939
Ihab Awadf2177b72013-11-25 13:33:23 -08004940 /**
4941 * @see android.telephony.TelephonyManager.WifiCallingChoices
4942 */
4943 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 final long identity = Binder.clearCallingIdentity();
4945 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004946 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4948 getWhenToMakeWifiCallsDefaultPreference());
4949 } finally {
4950 Binder.restoreCallingIdentity(identity);
4951 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004952 }
4953
4954 /**
4955 * @see android.telephony.TelephonyManager.WifiCallingChoices
4956 */
4957 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004961 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4963 } finally {
4964 Binder.restoreCallingIdentity(identity);
4965 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004966 }
4967
Sailesh Nepald1e68152013-12-12 19:08:02 -08004968 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004969 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004970 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004971 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004972
Jordan Liu4c733742019-02-28 12:03:40 -08004973 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4974 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4975 if (phoneId == -1) {
4976 throw new IllegalArgumentException("Given slot index: " + slotIndex
4977 + " does not correspond to an active phone");
4978 }
4979 return PhoneFactory.getPhone(phoneId);
4980 }
4981
Shishir Agrawal566b7612013-10-28 14:41:00 -07004982 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004983 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4984 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4986 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004987 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004988 if (DBG) {
4989 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4990 }
4991 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4992 p2);
4993 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004994
Jordan Liu4c733742019-02-28 12:03:40 -08004995
4996 @Override
4997 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4998 int slotIndex, String callingPackage, String aid, int p2) {
4999 enforceModifyPermission();
5000 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5001 if (DBG) {
5002 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5003 }
5004 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5005 callingPackage, aid, p2);
5006 }
5007
5008 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5009 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 final long identity = Binder.clearCallingIdentity();
5011 try {
5012 if (TextUtils.equals(ISDR_AID, aid)) {
5013 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005014 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5015 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 if (bestComponent == null
5017 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5018 loge("The calling package is not allowed to access ISD-R.");
5019 throw new SecurityException(
5020 "The calling package is not allowed to access ISD-R.");
5021 }
Derek Tan740e1672017-06-27 14:56:27 -07005022 }
Derek Tan740e1672017-06-27 14:56:27 -07005023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005025 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5026 null /* workSource */);
5027 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 return response;
5029 } finally {
5030 Binder.restoreCallingIdentity(identity);
5031 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005032 }
5033
5034 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005035 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5037 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005038 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5039 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5040 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005041
Jordan Liu4c733742019-02-28 12:03:40 -08005042 @Override
5043 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5044 enforceModifyPermission();
5045 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5046 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5047 channel);
5048 }
5049
5050 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051 final long identity = Binder.clearCallingIdentity();
5052 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053 if (channel < 0) {
5054 return false;
5055 }
Jordan Liu4c733742019-02-28 12:03:40 -08005056 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5057 null /* workSource */);
5058 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059 return success;
5060 } finally {
5061 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005062 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005063 }
5064
5065 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005066 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005067 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5069 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005070 if (DBG) {
5071 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5072 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5073 + p3 + " data=" + data);
5074 }
5075 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5076 command, p1, p2, p3, data);
5077 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005078
Jordan Liu4c733742019-02-28 12:03:40 -08005079 @Override
5080 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5081 int command, int p1, int p2, int p3, String data) {
5082 enforceModifyPermission();
5083 if (DBG) {
5084 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5085 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5086 + p3 + " data=" + data);
5087 }
5088 return iccTransmitApduLogicalChannelWithPermission(
5089 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5090 data);
5091 }
5092
5093 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5094 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005097 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 return "";
5099 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005100
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005101 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005102 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5103 null /* workSource */);
5104 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 // Append the returned status code to the end of the response payload.
5107 String s = Integer.toHexString(
5108 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5109 if (response.payload != null) {
5110 s = IccUtils.bytesToHexString(response.payload) + s;
5111 }
5112 return s;
5113 } finally {
5114 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005115 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005116 }
Jake Hambye994d462014-02-03 13:10:13 -08005117
Evan Charltonc66da362014-05-16 14:06:40 -07005118 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005119 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5120 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5122 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005124 if (DBG) {
5125 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5126 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5127 }
5128 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5129 cla, command, p1, p2, p3, data);
5130 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005131
Jordan Liu4c733742019-02-28 12:03:40 -08005132 @Override
5133 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5134 int command, int p1, int p2, int p3, String data) {
5135 enforceModifyPermission();
5136 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5137 if (DBG) {
5138 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5139 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5140 + " data=" + data);
5141 }
5142
5143 return iccTransmitApduBasicChannelWithPermission(
5144 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5145 p2, p3, data);
5146 }
5147
5148 // open APDU basic channel assuming the caller has sufficient permissions
5149 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5150 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151 final long identity = Binder.clearCallingIdentity();
5152 try {
5153 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5154 && TextUtils.equals(ISDR_AID, data)) {
5155 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005156 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5157 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 if (bestComponent == null
5159 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5160 loge("The calling package is not allowed to select ISD-R.");
5161 throw new SecurityException(
5162 "The calling package is not allowed to select ISD-R.");
5163 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005164 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005165
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005167 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5168 null /* workSource */);
5169 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 // Append the returned status code to the end of the response payload.
5172 String s = Integer.toHexString(
5173 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5174 if (response.payload != null) {
5175 s = IccUtils.bytesToHexString(response.payload) + s;
5176 }
5177 return s;
5178 } finally {
5179 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005180 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005181 }
5182
5183 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005184 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005185 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005186 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5187 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 final long identity = Binder.clearCallingIdentity();
5190 try {
5191 if (DBG) {
5192 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5193 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5194 }
5195
5196 IccIoResult response =
5197 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5198 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5199 subId);
5200
5201 if (DBG) {
5202 log("Exchange SIM_IO [R]" + response);
5203 }
5204
5205 byte[] result = null;
5206 int length = 2;
5207 if (response.payload != null) {
5208 length = 2 + response.payload.length;
5209 result = new byte[length];
5210 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5211 } else {
5212 result = new byte[length];
5213 }
5214
5215 result[length - 1] = (byte) response.sw2;
5216 result[length - 2] = (byte) response.sw1;
5217 return result;
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005220 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005221 }
5222
Nathan Haroldb3014052017-01-25 15:57:32 -08005223 /**
5224 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5225 * on a particular subscription
5226 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005227 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5228 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005230 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005231 return null;
5232 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233
5234 final long identity = Binder.clearCallingIdentity();
5235 try {
5236 if (appType != TelephonyManager.APPTYPE_USIM
5237 && appType != TelephonyManager.APPTYPE_SIM) {
5238 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5239 return null;
5240 }
5241 Object response = sendRequest(
5242 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5243 if (response instanceof String[]) {
5244 return (String[]) response;
5245 }
yincheng zhaod698b842019-09-06 17:06:54 -07005246 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005248 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005249 } finally {
5250 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005251 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005252 }
5253
yincheng zhaod698b842019-09-06 17:06:54 -07005254 /**
5255 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5256 * subscription.
5257 *
5258 * @param subId the id of the subscription.
5259 * @param appType the uicc app type, must be USIM or SIM.
5260 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5261 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005262 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005263 * @return number of fplmns that is successfully written to the SIM.
5264 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005265 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5266 String callingFeatureId) {
5267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5268 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005269 if (DBG) logv("no permissions for setForbiddenplmns");
5270 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5271 }
5272 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5273 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5274 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5275 }
5276 if (fplmns == null) {
5277 throw new IllegalArgumentException("Fplmn List provided is null");
5278 }
5279 for (String fplmn : fplmns) {
5280 if (!CellIdentity.isValidPlmn(fplmn)) {
5281 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5282 }
5283 }
5284 final long identity = Binder.clearCallingIdentity();
5285 try {
5286 Object response = sendRequest(
5287 CMD_SET_FORBIDDEN_PLMNS,
5288 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5289 subId);
5290 return (int) response;
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
5293 }
5294 }
5295
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005296 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005297 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5299 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5304 if (response.payload == null) {
5305 return "";
5306 }
Evan Charltonc66da362014-05-16 14:06:40 -07005307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308 // Append the returned status code to the end of the response payload.
5309 String s = Integer.toHexString(
5310 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5311 s = IccUtils.bytesToHexString(response.payload) + s;
5312 return s;
5313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
Evan Charltonc66da362014-05-16 14:06:40 -07005316 }
5317
Jake Hambye994d462014-02-03 13:10:13 -08005318 /**
5319 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5320 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5321 *
5322 * @param itemID the ID of the item to read
5323 * @return the NV item as a String, or null on error.
5324 */
5325 @Override
5326 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005327 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5329 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330
5331 final long identity = Binder.clearCallingIdentity();
5332 try {
5333 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005334 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5336 return value;
5337 } finally {
5338 Binder.restoreCallingIdentity(identity);
5339 }
Jake Hambye994d462014-02-03 13:10:13 -08005340 }
5341
5342 /**
5343 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5344 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5345 *
5346 * @param itemID the ID of the item to read
5347 * @param itemValue the value to write, as a String
5348 * @return true on success; false on any failure
5349 */
5350 @Override
5351 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005352 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5354 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355
5356 final long identity = Binder.clearCallingIdentity();
5357 try {
5358 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5359 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005360 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5362 return success;
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
5365 }
Jake Hambye994d462014-02-03 13:10:13 -08005366 }
5367
5368 /**
5369 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5370 * Used for device configuration by some CDMA operators.
5371 *
5372 * @param preferredRoamingList byte array containing the new PRL
5373 * @return true on success; false on any failure
5374 */
5375 @Override
5376 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5378 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379
5380 final long identity = Binder.clearCallingIdentity();
5381 try {
5382 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5383 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5384 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5385 return success;
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388 }
Jake Hambye994d462014-02-03 13:10:13 -08005389 }
5390
5391 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005392 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005393 * Used for device configuration by some CDMA operators.
5394 *
chen xu6dac5ab2018-10-26 17:39:23 -07005395 * @param slotIndex - device slot.
5396 *
Jake Hambye994d462014-02-03 13:10:13 -08005397 * @return true on success; false on any failure
5398 */
5399 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005400 public boolean resetModemConfig(int slotIndex) {
5401 Phone phone = PhoneFactory.getPhone(slotIndex);
5402 if (phone != null) {
5403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5404 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405
chen xu6dac5ab2018-10-26 17:39:23 -07005406 final long identity = Binder.clearCallingIdentity();
5407 try {
5408 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5409 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5410 return success;
5411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 }
chen xu6dac5ab2018-10-26 17:39:23 -07005415 return false;
5416 }
5417
5418 /**
5419 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5420 *
5421 * @param slotIndex - device slot.
5422 *
5423 * @return true on success; false on any failure
5424 */
5425 @Override
5426 public boolean rebootModem(int slotIndex) {
5427 Phone phone = PhoneFactory.getPhone(slotIndex);
5428 if (phone != null) {
5429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5430 mApp, phone.getSubId(), "rebootModem");
5431
5432 final long identity = Binder.clearCallingIdentity();
5433 try {
5434 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5435 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5436 return success;
5437 } finally {
5438 Binder.restoreCallingIdentity(identity);
5439 }
5440 }
5441 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005442 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005443
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005444 public String[] getPcscfAddress(String apnType, String callingPackage,
5445 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005446 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5448 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005449 return new String[0];
5450 }
5451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452 final long identity = Binder.clearCallingIdentity();
5453 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005454 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455 } finally {
5456 Binder.restoreCallingIdentity(identity);
5457 }
Wink Saville36469e72014-06-11 15:17:00 -07005458 }
5459
Brad Ebinger51f743a2017-01-23 13:50:20 -08005460 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005461 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5462 * {@link #disableIms(int)}.
5463 * @param slotIndex device slot.
5464 */
5465 public void resetIms(int slotIndex) {
5466 enforceModifyPermission();
5467
5468 final long identity = Binder.clearCallingIdentity();
5469 try {
5470 if (mImsResolver == null) {
5471 // may happen if the does not support IMS.
5472 return;
5473 }
5474 mImsResolver.disableIms(slotIndex);
5475 mImsResolver.enableIms(slotIndex);
5476 } finally {
5477 Binder.restoreCallingIdentity(identity);
5478 }
5479 }
5480
5481 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005482 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5483 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005484 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005485 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005486 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487
5488 final long identity = Binder.clearCallingIdentity();
5489 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005490 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005491 // may happen if the device does not support IMS.
5492 return;
5493 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005494 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005498 }
5499
5500 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005501 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5502 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005503 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005504 public void disableIms(int slotId) {
5505 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506
5507 final long identity = Binder.clearCallingIdentity();
5508 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005509 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005510 // may happen if the device does not support IMS.
5511 return;
5512 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005513 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514 } finally {
5515 Binder.restoreCallingIdentity(identity);
5516 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005517 }
5518
5519 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005520 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5521 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005522 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005523 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005524 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526
5527 final long identity = Binder.clearCallingIdentity();
5528 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005529 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005530 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5531 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005532 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005533 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005537 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005538 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005539 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5540 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005541 @Override
5542 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005543 enforceModifyPermission();
5544
5545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005548 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005549 } finally {
5550 Binder.restoreCallingIdentity(identity);
5551 }
5552 }
5553
5554 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005555 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005556 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005557 */
5558 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5559 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005563 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005564 // may happen if the device does not support IMS.
5565 return null;
5566 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005567 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005571 }
5572
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005573 /**
5574 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005575 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005576 */
5577 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5578 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579
5580 final long identity = Binder.clearCallingIdentity();
5581 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005582 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005583 // may happen if the device does not support IMS.
5584 return null;
5585 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005586 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005590 }
5591
Brad Ebinger884c07b2018-02-15 16:17:40 -08005592 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005593 * Sets the ImsService Package Name that Telephony will bind to.
5594 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005595 * @param slotIndex the slot ID that the ImsService should bind for.
5596 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005597 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005598 * @param featureTypes An integer array of feature types associated with a packageName.
5599 * @param packageName The name of the package that the current configuration will be replaced
5600 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005601 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005602 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005603 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5604 int[] featureTypes, String packageName) {
5605 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5606 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5608 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005609 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005610
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 final long identity = Binder.clearCallingIdentity();
5612 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005613 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005614 // may happen if the device does not support IMS.
5615 return false;
5616 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005617 Map<Integer, String> featureConfig = new HashMap<>();
5618 for (int featureType : featureTypes) {
5619 featureConfig.put(featureType, packageName);
5620 }
5621 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5622 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005626 }
5627
5628 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005629 * Clears any carrier ImsService overrides for the slot index specified that were previously
5630 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5631 *
5632 * This should only be used for testing.
5633 *
5634 * @param slotIndex the slot ID that the ImsService should bind for.
5635 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5636 */
5637 @Override
5638 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5639 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5640 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5641 "clearCarrierImsServiceOverride");
5642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5643 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5644 "clearCarrierImsServiceOverride");
5645
5646 final long identity = Binder.clearCallingIdentity();
5647 try {
5648 if (mImsResolver == null) {
5649 // may happen if the device does not support IMS.
5650 return false;
5651 }
5652 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
5655 }
5656 }
5657
5658 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005659 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005660 *
5661 * @param slotId The slot that the ImsService is associated with.
5662 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5663 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005664 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005665 * @return the package name of the ImsService configuration.
5666 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005667 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5668 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005669 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005670 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005671 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005672 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5673 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005674
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 final long identity = Binder.clearCallingIdentity();
5676 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005677 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005678 // may happen if the device does not support IMS.
5679 return "";
5680 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005681 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005682 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5683 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005687 }
5688
Brad Ebinger77b832e2019-10-17 17:03:22 -07005689 /**
5690 * Get the MmTelFeature state associated with the requested subscription id.
5691 * @param subId The subscription that the MmTelFeature is associated with.
5692 * @param callback A callback with an integer containing the
5693 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5694 */
5695 @Override
5696 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5697 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5698 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5699 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5700 "IMS not available on device.");
5701 }
5702 final long token = Binder.clearCallingIdentity();
5703 try {
5704 int slotId = getSlotIndex(subId);
5705 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5706 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5707 + subId + "'");
5708 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5709 }
5710 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5711 try {
5712 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5713 } catch (RemoteException e) {
5714 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5715 + "Ignore");
5716 }
5717 });
5718 } finally {
5719 Binder.restoreCallingIdentity(token);
5720 }
5721 }
5722
Daniel Brightbb5840b2021-01-12 15:48:18 -08005723 /**
5724 * Sets the ims registration state on all valid {@link Phone}s.
5725 */
5726 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005727 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728
5729 final long identity = Binder.clearCallingIdentity();
5730 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005731 // NOTE: Before S, this method only set the default phone.
5732 for (final Phone phone : PhoneFactory.getPhones()) {
5733 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5734 phone.setImsRegistrationState(registered);
5735 }
5736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
Wink Saville36469e72014-06-11 15:17:00 -07005740 }
5741
5742 /**
Stuart Scott54788802015-03-30 13:18:01 -07005743 * Set the network selection mode to automatic.
5744 *
5745 */
5746 @Override
5747 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5749 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750
5751 final long identity = Binder.clearCallingIdentity();
5752 try {
shilufc958392020-01-20 11:36:01 -08005753 if (!isActiveSubscription(subId)) {
5754 return;
5755 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005757 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5758 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759 } finally {
5760 Binder.restoreCallingIdentity(identity);
5761 }
Stuart Scott54788802015-03-30 13:18:01 -07005762 }
5763
Jack Yud10cdd42020-09-28 20:28:01 -07005764 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005765 * Ask the radio to connect to the input network and change selection mode to manual.
5766 *
5767 * @param subId the id of the subscription.
5768 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5769 * the operator to attach to.
5770 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5771 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5772 * normal network selection next time.
5773 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005774 */
5775 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005776 public boolean setNetworkSelectionModeManual(
5777 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5779 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005780
5781 if (!isActiveSubscription(subId)) {
5782 return false;
5783 }
5784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 final long identity = Binder.clearCallingIdentity();
5786 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005787 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005789 if (DBG) {
5790 log("setNetworkSelectionModeManual: subId: " + subId
5791 + " operator: " + operatorInfo);
5792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005797 }
shilu84f6e8b2019-12-19 13:58:01 -08005798 /**
5799 * Get the manual network selection
5800 *
5801 * @param subId the id of the subscription.
5802 *
5803 * @return the previously saved user selected PLMN
5804 */
5805 @Override
5806 public String getManualNetworkSelectionPlmn(int subId) {
5807 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005808 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005809 mApp, subId, "getManualNetworkSelectionPlmn");
5810
5811 final long identity = Binder.clearCallingIdentity();
5812 try {
5813 if (!isActiveSubscription(subId)) {
5814 return "";
5815 }
5816
5817 final Phone phone = getPhone(subId);
5818 if (phone == null) {
5819 return "";
5820 }
5821 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5822 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5823 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5824 } finally {
5825 Binder.restoreCallingIdentity(identity);
5826 }
5827 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005828
5829 /**
5830 * Scans for available networks.
5831 */
5832 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005833 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5834 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5836 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005837 LocationAccessPolicy.LocationPermissionResult locationResult =
5838 LocationAccessPolicy.checkLocationPermission(mApp,
5839 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5840 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005841 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005842 .setCallingPid(Binder.getCallingPid())
5843 .setCallingUid(Binder.getCallingUid())
5844 .setMethod("getCellNetworkScanResults")
5845 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07005846 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5847 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005848 .build());
5849 switch (locationResult) {
5850 case DENIED_HARD:
5851 throw new SecurityException("Not allowed to access scan results -- location");
5852 case DENIED_SOFT:
5853 return null;
5854 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855
Pengquan Menga1bb6272018-09-06 09:59:22 -07005856 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857 try {
5858 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005859 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005864 }
5865
5866 /**
sqian80370722020-01-29 15:02:51 -08005867 * Get the call forwarding info, given the call forwarding reason.
5868 */
5869 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005870 public void getCallForwarding(int subId, int callForwardingReason,
5871 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005872 enforceReadPrivilegedPermission("getCallForwarding");
5873 long identity = Binder.clearCallingIdentity();
5874 try {
5875 if (DBG) {
5876 log("getCallForwarding: subId " + subId
5877 + " callForwardingReason" + callForwardingReason);
5878 }
Hall Liua1acea22020-09-18 19:04:59 -07005879
5880 Phone phone = getPhone(subId);
5881 if (phone == null) {
5882 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005883 callback.onError(
5884 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005885 } catch (RemoteException e) {
5886 // ignore
5887 }
5888 return;
5889 }
5890
5891 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5892 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5893 @Override
5894 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5895 try {
5896 callback.onCallForwardingInfoAvailable(info);
5897 } catch (RemoteException e) {
5898 // ignore
5899 }
5900 }
5901
5902 @Override
5903 public void onError(int error) {
5904 try {
5905 callback.onError(error);
5906 } catch (RemoteException e) {
5907 // ignore
5908 }
5909 }
5910 });
5911 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005912 } finally {
5913 Binder.restoreCallingIdentity(identity);
5914 }
5915 }
5916
5917 /**
5918 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5919 * reason, the number to forward, and the timeout before the forwarding is attempted.
5920 */
5921 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005922 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5923 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005924 enforceModifyPermission();
5925 long identity = Binder.clearCallingIdentity();
5926 try {
5927 if (DBG) {
5928 log("setCallForwarding: subId " + subId
5929 + " callForwardingInfo" + callForwardingInfo);
5930 }
Hall Liua1acea22020-09-18 19:04:59 -07005931
5932 Phone phone = getPhone(subId);
5933 if (phone == null) {
5934 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005935 callback.accept(
5936 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005937 } catch (RemoteException e) {
5938 // ignore
5939 }
5940 return;
5941 }
5942
5943 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5944 FunctionalUtils.ignoreRemoteException(callback::accept));
5945
5946 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
5950 }
5951
5952 /**
Hall Liua1acea22020-09-18 19:04:59 -07005953 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005954 */
5955 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005956 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWangc63cf522021-03-31 22:08:45 +08005957 enforceReadPrivilegedPermission("getCallWaitingStatus");
sqian80370722020-01-29 15:02:51 -08005958 long identity = Binder.clearCallingIdentity();
5959 try {
Hall Liua1acea22020-09-18 19:04:59 -07005960 Phone phone = getPhone(subId);
5961 if (phone == null) {
5962 try {
5963 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5964 } catch (RemoteException e) {
5965 // ignore
5966 }
5967 return;
5968 }
SongFerngWangc63cf522021-03-31 22:08:45 +08005969 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5970 PersistableBundle c = configManager.getConfigForSubId(subId);
5971 boolean requireUssd = c.getBoolean(
5972 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005973
sqian80370722020-01-29 15:02:51 -08005974 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWangc63cf522021-03-31 22:08:45 +08005975 if (requireUssd) {
5976 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5977 getSubscriptionCarrierId(subId));
5978 String newUssdCommand = "";
5979 try {
5980 newUssdCommand = carrierXmlParser.getFeature(
5981 CarrierXmlParser.FEATURE_CALL_WAITING)
5982 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
5983 } catch (NullPointerException e) {
5984 loge("Failed to generate USSD number" + e);
5985 }
5986 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5987 mMainThreadHandler, callback, carrierXmlParser,
5988 CarrierXmlParser.SsEntry.SSAction.QUERY);
5989 final String ussdCommand = newUssdCommand;
5990 Executors.newSingleThreadExecutor().execute(() -> {
5991 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5992 });
5993 } else {
5994 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
5995 callback::accept);
5996 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
5997 }
sqian80370722020-01-29 15:02:51 -08005998 } finally {
5999 Binder.restoreCallingIdentity(identity);
6000 }
6001 }
6002
6003 /**
Hall Liua1acea22020-09-18 19:04:59 -07006004 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08006005 */
6006 @Override
Hall Liua1acea22020-09-18 19:04:59 -07006007 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08006008 enforceModifyPermission();
6009 long identity = Binder.clearCallingIdentity();
6010 try {
Hall Liua1acea22020-09-18 19:04:59 -07006011 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6012
6013 Phone phone = getPhone(subId);
6014 if (phone == null) {
6015 try {
6016 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6017 } catch (RemoteException e) {
6018 // ignore
6019 }
6020 return;
6021 }
6022
SongFerngWangc63cf522021-03-31 22:08:45 +08006023 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6024 PersistableBundle c = configManager.getConfigForSubId(subId);
6025 boolean requireUssd = c.getBoolean(
6026 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07006027
SongFerngWangc63cf522021-03-31 22:08:45 +08006028 if (DBG) log("getCallWaitingStatus: subId " + subId);
6029 if (requireUssd) {
6030 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6031 getSubscriptionCarrierId(subId));
6032 CarrierXmlParser.SsEntry.SSAction ssAction =
6033 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6034 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6035 String newUssdCommand = "";
6036 try {
6037 newUssdCommand = carrierXmlParser.getFeature(
6038 CarrierXmlParser.FEATURE_CALL_WAITING)
6039 .makeCommand(ssAction, null);
6040 } catch (NullPointerException e) {
6041 loge("Failed to generate USSD number" + e);
6042 }
6043 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6044 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6045 final String ussdCommand = newUssdCommand;
6046 Executors.newSingleThreadExecutor().execute(() -> {
6047 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6048 });
6049 } else {
6050 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6051 FunctionalUtils.ignoreRemoteException(callback::accept));
6052
6053 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6054 }
sqian80370722020-01-29 15:02:51 -08006055 } finally {
6056 Binder.restoreCallingIdentity(identity);
6057 }
6058 }
6059
6060 /**
yinxub1bed742017-04-17 11:45:04 -07006061 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006062 *
yinxub1bed742017-04-17 11:45:04 -07006063 * @param subId id of the subscription
6064 * @param request contains the radio access networks with bands/channels to scan
6065 * @param messenger callback messenger for scan results or errors
6066 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006067 * @return the id of the requested scan which can be used to stop the scan.
6068 */
6069 @Override
6070 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006071 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6073 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006074 LocationAccessPolicy.LocationPermissionResult locationResult =
6075 LocationAccessPolicy.checkLocationPermission(mApp,
6076 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6077 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006078 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006079 .setCallingPid(Binder.getCallingPid())
6080 .setCallingUid(Binder.getCallingUid())
6081 .setMethod("requestNetworkScan")
6082 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6083 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006084 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07006085 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6086 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006087 if (e != null) {
6088 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6089 throw e;
6090 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006091 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006092 return TelephonyScanManager.INVALID_SCAN_ID;
6093 }
6094 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006095 }
Hall Liu912dfd32019-04-25 14:02:26 -07006096 int callingUid = Binder.getCallingUid();
6097 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006098 final long identity = Binder.clearCallingIdentity();
6099 try {
6100 return mNetworkScanRequestTracker.startNetworkScan(
6101 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006102 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006103 } finally {
6104 Binder.restoreCallingIdentity(identity);
6105 }
yinxu504e1392017-04-12 16:03:22 -07006106 }
6107
Hall Liub2ac8ef2019-02-28 15:56:23 -08006108 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07006109 NetworkScanRequest request, int subId, String callingPackage) {
6110 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006111 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6112 boolean hasNetworkScanPermission =
6113 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6114 == PERMISSION_GRANTED;
6115
6116 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6117 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6118 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006119 }
6120
6121 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6122 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006123 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6124 return new SecurityException("Specific channels must not be"
6125 + " scanned without location access.");
6126 }
6127 }
6128 }
6129
Hall Liub2ac8ef2019-02-28 15:56:23 -08006130 return null;
6131 }
6132
yinxu504e1392017-04-12 16:03:22 -07006133 /**
6134 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006135 *
6136 * @param subId id of the subscription
6137 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006138 */
6139 @Override
6140 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6142 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143
Hall Liu912dfd32019-04-25 14:02:26 -07006144 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145 final long identity = Binder.clearCallingIdentity();
6146 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006147 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 } finally {
6149 Binder.restoreCallingIdentity(identity);
6150 }
yinxu504e1392017-04-12 16:03:22 -07006151 }
6152
6153 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006154 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006155 *
SongFerngWang9e060372020-12-21 16:41:52 +08006156 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006157 */
6158 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006159 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006160 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006161 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006162 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163
6164 final long identity = Binder.clearCallingIdentity();
6165 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006166 if (DBG) log("getAllowedNetworkTypesBitmask");
6167 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6168 int networkTypesBitmask = (result != null ? result[0] : -1);
6169 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6170 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006174 }
6175
6176 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006177 * Get the allowed network types for certain reason.
6178 *
6179 * @param subId the id of the subscription.
6180 * @param reason the reason the allowed network type change is taking place
6181 * @return the allowed network types.
6182 */
6183 @Override
6184 public long getAllowedNetworkTypesForReason(int subId,
6185 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006186 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006187 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6191 } finally {
6192 Binder.restoreCallingIdentity(identity);
6193 }
6194 }
6195
6196 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006197 * Enable/Disable E-UTRA-NR Dual Connectivity
6198 * @param subId subscription id of the sim card
6199 * @param nrDualConnectivityState expected NR dual connectivity state
6200 * This can be passed following states
6201 * <ol>
6202 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6203 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6204 * <li>Disable NR dual connectivity and force secondary cell to be released
6205 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6206 * </ol>
6207 * @return operation result.
6208 */
6209 @Override
6210 public int setNrDualConnectivityState(int subId,
6211 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6213 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006214 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006215 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6216 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6217 }
6218
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006219 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6220 final long identity = Binder.clearCallingIdentity();
6221 try {
6222 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6223 nrDualConnectivityState, subId,
6224 workSource);
6225 if (DBG) log("enableNRDualConnectivity result: " + result);
6226 return result;
6227 } finally {
6228 Binder.restoreCallingIdentity(identity);
6229 }
6230 }
6231
6232 /**
6233 * Is E-UTRA-NR Dual Connectivity enabled
6234 * @return true if dual connectivity is enabled else false
6235 */
6236 @Override
6237 public boolean isNrDualConnectivityEnabled(int subId) {
6238 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006239 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006240 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006241 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006242 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6243 return false;
6244 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006245 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6246 final long identity = Binder.clearCallingIdentity();
6247 try {
6248 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6249 null, subId, workSource);
6250 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6251 return isEnabled;
6252 } finally {
6253 Binder.restoreCallingIdentity(identity);
6254 }
6255 }
6256
6257 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006258 * Set the allowed network types of the device and
6259 * provide the reason triggering the allowed network change.
6260 *
6261 * @param subId the id of the subscription.
6262 * @param reason the reason the allowed network type change is taking place
6263 * @param allowedNetworkTypes the allowed network types.
6264 * @return true on success; false on any failure.
6265 */
6266 @Override
6267 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006268 @TelephonyManager.AllowedNetworkTypesReason int reason,
6269 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6271 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006272 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWangc2d3ccc2021-04-15 19:46:33 +08006273 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6274 return false;
6275 }
6276 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6277 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang9e060372020-12-21 16:41:52 +08006278 return false;
6279 }
6280
SongFerngWang522637d2021-03-02 22:09:29 +08006281 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6282 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6283
6284
6285 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6286 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6287 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006288 }
SongFerngWang522637d2021-03-02 22:09:29 +08006289
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006290 final long identity = Binder.clearCallingIdentity();
6291 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006292 Boolean success = (Boolean) sendRequest(
6293 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6294 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6295
6296 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6297 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006298 } finally {
6299 Binder.restoreCallingIdentity(identity);
6300 }
6301 }
6302
6303 /**
Miaoa84611c2019-03-15 09:21:10 +08006304 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006305 *
Miaoa84611c2019-03-15 09:21:10 +08006306 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006307 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006308 * @hide
6309 */
6310 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006311 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006312 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006314 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 try {
Miaoa84611c2019-03-15 09:21:10 +08006316 if (phone != null) {
6317 return phone.hasMatchedTetherApnSetting();
6318 } else {
6319 return false;
6320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 } finally {
6322 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006323 }
Junda Liu475951f2014-11-07 16:45:03 -08006324 }
6325
6326 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006327 * Enable or disable always reporting signal strength changes from radio.
6328 *
6329 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6330 */
6331 @Override
6332 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6333 enforceModifyPermission();
6334 enforceSystemCaller();
6335
6336 final long identity = Binder.clearCallingIdentity();
6337 final Phone phone = getPhone(subId);
6338 try {
6339 if (phone != null) {
6340 if (DBG) {
6341 log("setAlwaysReportSignalStrength: subId=" + subId
6342 + " isEnable=" + isEnable);
6343 }
6344 phone.setAlwaysReportSignalStrength(isEnable);
6345 } else {
6346 loge("setAlwaysReportSignalStrength: no phone found for subId="
6347 + subId);
6348 }
6349 } finally {
6350 Binder.restoreCallingIdentity(identity);
6351 }
6352 }
6353
6354 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006355 * Get the user enabled state of Mobile Data.
6356 *
6357 * TODO: remove and use isUserDataEnabled.
6358 * This can't be removed now because some vendor codes
6359 * calls through ITelephony directly while they should
6360 * use TelephonyManager.
6361 *
6362 * @return true on enabled
6363 */
6364 @Override
6365 public boolean getDataEnabled(int subId) {
6366 return isUserDataEnabled(subId);
6367 }
6368
6369 /**
6370 * Get whether mobile data is enabled per user setting.
6371 *
6372 * There are other factors deciding whether mobile data is actually enabled, but they are
6373 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006374 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006375 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006376 *
6377 * @return {@code true} if data is enabled else {@code false}
6378 */
6379 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006380 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006381 try {
6382 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6383 null);
6384 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6386 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388
6389 final long identity = Binder.clearCallingIdentity();
6390 try {
6391 int phoneId = mSubscriptionController.getPhoneId(subId);
6392 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6393 Phone phone = PhoneFactory.getPhone(phoneId);
6394 if (phone != null) {
6395 boolean retVal = phone.isUserDataEnabled();
6396 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6397 return retVal;
6398 } else {
6399 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6400 return false;
6401 }
6402 } finally {
6403 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006404 }
6405 }
6406
6407 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006408 * Checks if the device is capable of mobile data by considering whether whether the
6409 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6410 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006411 *
Shuo Qian985d1232020-01-08 14:30:06 -08006412 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006413 */
6414 @Override
6415 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006416 try {
6417 try {
6418 mApp.enforceCallingOrSelfPermission(
6419 android.Manifest.permission.ACCESS_NETWORK_STATE,
6420 null);
6421 } catch (Exception e) {
6422 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6423 "isDataEnabled");
6424 }
6425 } catch (Exception e) {
6426 enforceReadPrivilegedPermission("isDataEnabled");
6427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428
6429 final long identity = Binder.clearCallingIdentity();
6430 try {
6431 int phoneId = mSubscriptionController.getPhoneId(subId);
6432 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6433 Phone phone = PhoneFactory.getPhone(phoneId);
6434 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006435 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6437 return retVal;
6438 } else {
6439 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6440 return false;
6441 }
6442 } finally {
6443 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006444 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006445 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006446
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006447 /**
6448 * Check if data is enabled for a specific reason
6449 * @param subId Subscription index
6450 * @param reason the reason the data enable change is taking place
6451 * @return {@code true} if the overall data is enabled; {@code false} if not.
6452 */
6453 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006454 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006455 @TelephonyManager.DataEnabledReason int reason) {
6456 try {
6457 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6458 null);
6459 } catch (Exception e) {
6460 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006461 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006462 }
6463
6464
6465 final long identity = Binder.clearCallingIdentity();
6466 try {
6467 int phoneId = mSubscriptionController.getPhoneId(subId);
6468 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006469 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006470 + " reason=" + reason);
6471 }
6472 Phone phone = PhoneFactory.getPhone(phoneId);
6473 if (phone != null) {
6474 boolean retVal;
6475 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6476 retVal = phone.isUserDataEnabled();
6477 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006478 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006479 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006480 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006481 return retVal;
6482 } else {
6483 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006484 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006485 + subId + " retVal=false");
6486 }
6487 return false;
6488 }
6489 } finally {
6490 Binder.restoreCallingIdentity(identity);
6491 }
6492 }
6493
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006494 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006495 Phone phone) {
Sarah Chinca45c312021-04-09 10:37:15 -07006496 if (uid == Process.PHONE_UID) {
6497 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6498 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liuce478d22020-07-13 12:13:03 -07006499 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6500 }
6501
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006502 //load access rules from carrier configs, and check those as well: b/139133814
6503 SubscriptionController subController = SubscriptionController.getInstance();
6504 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6505 || subController == null) return privilegeFromSim;
6506
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006507 PackageManager pkgMgr = phone.getContext().getPackageManager();
6508 String[] packages = pkgMgr.getPackagesForUid(uid);
6509
6510 final long identity = Binder.clearCallingIdentity();
6511 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006512 int subId = phone.getSubId();
6513 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6514 // A test override is in place for the privileges for this subId, so don't try to
6515 // read the subscription privileges.
6516 return privilegeFromSim;
6517 }
6518 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006519 SubscriptionManager subManager = (SubscriptionManager)
6520 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6521 for (String pkg : packages) {
6522 if (subManager.canManageSubscription(subInfo, pkg)) {
6523 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6524 }
6525 }
6526 return privilegeFromSim;
6527 } finally {
6528 Binder.restoreCallingIdentity(identity);
6529 }
6530 }
6531
6532 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6533 String pkgName) {
6534 //load access rules from carrier configs, and check those as well: b/139133814
6535 SubscriptionController subController = SubscriptionController.getInstance();
6536 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6537 || subController == null) return privilegeFromSim;
6538
6539 final long identity = Binder.clearCallingIdentity();
6540 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006541 int subId = phone.getSubId();
6542 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6543 // A test override is in place for the privileges for this subId, so don't try to
6544 // read the subscription privileges.
6545 return privilegeFromSim;
6546 }
6547 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006548 SubscriptionManager subManager = (SubscriptionManager)
6549 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6550 return subManager.canManageSubscription(subInfo, pkgName)
6551 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6552 } finally {
6553 Binder.restoreCallingIdentity(identity);
6554 }
6555 }
6556
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006557 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006558 public int getCarrierPrivilegeStatus(int subId) {
6559 final Phone phone = getPhone(subId);
6560 if (phone == null) {
6561 loge("getCarrierPrivilegeStatus: Invalid subId");
6562 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6563 }
6564 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006565 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006566 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006567 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6568 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006569
6570 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6571 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006572 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006573 }
Junda Liu29340342014-07-10 15:23:27 -07006574
6575 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006576 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006577 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006578 final Phone phone = getPhone(subId);
6579 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006580 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006581 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6582 }
6583 UiccProfile profile =
6584 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6585 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006586 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006587 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6588 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006589 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006590 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006591 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006592 }
6593
6594 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006595 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6596 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006597 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006598 }
6599
6600 int phoneId = SubscriptionManager.getPhoneId(subId);
6601 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006602 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006603 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006604 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6605 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006606 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6607 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6608 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006609 }
6610
6611 @Override
6612 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006613 if (TextUtils.isEmpty(pkgName))
6614 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006615 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6616 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6617 UiccCard card = UiccController.getInstance().getUiccCard(i);
6618 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006619 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006620 continue;
6621 }
6622
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006623 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6624 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6625 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006626 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6627 break;
6628 }
6629 }
6630
6631 return result;
Junda Liu29340342014-07-10 15:23:27 -07006632 }
Derek Tan89e89d42014-07-08 17:00:10 -07006633
6634 @Override
Junda Liue64de782015-04-16 17:19:16 -07006635 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6636 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6637 loge("phoneId " + phoneId + " is not valid.");
6638 return null;
6639 }
6640 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006641 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006642 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006643 return null ;
6644 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006645 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006646 }
6647
Amith Yamasani6e118872016-02-19 12:53:51 -08006648 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006649 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006650 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006651 List<String> privilegedPackages = new ArrayList<>();
6652 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006653 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6654 // has UICC in that slot.
6655 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006656 if (card.hasCarrierPrivilegeRules()) {
6657 if (packages == null) {
6658 // Only check packages in user 0 for now
6659 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006660 PackageManager.MATCH_DISABLED_COMPONENTS
6661 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006662 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006663 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006664 }
6665 for (int p = packages.size() - 1; p >= 0; p--) {
6666 PackageInfo pkgInfo = packages.get(p);
6667 if (pkgInfo != null && pkgInfo.packageName != null
6668 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006669 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006670 privilegedPackages.add(pkgInfo.packageName);
6671 }
6672 }
6673 }
6674 }
6675 return privilegedPackages;
6676 }
6677
chen xuf7e9fe82019-05-09 19:31:02 -07006678 @Override
6679 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006680 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6681
6682 final long identity = Binder.clearCallingIdentity();
6683
chen xuf7e9fe82019-05-09 19:31:02 -07006684 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006685 try {
6686 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6687 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6688 }
6689 } finally {
6690 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006691 }
6692 return privilegedPackages;
6693 }
6694
Wink Savilleb564aae2014-10-23 10:18:09 -07006695 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006696 final Phone phone = getPhone(subId);
6697 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006698 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006699 return null;
6700 }
6701 String iccId = card.getIccId();
6702 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006703 return null;
6704 }
6705 return iccId;
6706 }
6707
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006708 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006709 public void setCallComposerStatus(int subId, int status) {
6710 enforceModifyPermission();
6711
6712 final long identity = Binder.clearCallingIdentity();
6713 try {
6714 Phone phone = getPhone(subId);
6715 if (phone != null) {
6716 Phone defaultPhone = phone.getImsPhone();
6717 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6718 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6719 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006720 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6721 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006722 }
6723 }
Shuo Qiand8782462020-12-22 19:10:14 -08006724 } catch (ImsException e) {
6725 throw new ServiceSpecificException(e.getCode());
6726 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006727 Binder.restoreCallingIdentity(identity);
6728 }
6729 }
6730
6731 @Override
6732 public int getCallComposerStatus(int subId) {
6733 enforceReadPrivilegedPermission("getCallComposerStatus");
6734
6735 final long identity = Binder.clearCallingIdentity();
6736 try {
6737 Phone phone = getPhone(subId);
6738 if (phone != null) {
6739 Phone defaultPhone = phone.getImsPhone();
6740 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6741 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6742 return imsPhone.getCallComposerStatus();
6743 }
6744 }
6745 } finally {
6746 Binder.restoreCallingIdentity(identity);
6747 }
6748 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6749 }
6750
6751 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006752 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6753 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006754 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006755 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 final long identity = Binder.clearCallingIdentity();
6758 try {
6759 final String iccId = getIccId(subId);
6760 final Phone phone = getPhone(subId);
6761 if (phone == null) {
6762 return false;
6763 }
6764 final String subscriberId = phone.getSubscriberId();
6765
6766 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006767 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768 + subscriberId + " to " + number);
6769 }
6770
6771 if (TextUtils.isEmpty(iccId)) {
6772 return false;
6773 }
6774
6775 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6776
6777 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6778 if (alphaTag == null) {
6779 editor.remove(alphaTagPrefKey);
6780 } else {
6781 editor.putString(alphaTagPrefKey, alphaTag);
6782 }
6783
6784 // Record both the line number and IMSI for this ICCID, since we need to
6785 // track all merged IMSIs based on line number
6786 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6787 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6788 if (number == null) {
6789 editor.remove(numberPrefKey);
6790 editor.remove(subscriberPrefKey);
6791 } else {
6792 editor.putString(numberPrefKey, number);
6793 editor.putString(subscriberPrefKey, subscriberId);
6794 }
6795
6796 editor.commit();
6797 return true;
6798 } finally {
6799 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006800 }
Derek Tan7226c842014-07-02 17:42:23 -07006801 }
6802
6803 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006804 public String getLine1NumberForDisplay(int subId, String callingPackage,
6805 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006806 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006808 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006809 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006810 return null;
6811 }
Derek Tan97ebb422014-09-05 16:55:38 -07006812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 final long identity = Binder.clearCallingIdentity();
6814 try {
6815 String iccId = getIccId(subId);
6816 if (iccId != null) {
6817 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6818 if (DBG_MERGE) {
6819 log("getLine1NumberForDisplay returning "
6820 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6821 }
6822 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6825 return null;
6826 } finally {
6827 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006828 }
Derek Tan7226c842014-07-02 17:42:23 -07006829 }
6830
6831 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006832 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6833 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006835 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006836 return null;
6837 }
Derek Tan97ebb422014-09-05 16:55:38 -07006838
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 final long identity = Binder.clearCallingIdentity();
6840 try {
6841 String iccId = getIccId(subId);
6842 if (iccId != null) {
6843 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6844 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6845 }
6846 return null;
6847 } finally {
6848 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006849 }
Derek Tan7226c842014-07-02 17:42:23 -07006850 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006851
6852 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006853 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6854 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006855 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6856 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006858 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006859 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006860 return null;
6861 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006862
Jordan Liub49b04b2019-05-06 14:45:15 -07006863 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6864 // the process, where TelephonyManager was instantiated.
6865 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006866 final long identity = Binder.clearCallingIdentity();
6867 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006868 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869 final TelephonyManager tele = TelephonyManager.from(context);
6870 final SubscriptionManager sub = SubscriptionManager.from(context);
6871
6872 // Figure out what subscribers are currently active
6873 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874
Jordan Liub49b04b2019-05-06 14:45:15 -07006875 // Only consider subs which match the current subId
6876 // This logic can be simplified. See b/131189269 for progress.
6877 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006878 activeSubscriberIds.add(tele.getSubscriberId(subId));
6879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006880
6881 // First pass, find a number override for an active subscriber
6882 String mergeNumber = null;
6883 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6884 for (String key : prefs.keySet()) {
6885 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6886 final String subscriberId = (String) prefs.get(key);
6887 if (activeSubscriberIds.contains(subscriberId)) {
6888 final String iccId = key.substring(
6889 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6890 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6891 mergeNumber = (String) prefs.get(numberKey);
6892 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006893 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006894 + " for active subscriber " + subscriberId);
6895 }
6896 if (!TextUtils.isEmpty(mergeNumber)) {
6897 break;
6898 }
6899 }
6900 }
6901 }
6902
6903 // Shortcut when no active merged subscribers
6904 if (TextUtils.isEmpty(mergeNumber)) {
6905 return null;
6906 }
6907
6908 // Second pass, find all subscribers under that line override
6909 final ArraySet<String> result = new ArraySet<>();
6910 for (String key : prefs.keySet()) {
6911 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6912 final String number = (String) prefs.get(key);
6913 if (mergeNumber.equals(number)) {
6914 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6915 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6916 final String subscriberId = (String) prefs.get(subscriberKey);
6917 if (!TextUtils.isEmpty(subscriberId)) {
6918 result.add(subscriberId);
6919 }
6920 }
6921 }
6922 }
6923
6924 final String[] resultArray = result.toArray(new String[result.size()]);
6925 Arrays.sort(resultArray);
6926 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006927 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6929 }
6930 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006931 } finally {
6932 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006933 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006934 }
6935
6936 @Override
zoey chen38003472019-12-13 17:16:31 +08006937 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6938 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006939
6940 final long identity = Binder.clearCallingIdentity();
6941 try {
6942 final TelephonyManager telephonyManager = mApp.getSystemService(
6943 TelephonyManager.class);
6944 String subscriberId = telephonyManager.getSubscriberId(subId);
6945 if (subscriberId == null) {
6946 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006947 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006948 + subId);
6949 }
6950 return null;
6951 }
6952
6953 final SubscriptionInfo info = SubscriptionController.getInstance()
6954 .getSubscriptionInfo(subId);
6955 final ParcelUuid groupUuid = info.getGroupUuid();
6956 // If it doesn't belong to any group, return just subscriberId of itself.
6957 if (groupUuid == null) {
6958 return new String[]{subscriberId};
6959 }
6960
6961 // Get all subscriberIds from the group.
6962 final List<String> mergedSubscriberIds = new ArrayList<>();
6963 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006964 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006965 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006966 for (SubscriptionInfo subInfo : groupInfos) {
6967 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6968 if (subscriberId != null) {
6969 mergedSubscriberIds.add(subscriberId);
6970 }
6971 }
6972
6973 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6974 } finally {
6975 Binder.restoreCallingIdentity(identity);
6976
6977 }
6978 }
6979
6980 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006981 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006982 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006983 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984
6985 final long identity = Binder.clearCallingIdentity();
6986 try {
6987 final Phone phone = getPhone(subId);
6988 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
6991 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006992 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006993
6994 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006995 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006996 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6997 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006998 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6999 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000
7001 final long identity = Binder.clearCallingIdentity();
7002 try {
7003 final Phone phone = getPhone(subId);
7004 if (phone == null) {
7005 return false;
7006 }
7007 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7008 cdmaNonRoamingList);
7009 } finally {
7010 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007011 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007012 }
7013
7014 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007015 @Deprecated
7016 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7017 enforceModifyPermission();
7018
7019 int returnValue = 0;
7020 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007021 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007022 if(result.exception == null) {
7023 if (result.result != null) {
7024 byte[] responseData = (byte[])(result.result);
7025 if(responseData.length > oemResp.length) {
7026 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7027 responseData.length + "bytes. Buffer Size is " +
7028 oemResp.length + "bytes.");
7029 }
7030 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7031 returnValue = responseData.length;
7032 }
7033 } else {
7034 CommandException ex = (CommandException) result.exception;
7035 returnValue = ex.getCommandError().ordinal();
7036 if(returnValue > 0) returnValue *= -1;
7037 }
7038 } catch (RuntimeException e) {
7039 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7040 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7041 if(returnValue > 0) returnValue *= -1;
7042 }
7043
7044 return returnValue;
7045 }
7046
7047 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007048 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007049 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007050 try {
7051 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007052 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007053 mApp, phone.getSubId(), "getRadioAccessFamily");
7054 } catch (SecurityException e) {
7055 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7056 throw e;
7057 }
chen xub97461a2018-10-26 14:17:57 -07007058 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007059 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007060 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 final long identity = Binder.clearCallingIdentity();
7063 try {
chen xub97461a2018-10-26 14:17:57 -07007064 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007065 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007066 mApp, phone.getSubId(), "getRadioAccessFamily");
7067 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007068 } finally {
7069 Binder.restoreCallingIdentity(identity);
7070 }
chen xub97461a2018-10-26 14:17:57 -07007071 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007072 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007073
7074 @Override
7075 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007076 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007077 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078
7079 final long identity = Binder.clearCallingIdentity();
7080 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007081 ImsManager.getInstance(defaultPhone.getContext(),
7082 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 } finally {
7084 Binder.restoreCallingIdentity(identity);
7085 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007086 }
7087
7088 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007089 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007090 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007091 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7092 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007093 return false;
7094 }
Svet Ganovb320e182015-04-16 12:30:10 -07007095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007096 final long identity = Binder.clearCallingIdentity();
7097 try {
7098 // Check the user preference and the system-level IMS setting. Even if the user has
7099 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7100 // In the long run, we may instead need to check if there exists a connection service
7101 // which can support video calling.
7102 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007103 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 return imsManager.isVtEnabledByPlatform()
7105 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7106 && imsManager.isVtEnabledByUser();
7107 } finally {
7108 Binder.restoreCallingIdentity(identity);
7109 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007110 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007111
Andrew Leea1239f22015-03-02 17:44:07 -08007112 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007113 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7114 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007116 mApp, subId, callingPackage, callingFeatureId,
7117 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 return false;
7119 }
7120
7121 final long identity = Binder.clearCallingIdentity();
7122 try {
7123 CarrierConfigManager configManager =
7124 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007125 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7127 } finally {
7128 Binder.restoreCallingIdentity(identity);
7129 }
Andrew Leea1239f22015-03-02 17:44:07 -08007130 }
7131
7132 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007133 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007135 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 return false;
7137 }
7138
7139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 CarrierConfigManager configManager =
7142 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007143 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7145 } finally {
7146 Binder.restoreCallingIdentity(identity);
7147 }
Andrew Leea1239f22015-03-02 17:44:07 -08007148 }
7149
Andrew Lee9431b832015-03-09 18:46:45 -07007150 @Override
7151 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007152 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007153 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007154 }
7155
7156 @Override
7157 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 final long identity = Binder.clearCallingIdentity();
7159 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007160 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 } finally {
7162 Binder.restoreCallingIdentity(identity);
7163 }
Andrew Lee9431b832015-03-09 18:46:45 -07007164 }
7165
Hall Liuf6668912018-10-31 17:05:23 -07007166 /**
7167 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7168 * support for the feature and device firmware support.
7169 *
7170 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7171 */
7172 @Override
7173 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007175 final Phone phone = getPhone(subscriptionId);
7176 if (phone == null) {
7177 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7178 return false;
7179 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007181 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007182 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7183 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007184 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185 return isCarrierSupported && isDeviceSupported;
7186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188 }
Hall Liu98187582018-01-22 19:15:32 -08007189 }
7190
Hall Liuf6668912018-10-31 17:05:23 -07007191 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007192 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7193 * RTT setting, will return true if the device and carrier both support RTT.
7194 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007195 */
7196 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 final long identity = Binder.clearCallingIdentity();
7198 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007199 boolean isRttSupported = isRttSupported(subscriptionId);
7200 boolean isUserRttSettingOn = Settings.Secure.getInt(
7201 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7202 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7203 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7204 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205 } finally {
7206 Binder.restoreCallingIdentity(identity);
7207 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007208 }
7209
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007210 @Deprecated
7211 @Override
7212 public String getDeviceId(String callingPackage) {
7213 return getDeviceIdWithFeature(callingPackage, null);
7214 }
7215
Sanket Padawe7310cc72015-01-14 09:53:20 -08007216 /**
7217 * Returns the unique device ID of phone, for example, the IMEI for
7218 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7219 *
7220 * <p>Requires Permission:
7221 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7222 */
7223 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007224 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007225 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007226 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007227 return null;
7228 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007229 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007230 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007231 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007232 return null;
7233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234
7235 final long identity = Binder.clearCallingIdentity();
7236 try {
7237 return phone.getDeviceId();
7238 } finally {
7239 Binder.restoreCallingIdentity(identity);
7240 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007241 }
7242
Ping Sunc67b7c22016-03-02 19:16:45 +08007243 /**
7244 * {@hide}
7245 * Returns the IMS Registration Status on a particular subid
7246 *
7247 * @param subId
7248 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007249 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007250 Phone phone = getPhone(subId);
7251 if (phone != null) {
7252 return phone.isImsRegistered();
7253 } else {
7254 return false;
7255 }
7256 }
7257
Santos Cordon7a1885b2015-02-03 11:15:19 -08007258 @Override
7259 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 final long identity = Binder.clearCallingIdentity();
7261 try {
7262 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7263 } finally {
7264 Binder.restoreCallingIdentity(identity);
7265 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007266 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007267
Tyler Gunnf70ed162019-04-03 15:28:53 -07007268 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007269 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007270 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007272 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007273 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7274 }
7275 final long identity = Binder.clearCallingIdentity();
7276 try {
7277 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
7281 }
7282
7283 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007284 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007285 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7286 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007287 final long identity = Binder.clearCallingIdentity();
7288 try {
7289 Phone phone = getPhone(subscriptionId);
7290 if (phone == null) {
7291 return null;
7292 }
7293 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7294 } finally {
7295 Binder.restoreCallingIdentity(identity);
7296 }
7297 }
7298
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007299 /**
7300 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007301 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007302 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007303 final long identity = Binder.clearCallingIdentity();
7304 try {
7305 Phone phone = getPhone(subId);
7306 if (phone != null) {
7307 return phone.isWifiCallingEnabled();
7308 } else {
7309 return false;
7310 }
7311 } finally {
7312 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007313 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007314 }
7315
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007316 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007317 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007318 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007319 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007320 final long identity = Binder.clearCallingIdentity();
7321 try {
7322 Phone phone = getPhone(subId);
7323 if (phone != null) {
7324 return phone.isVideoEnabled();
7325 } else {
7326 return false;
7327 }
7328 } finally {
7329 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007330 }
7331 }
7332
7333 /**
7334 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7335 * defined in {@link ImsRegistrationImplBase}.
7336 */
7337 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007338 final long identity = Binder.clearCallingIdentity();
7339 try {
7340 Phone phone = getPhone(subId);
7341 if (phone != null) {
7342 return phone.getImsRegistrationTech();
7343 } else {
7344 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7345 }
7346 } finally {
7347 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007348 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007349 }
7350
Stuart Scott8eef64f2015-04-08 15:13:54 -07007351 @Override
7352 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007353 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007354 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7355 return;
7356 }
7357
Svet Ganovcc087f82015-05-12 20:35:54 -07007358 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007359
Svet Ganovcc087f82015-05-12 20:35:54 -07007360 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007361 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7362 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007363 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007364 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007365 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007366 Phone phone = getPhone(subId);
SongFerngWang51ee2b12021-05-27 22:44:54 +08007367 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007368 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7369 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007370 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007371 // There has been issues when Sms raw table somehow stores orphan
7372 // fragments. They lead to garbled message when new fragments come
7373 // in and combined with those stale ones. In case this happens again,
7374 // user can reset all network settings which will clean up this table.
7375 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007376 // Clean up IMS settings as well here.
7377 int slotId = getSlotIndex(subId);
7378 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7379 ImsManager.getInstance(mApp, slotId).factoryReset();
7380 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007381
7382 // Erase modem config if erase modem on network setting is enabled.
7383 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7384 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7385 if (configValue != null && Boolean.parseBoolean(configValue)) {
7386 sendEraseModemConfig(getDefaultPhone());
7387 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007388 } finally {
7389 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007390 }
7391 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007392
SongFerngWang51ee2b12021-05-27 22:44:54 +08007393 @VisibleForTesting
7394 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7395 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7396 return;
7397 }
7398 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7399 RILConstants.PREFERRED_NETWORK_MODE);
7400 SubscriptionManager.setSubscriptionProperty(subId,
7401 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7402 "user=" + defaultNetworkType);
7403 phone.loadAllowedNetworksFromSubscriptionDatabase();
7404 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7405 defaultNetworkType, null);
7406 }
7407
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007408 private void cleanUpSmsRawTable(Context context) {
7409 ContentResolver resolver = context.getContentResolver();
7410 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7411 resolver.delete(uri, null, null);
7412 }
7413
Narayan Kamath1c496c22015-04-16 14:40:19 +01007414 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007415 public String getSimLocaleForSubscriber(int subId) {
7416 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7417 final Phone phone = getPhone(subId);
7418 if (phone == null) {
7419 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007420 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007421 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 final long identity = Binder.clearCallingIdentity();
7423 try {
chen xu5d3637b2019-01-21 23:31:38 -08007424 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007425 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007426 if (info == null) {
7427 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7428 return null;
7429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430 // Try and fetch the locale from the carrier properties or from the SIM language
7431 // preferences (EF-PL and EF-LI)...
7432 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007434 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7435 if (localeFromDefaultSim != null) {
7436 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7437 if (DBG) log("Using locale from subId: " + subId + " locale: "
7438 + localeFromDefaultSim);
7439 return localeFromDefaultSim.toLanguageTag();
7440 } else {
7441 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 }
7443 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 // The SIM language preferences only store a language (e.g. fr = French), not an
7446 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7447 // the SIM and carrier preferences does not include a country we add the country
7448 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007449 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007451 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452 return mccLocale.toLanguageTag();
7453 }
7454
7455 if (DBG) log("No locale found - returning null");
7456 return null;
7457 } finally {
7458 Binder.restoreCallingIdentity(identity);
7459 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007460 }
7461
7462 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007463 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007464 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007465 }
7466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 /**
7468 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7469 */
7470 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007471 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007472 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007473 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007474
Chenjie Yu1ba97252018-01-11 18:16:20 -08007475 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liue8315982020-10-09 19:00:11 -07007476 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007477
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007478 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007479 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7480 * representing the state of the modem.
7481 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007482 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7483 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007484 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007485 */
7486 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007487 public void requestModemActivityInfo(ResultReceiver result) {
7488 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007489 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490
7491 final long identity = Binder.clearCallingIdentity();
7492 try {
sqian1a1be542020-03-05 11:37:28 -08007493 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 } finally {
7495 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007496 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007497 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007498
Siddharth Rayb8114062018-06-17 15:02:38 -07007499 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7500 // less than total activity duration.
7501 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7502 if (info == null) {
7503 return false;
7504 }
7505 int activityDurationMs =
Hall Liue8315982020-10-09 19:00:11 -07007506 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7507 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7508
Siddharth Rayb8114062018-06-17 15:02:38 -07007509 return (info.isValid()
7510 && (info.getSleepTimeMillis() <= activityDurationMs)
7511 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007512 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007513 && (totalTxTimeMs <= activityDurationMs));
7514 }
7515
Jack Yu85bd38a2015-11-09 11:34:32 -08007516 /**
7517 * {@hide}
7518 * Returns the service state information on specified subscription.
7519 */
7520 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007521 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7522 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007524 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007525 return null;
7526 }
7527
Hall Liuf19c44f2018-11-27 14:38:17 -08007528 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7529 LocationAccessPolicy.checkLocationPermission(mApp,
7530 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7531 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007532 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007533 .setCallingPid(Binder.getCallingPid())
7534 .setCallingUid(Binder.getCallingUid())
7535 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007536 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007537 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007538 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7539 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007540 .build());
7541
7542 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7543 LocationAccessPolicy.checkLocationPermission(mApp,
7544 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7545 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007546 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007547 .setCallingPid(Binder.getCallingPid())
7548 .setCallingUid(Binder.getCallingUid())
7549 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007550 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007551 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007552 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7553 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007554 .build());
7555 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7556 boolean hasFinePermission =
7557 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7558 boolean hasCoarsePermission =
7559 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 final long identity = Binder.clearCallingIdentity();
7562 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007563 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7564 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7565 Rlog.d(LOG_TAG,
7566 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7567 return null;
7568 }
7569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 final Phone phone = getPhone(subId);
7571 if (phone == null) {
7572 return null;
7573 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007574
Hall Liuf19c44f2018-11-27 14:38:17 -08007575 ServiceState ss = phone.getServiceState();
7576
7577 // Scrub out the location info in ServiceState depending on what level of access
7578 // the caller has.
7579 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007580 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7581 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007585 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007586
7587 /**
7588 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7589 *
7590 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7591 * voicemail ringtone.
7592 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7593 * PhoneAccount.
7594 */
7595 @Override
7596 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 final long identity = Binder.clearCallingIdentity();
7598 try {
7599 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7600 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007601 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
7607 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007608 }
7609
7610 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007611 * Sets the per-account voicemail ringtone.
7612 *
7613 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7614 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7615 *
7616 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7617 * voicemail ringtone.
7618 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7619 * PhoneAccount.
7620 */
7621 @Override
7622 public void setVoicemailRingtoneUri(String callingPackage,
7623 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007624 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007625 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007626 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7627 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7629 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7630 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007632
7633 final long identity = Binder.clearCallingIdentity();
7634 try {
7635 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7636 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007637 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007638 }
7639 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7640 } finally {
7641 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007642 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007643 }
7644
7645 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007646 * Returns whether vibration is set for voicemail notification in Phone settings.
7647 *
7648 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7649 * voicemail vibration setting.
7650 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7651 */
7652 @Override
7653 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 final long identity = Binder.clearCallingIdentity();
7655 try {
7656 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7657 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007658 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007661 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7662 } finally {
7663 Binder.restoreCallingIdentity(identity);
7664 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007665 }
7666
Youhan Wange64578a2016-05-02 15:32:42 -07007667 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007668 * Sets the per-account voicemail vibration.
7669 *
7670 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7671 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7672 *
7673 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7674 * voicemail vibration setting.
7675 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7676 * specific PhoneAccount.
7677 */
7678 @Override
7679 public void setVoicemailVibrationEnabled(String callingPackage,
7680 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007681 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007682 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007683 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7684 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7686 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7687 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007688 }
7689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 final long identity = Binder.clearCallingIdentity();
7691 try {
7692 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7693 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007694 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 }
7696 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007699 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007700 }
7701
7702 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007703 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7704 *
7705 * @throws SecurityException if the caller does not have the required permission
7706 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007707 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007708 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007709 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007710 }
7711
7712 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007713 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7714 * permission.
7715 *
7716 * @throws SecurityException if the caller does not have the required permission
7717 */
7718 private void enforceSendSmsPermission() {
7719 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7720 }
7721
7722 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007723 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007724 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007725 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007726 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007727 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728 final long identity = Binder.clearCallingIdentity();
7729 try {
7730 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007731 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 if (componentName == null) {
7733 throw new SecurityException(
7734 "Caller not current active visual voicemail package[null]");
7735 }
7736 String vvmPackage = componentName.getPackageName();
7737 if (!callingPackage.equals(vvmPackage)) {
7738 throw new SecurityException("Caller not current active visual voicemail package["
7739 + vvmPackage + "]");
7740 }
7741 } finally {
7742 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007743 }
7744 }
7745
7746 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007747 * Return the application ID for the app type.
7748 *
7749 * @param subId the subscription ID that this request applies to.
7750 * @param appType the uicc app type.
7751 * @return Application ID for specificied app type, or null if no uicc.
7752 */
7753 @Override
7754 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007755 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007756 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757
7758 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007759 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 if (phone == null) {
7761 return null;
7762 }
7763 String aid = null;
7764 try {
7765 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7766 .getApplicationByType(appType).getAid();
7767 } catch (Exception e) {
7768 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7769 }
7770 return aid;
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007773 }
Youhan Wange64578a2016-05-02 15:32:42 -07007774 }
7775
Youhan Wang4001d252016-05-11 10:29:41 -07007776 /**
7777 * Return the Electronic Serial Number.
7778 *
7779 * @param subId the subscription ID that this request applies to.
7780 * @return ESN or null if error.
7781 */
7782 @Override
7783 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007784 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007785 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786
7787 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007788 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007789 if (phone == null) {
7790 return null;
7791 }
7792 String esn = null;
7793 try {
7794 esn = phone.getEsn();
7795 } catch (Exception e) {
7796 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7797 }
7798 return esn;
7799 } finally {
7800 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007801 }
Youhan Wang4001d252016-05-11 10:29:41 -07007802 }
7803
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007804 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007805 * Return the Preferred Roaming List Version.
7806 *
7807 * @param subId the subscription ID that this request applies to.
7808 * @return PRLVersion or null if error.
7809 */
7810 @Override
7811 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007812 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007813 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814
7815 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007816 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 if (phone == null) {
7818 return null;
7819 }
7820 String cdmaPrlVersion = null;
7821 try {
7822 cdmaPrlVersion = phone.getCdmaPrlVersion();
7823 } catch (Exception e) {
7824 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7825 }
7826 return cdmaPrlVersion;
7827 } finally {
7828 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007829 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007830 }
7831
7832 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007833 * Get snapshot of Telephony histograms
7834 * @return List of Telephony histograms
7835 * @hide
7836 */
7837 @Override
7838 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7840 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841
7842 final long identity = Binder.clearCallingIdentity();
7843 try {
7844 return RIL.getTelephonyRILTimingHistograms();
7845 } finally {
7846 Binder.restoreCallingIdentity(identity);
7847 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007848 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007849
7850 /**
7851 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007852 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7853 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007854 * Require system privileges. In the future we may add this to carrier APIs.
7855 *
Michele Berionne482f8202018-11-27 18:57:59 -08007856 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007857 */
7858 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007859 @TelephonyManager.SetCarrierRestrictionResult
7860 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007861 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007862 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007863
Michele Berionne482f8202018-11-27 18:57:59 -08007864 if (carrierRestrictionRules == null) {
7865 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007866 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 final long identity = Binder.clearCallingIdentity();
7869 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007870 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007871 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007872 } finally {
7873 Binder.restoreCallingIdentity(identity);
7874 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007875 }
7876
7877 /**
7878 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007879 * Get the allowed carrier list and the excluded carrier list, including the priority between
7880 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007881 * Require system privileges. In the future we may add this to carrier APIs.
7882 *
Michele Berionne482f8202018-11-27 18:57:59 -08007883 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007884 */
7885 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007886 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007887 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007889
7890 final long identity = Binder.clearCallingIdentity();
7891 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007892 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7893 if (response instanceof CarrierRestrictionRules) {
7894 return (CarrierRestrictionRules) response;
7895 }
7896 // Response is an Exception of some kind,
7897 // which is signalled to the user as a NULL retval
7898 return null;
7899 } catch (Exception e) {
7900 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7901 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007902 } finally {
7903 Binder.restoreCallingIdentity(identity);
7904 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007905 }
7906
fionaxu59545b42016-05-25 15:53:37 -07007907 /**
fionaxu59545b42016-05-25 15:53:37 -07007908 * Action set from carrier signalling broadcast receivers to enable/disable radio
7909 * @param subId the subscription ID that this action applies to.
7910 * @param enabled control enable or disable radio.
7911 * {@hide}
7912 */
7913 @Override
7914 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7915 enforceModifyPermission();
7916 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917
7918 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007919 if (phone == null) {
7920 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7921 return;
7922 }
7923 try {
7924 phone.carrierActionSetRadioEnabled(enabled);
7925 } catch (Exception e) {
7926 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007927 } finally {
7928 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007929 }
7930 }
7931
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007932 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007933 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7934 * network status based on which carrier apps could apply actions accordingly,
7935 * enable/disable default url handler for example.
7936 *
7937 * @param subId the subscription ID that this action applies to.
7938 * @param report control start/stop reporting the default network status.
7939 * {@hide}
7940 */
7941 @Override
7942 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7943 enforceModifyPermission();
7944 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007945
7946 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007947 if (phone == null) {
7948 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7949 return;
7950 }
7951 try {
7952 phone.carrierActionReportDefaultNetworkStatus(report);
7953 } catch (Exception e) {
7954 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 } finally {
7956 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007957 }
7958 }
7959
7960 /**
fionaxud9622282017-07-17 17:51:30 -07007961 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7962 * @param subId the subscription ID that this action applies to.
7963 * {@hide}
7964 */
7965 @Override
7966 public void carrierActionResetAll(int subId) {
7967 enforceModifyPermission();
7968 final Phone phone = getPhone(subId);
7969 if (phone == null) {
7970 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7971 return;
7972 }
7973 try {
7974 phone.carrierActionResetAll();
7975 } catch (Exception e) {
7976 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7977 }
7978 }
7979
7980 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007981 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7982 * bug report is being generated.
7983 */
7984 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007985 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007986 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7987 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007988 writer.println("Permission Denial: can't dump Phone from pid="
7989 + Binder.getCallingPid()
7990 + ", uid=" + Binder.getCallingUid()
7991 + "without permission "
7992 + android.Manifest.permission.DUMP);
7993 return;
7994 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007995 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007996 }
Jack Yueb89b242016-06-22 13:27:47 -07007997
Brad Ebingerdac2f002018-04-03 15:17:52 -07007998 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007999 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8000 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8001 @NonNull String[] args) {
8002 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8003 this, in.getFileDescriptor(), out.getFileDescriptor(),
8004 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008005 }
8006
Jack Yueb89b242016-06-22 13:27:47 -07008007 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008008 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07008009 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008010 * @param reason the reason the data enable change is taking place
8011 * @param enabled True if enabling the data, otherwise disabling.
8012 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008013 */
8014 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07008015 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008016 boolean enabled) {
8017 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8018 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8019 try {
8020 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07008021 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008022 } catch (SecurityException se) {
8023 enforceModifyPermission();
8024 }
8025 } else {
8026 enforceModifyPermission();
8027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008028
8029 final long identity = Binder.clearCallingIdentity();
8030 try {
8031 Phone phone = getPhone(subId);
8032 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008033 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8034 phone.carrierActionSetMeteredApnsEnabled(enabled);
8035 } else {
8036 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008038 }
8039 } finally {
8040 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008041 }
8042 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008043
8044 /**
8045 * Get Client request stats
8046 * @return List of Client Request Stats
8047 * @hide
8048 */
8049 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008050 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8051 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008053 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008054 return null;
8055 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008056 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008057
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008058 final long identity = Binder.clearCallingIdentity();
8059 try {
8060 if (phone != null) {
8061 return phone.getClientRequestStats();
8062 }
8063
8064 return null;
8065 } finally {
8066 Binder.restoreCallingIdentity(identity);
8067 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008068 }
8069
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008070 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008071 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008072 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008073 }
Jack Yueb4124c2017-02-16 15:32:43 -08008074
8075 /**
Grace Chen70990072017-03-24 17:21:30 -07008076 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008077 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008078 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008079 * @param state State of SIM (power down, power up, pass through)
8080 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8081 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8082 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008083 *
8084 **/
8085 @Override
Grace Chen70990072017-03-24 17:21:30 -07008086 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008087 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008088 Phone phone = PhoneFactory.getPhone(slotIndex);
8089
vagdeviaf9a5b92018-08-15 16:01:53 -07008090 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008092 final long identity = Binder.clearCallingIdentity();
8093 try {
8094 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008095 phone.setSimPowerState(state, null, workSource);
8096 }
8097 } finally {
8098 Binder.restoreCallingIdentity(identity);
8099 }
8100 }
8101
8102 /**
8103 * Set SIM card power state.
8104 *
8105 * @param slotIndex SIM slot id.
8106 * @param state State of SIM (power down, power up, pass through)
8107 * @param callback callback to trigger after success or failure
8108 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8109 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8110 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8111 *
8112 **/
8113 @Override
8114 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8115 IIntegerConsumer callback) {
8116 enforceModifyPermission();
8117 Phone phone = PhoneFactory.getPhone(slotIndex);
8118
8119 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8120
8121 final long identity = Binder.clearCallingIdentity();
8122 try {
8123 if (phone != null) {
8124 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8125 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126 }
8127 } finally {
8128 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008129 }
8130 }
Shuo Qiandd210312017-04-12 22:11:33 +00008131
Tyler Gunn65d45c22017-06-05 11:22:26 -07008132 private boolean isUssdApiAllowed(int subId) {
8133 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008134 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008135 if (configManager == null) {
8136 return false;
8137 }
8138 PersistableBundle pb = configManager.getConfigForSubId(subId);
8139 if (pb == null) {
8140 return false;
8141 }
8142 return pb.getBoolean(
8143 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8144 }
8145
Shuo Qiandd210312017-04-12 22:11:33 +00008146 /**
8147 * Check if phone is in emergency callback mode
8148 * @return true if phone is in emergency callback mode
8149 * @param subId sub id
8150 */
goneil9c5f4872017-12-05 14:07:56 -08008151 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008152 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008153 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008154 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155
8156 final long identity = Binder.clearCallingIdentity();
8157 try {
8158 if (phone != null) {
8159 return phone.isInEcm();
8160 } else {
8161 return false;
8162 }
8163 } finally {
8164 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008165 }
8166 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008167
8168 /**
8169 * Get the current signal strength information for the given subscription.
8170 * Because this information is not updated when the device is in a low power state
8171 * it should not be relied-upon to be current.
8172 * @param subId Subscription index
8173 * @return the most recent cached signal strength info from the modem
8174 */
8175 @Override
8176 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008177 final long identity = Binder.clearCallingIdentity();
8178 try {
8179 Phone p = getPhone(subId);
8180 if (p == null) {
8181 return null;
8182 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008183
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184 return p.getSignalStrength();
8185 } finally {
8186 Binder.restoreCallingIdentity(identity);
8187 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008188 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008189
Pengquan Meng77b7f132018-08-22 14:49:57 -07008190 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008191 * Get the current modem radio state for the given slot.
8192 * @param slotIndex slot index.
8193 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008194 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008195 * @return the current radio power state from the modem
8196 */
8197 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008198 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008199 Phone phone = PhoneFactory.getPhone(slotIndex);
8200 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008201 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8202 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008203 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8204 }
8205
8206 final long identity = Binder.clearCallingIdentity();
8207 try {
8208 return phone.getRadioPowerState();
8209 } finally {
8210 Binder.restoreCallingIdentity(identity);
8211 }
8212 }
8213 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8214 }
8215
8216 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008217 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8218 *
8219 * <p>Requires one of the following permissions:
8220 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8221 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8222 * privileges.
8223 *
8224 * @param subId subscription id
8225 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8226 * {@code false}.
8227 */
8228 @Override
8229 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008230 try {
8231 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8232 null);
8233 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008234 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008235 mApp, subId, "isDataRoamingEnabled");
8236 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008237
Pengquan Menga1bb6272018-09-06 09:59:22 -07008238 boolean isEnabled = false;
8239 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008240 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008241 Phone phone = getPhone(subId);
8242 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008243 } finally {
8244 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008245 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008246 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008247 }
8248
8249
8250 /**
8251 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8252 *
8253 * <p> Requires permission:
8254 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8255 * privileges.
8256 *
8257 * @param subId subscription id
8258 * @param isEnabled {@code true} means enable, {@code false} means disable.
8259 */
8260 @Override
8261 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008262 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8263 mApp, subId, "setDataRoamingEnabled");
8264
Pengquan Menga1bb6272018-09-06 09:59:22 -07008265 final long identity = Binder.clearCallingIdentity();
8266 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008267 Phone phone = getPhone(subId);
8268 if (phone != null) {
8269 phone.setDataRoamingEnabled(isEnabled);
8270 }
8271 } finally {
8272 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008273 }
8274 }
8275
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008276 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008277 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008278 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008279 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008280 mApp, subId, "isManualNetworkSelectionAllowed");
8281
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008282 boolean isAllowed = true;
8283 final long identity = Binder.clearCallingIdentity();
8284 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008285 Phone phone = getPhone(subId);
8286 if (phone != null) {
8287 isAllowed = phone.isCspPlmnEnabled();
8288 }
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
8291 }
8292 return isAllowed;
8293 }
8294
8295 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008296 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008297 // Verify that tha callingPackage belongs to the calling UID
8298 mApp.getSystemService(AppOpsManager.class)
8299 .checkPackage(Binder.getCallingUid(), callingPackage);
8300
Jordan Liu1e142fc2019-04-22 15:10:43 -07008301 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008302 try {
8303 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008304 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008305 } catch (SecurityException e) {
8306 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8307 // has carrier privileges on an active UICC
8308 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8309 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008310 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008311 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008312 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008313
8314 final long identity = Binder.clearCallingIdentity();
8315 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008316 UiccController uiccController = UiccController.getInstance();
8317 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008318 if (hasReadPermission) {
8319 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008320 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008321
8322 // Remove private info if the caller doesn't have access
8323 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8324 for (UiccCardInfo cardInfo : cardInfos) {
8325 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8326 // is available
8327 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8328 if (card == null || card.getUiccProfile() == null) {
8329 // assume no access if the card or profile is unavailable
8330 filteredInfos.add(cardInfo.getUnprivileged());
8331 continue;
8332 }
8333 UiccProfile profile = card.getUiccProfile();
8334 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8335 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8336 filteredInfos.add(cardInfo);
8337 } else {
8338 filteredInfos.add(cardInfo.getUnprivileged());
8339 }
8340 }
8341 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008342 } finally {
8343 Binder.restoreCallingIdentity(identity);
8344 }
8345 }
8346
8347 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008348 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008349 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008351 final long identity = Binder.clearCallingIdentity();
8352 try {
8353 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8354 if (slots == null) {
8355 Rlog.i(LOG_TAG, "slots is null.");
8356 return null;
8357 }
8358
8359 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8360 for (int i = 0; i < slots.length; i++) {
8361 UiccSlot slot = slots[i];
8362 if (slot == null) {
8363 continue;
8364 }
8365
Jordan Liu7be7e652019-05-06 18:55:02 +00008366 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367 UiccCard card = slot.getUiccCard();
8368 if (card != null) {
8369 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008370 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008371 cardId = slot.getEid();
8372 if (TextUtils.isEmpty(cardId)) {
8373 cardId = slot.getIccId();
8374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008375 }
8376
Jordan Liu857451f2019-05-09 16:35:35 -07008377 if (cardId != null) {
8378 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8379 // if cardId is an EID, it's all digits so this is fine
8380 cardId = IccUtils.stripTrailingFs(cardId);
8381 }
8382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008383 int cardState = 0;
8384 switch (slot.getCardState()) {
8385 case CARDSTATE_ABSENT:
8386 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8387 break;
8388 case CARDSTATE_PRESENT:
8389 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8390 break;
8391 case CARDSTATE_ERROR:
8392 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8393 break;
8394 case CARDSTATE_RESTRICTED:
8395 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8396 break;
8397 default:
8398 break;
8399
8400 }
8401
8402 infos[i] = new UiccSlotInfo(
8403 slot.isActive(),
8404 slot.isEuicc(),
8405 cardId,
8406 cardState,
8407 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008408 slot.isExtendedApduSupported(),
8409 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008410 }
8411 return infos;
8412 } finally {
8413 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008414 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008415 }
8416
8417 @Override
8418 public boolean switchSlots(int[] physicalSlots) {
8419 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008420
8421 final long identity = Binder.clearCallingIdentity();
8422 try {
8423 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008427 }
Jack Yu4c988042018-02-27 15:30:01 -08008428
8429 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008430 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 return UiccController.getInstance().getCardIdForDefaultEuicc();
8434 } finally {
8435 Binder.restoreCallingIdentity(identity);
8436 }
8437 }
8438
Pengquan Meng85728fb2018-03-12 16:31:21 -07008439 /**
goneil47ffb6e2018-04-06 15:40:58 -07008440 * A test API to reload the UICC profile.
8441 *
8442 * <p>Requires that the calling app has permission
8443 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8444 * @hide
8445 */
8446 @Override
8447 public void refreshUiccProfile(int subId) {
8448 enforceModifyPermission();
8449
8450 final long identity = Binder.clearCallingIdentity();
8451 try {
8452 Phone phone = getPhone(subId);
8453 if (phone == null) {
8454 return;
8455 }
8456 UiccCard uiccCard = phone.getUiccCard();
8457 if (uiccCard == null) {
8458 return;
8459 }
8460 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8461 if (uiccProfile == null) {
8462 return;
8463 }
8464 uiccProfile.refresh();
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
8467 }
8468 }
8469
8470 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008471 * Returns false if the mobile data is disabled by default, otherwise return true.
8472 */
8473 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008474 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008475 }
8476
8477 /**
8478 * Returns true if the data roaming is enabled by default, i.e the system property
8479 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8480 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8481 */
8482 private boolean getDefaultDataRoamingEnabled(int subId) {
8483 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008484 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008485 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008486 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8487 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8488 return isDataRoamingEnabled;
8489 }
8490
8491 /**
8492 * Returns the default network type for the given {@code subId}, if the default network type is
8493 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8494 */
8495 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008496 List<Integer> list = TelephonyProperties.default_network();
8497 int phoneId = mSubscriptionController.getPhoneId(subId);
8498 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8499 return list.get(phoneId);
8500 }
8501 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008502 }
fionaxua13278b2018-03-21 00:08:13 -07008503
8504 @Override
8505 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008506 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008508
8509 final long identity = Binder.clearCallingIdentity();
8510 try {
8511 final Phone phone = getPhone(subId);
8512 if (phone == null) {
8513 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8514 return;
8515 }
chen xueaba88a2019-03-15 13:15:10 -07008516 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8517 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008518 if (carrierPrivilegeRules == null) {
8519 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8520 } else {
8521 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008523 } finally {
8524 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008525 }
fionaxua13278b2018-03-21 00:08:13 -07008526 }
8527
8528 @Override
8529 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008530 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008531
8532 final long identity = Binder.clearCallingIdentity();
8533 try {
8534 final Phone phone = getPhone(subId);
8535 if (phone == null) {
8536 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8537 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8538 }
8539 return phone.getCarrierIdListVersion();
8540 } finally {
8541 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008542 }
fionaxua13278b2018-03-21 00:08:13 -07008543 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008544
8545 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008546 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8547 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008548 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008549 mApp, subId, callingPackage, callingFeatureId,
8550 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008551 return -1;
8552 }
8553
8554 final long identity = Binder.clearCallingIdentity();
8555 try {
8556 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8557 } finally {
8558 Binder.restoreCallingIdentity(identity);
8559 }
8560 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008561
8562 @Override
8563 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008564 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008565 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008566 mApp, subId, "getCdmaRoamingMode");
8567
8568 final long identity = Binder.clearCallingIdentity();
8569 try {
8570 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8571 } finally {
8572 Binder.restoreCallingIdentity(identity);
8573 }
8574 }
8575
8576 @Override
8577 public boolean setCdmaRoamingMode(int subId, int mode) {
8578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8579 mApp, subId, "setCdmaRoamingMode");
8580
8581 final long identity = Binder.clearCallingIdentity();
8582 try {
8583 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8584 } finally {
8585 Binder.restoreCallingIdentity(identity);
8586 }
8587 }
8588
8589 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008590 public int getCdmaSubscriptionMode(int subId) {
8591 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008592 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008593 mApp, subId, "getCdmaSubscriptionMode");
8594
8595 final long identity = Binder.clearCallingIdentity();
8596 try {
8597 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8598 } finally {
8599 Binder.restoreCallingIdentity(identity);
8600 }
8601 }
8602
8603 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008604 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8606 mApp, subId, "setCdmaSubscriptionMode");
8607
8608 final long identity = Binder.clearCallingIdentity();
8609 try {
8610 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8611 } finally {
8612 Binder.restoreCallingIdentity(identity);
8613 }
8614 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008615
sqianc5eccab2018-10-19 18:46:41 -07008616 @Override
sqian8c685422019-02-22 15:55:18 -08008617 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008618 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008619 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008620 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8621 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008622 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8623 }
8624 final long identity = Binder.clearCallingIdentity();
8625 try {
sqian854d44b2018-12-12 16:48:18 -08008626 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8627 for (Phone phone: PhoneFactory.getPhones()) {
8628 if (phone.getEmergencyNumberTracker() != null
8629 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8630 emergencyNumberListInternal.put(
8631 phone.getSubId(),
8632 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8633 }
sqian11b7a0e2018-12-05 18:48:28 -08008634 }
sqian854d44b2018-12-12 16:48:18 -08008635 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008636 } finally {
8637 Binder.restoreCallingIdentity(identity);
8638 }
sqianc5eccab2018-10-19 18:46:41 -07008639 }
8640
8641 @Override
sqian8c685422019-02-22 15:55:18 -08008642 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008643 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008644 if (!exactMatch) {
8645 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008646 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008647 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008648 }
8649 final long identity = Binder.clearCallingIdentity();
8650 try {
sqian854d44b2018-12-12 16:48:18 -08008651 for (Phone phone: PhoneFactory.getPhones()) {
8652 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008653 && phone.getEmergencyNumberTracker()
8654 .isEmergencyNumber(number, exactMatch)) {
8655 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008656 }
sqian11b7a0e2018-12-05 18:48:28 -08008657 }
8658 return false;
8659 } finally {
8660 Binder.restoreCallingIdentity(identity);
8661 }
8662 }
8663
sqianf4ca7ed2019-01-15 18:32:07 -08008664 /**
Shuo Qian479dd9e2021-02-22 18:32:21 -08008665 * Start emergency callback mode for GsmCdmaPhone for testing.
8666 */
8667 @Override
8668 public void startEmergencyCallbackMode() {
8669 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8670 "startEmergencyCallbackMode");
8671 enforceModifyPermission();
8672 final long identity = Binder.clearCallingIdentity();
8673 try {
8674 for (Phone phone : PhoneFactory.getPhones()) {
8675 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8676 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8677 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8678 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8679 gsmCdmaPhone.obtainMessage(
8680 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8681 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8682 }
8683 }
8684 } finally {
8685 Binder.restoreCallingIdentity(identity);
8686 }
8687 }
8688
8689 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008690 * Update emergency number list for test mode.
8691 */
8692 @Override
8693 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8694 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8695 "updateEmergencyNumberListTestMode");
8696
8697 final long identity = Binder.clearCallingIdentity();
8698 try {
8699 for (Phone phone: PhoneFactory.getPhones()) {
8700 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8701 if (tracker != null) {
8702 tracker.executeEmergencyNumberTestModeCommand(action, num);
8703 }
8704 }
8705 } finally {
8706 Binder.restoreCallingIdentity(identity);
8707 }
8708 }
8709
8710 /**
8711 * Get the full emergency number list for test mode.
8712 */
8713 @Override
8714 public List<String> getEmergencyNumberListTestMode() {
8715 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8716 "getEmergencyNumberListTestMode");
8717
8718 final long identity = Binder.clearCallingIdentity();
8719 try {
8720 Set<String> emergencyNumbers = new HashSet<>();
8721 for (Phone phone: PhoneFactory.getPhones()) {
8722 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8723 if (tracker != null) {
8724 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8725 emergencyNumbers.add(num.getNumber());
8726 }
8727 }
8728 }
8729 return new ArrayList<>(emergencyNumbers);
8730 } finally {
8731 Binder.restoreCallingIdentity(identity);
8732 }
8733 }
8734
chen xud6b45bd2018-10-30 22:27:10 -07008735 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008736 public int getEmergencyNumberDbVersion(int subId) {
8737 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8738
8739 final long identity = Binder.clearCallingIdentity();
8740 try {
8741 final Phone phone = getPhone(subId);
8742 if (phone == null) {
8743 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8744 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8745 }
8746 return phone.getEmergencyNumberDbVersion();
8747 } finally {
8748 Binder.restoreCallingIdentity(identity);
8749 }
8750 }
8751
8752 @Override
8753 public void notifyOtaEmergencyNumberDbInstalled() {
8754 enforceModifyPermission();
8755
8756 final long identity = Binder.clearCallingIdentity();
8757 try {
8758 for (Phone phone: PhoneFactory.getPhones()) {
8759 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8760 if (tracker != null) {
8761 tracker.updateOtaEmergencyNumberDatabase();
8762 }
8763 }
8764 } finally {
8765 Binder.restoreCallingIdentity(identity);
8766 }
8767 }
8768
8769 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008770 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008771 enforceActiveEmergencySessionPermission();
8772
8773 final long identity = Binder.clearCallingIdentity();
8774 try {
8775 for (Phone phone: PhoneFactory.getPhones()) {
8776 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8777 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008778 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8779 }
8780 }
8781 } finally {
8782 Binder.restoreCallingIdentity(identity);
8783 }
8784 }
8785
8786 @Override
8787 public void resetOtaEmergencyNumberDbFilePath() {
8788 enforceActiveEmergencySessionPermission();
8789
8790 final long identity = Binder.clearCallingIdentity();
8791 try {
8792 for (Phone phone: PhoneFactory.getPhones()) {
8793 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8794 if (tracker != null) {
8795 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008796 }
8797 }
8798 } finally {
8799 Binder.restoreCallingIdentity(identity);
8800 }
8801 }
8802
8803 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008804 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8805 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8806 Phone phone = getPhone(subId);
8807 if (phone == null) {
8808 return null;
8809 }
8810 final long identity = Binder.clearCallingIdentity();
8811 try {
8812 UiccProfile profile = UiccController.getInstance()
8813 .getUiccProfileForPhone(phone.getPhoneId());
8814 if (profile != null) {
8815 return profile.getCertsFromCarrierPrivilegeAccessRules();
8816 }
8817 } finally {
8818 Binder.restoreCallingIdentity(identity);
8819 }
8820 return null;
8821 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008822
8823 /**
8824 * Enable or disable a modem stack.
8825 */
8826 @Override
8827 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8828 enforceModifyPermission();
8829
8830 final long identity = Binder.clearCallingIdentity();
8831 try {
8832 Phone phone = PhoneFactory.getPhone(slotIndex);
8833 if (phone == null) {
8834 return false;
8835 } else {
8836 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8837 }
8838 } finally {
8839 Binder.restoreCallingIdentity(identity);
8840 }
8841 }
Michelecea4cf22018-12-21 15:00:11 -08008842
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008843 /**
8844 * Whether a modem stack is enabled or not.
8845 */
8846 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008847 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8848 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008849 Phone phone = PhoneFactory.getPhone(slotIndex);
8850 if (phone == null) return false;
8851
8852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008853 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8854 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008855 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8856 }
8857
8858 final long identity = Binder.clearCallingIdentity();
8859 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008860 try {
8861 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8862 } catch (NoSuchElementException ex) {
8863 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8864 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008865 } finally {
8866 Binder.restoreCallingIdentity(identity);
8867 }
8868 }
8869
Michelecea4cf22018-12-21 15:00:11 -08008870 @Override
Michele0ea7d782019-03-19 14:58:42 -07008871 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008872 enforceModifyPermission();
8873
8874 final long identity = Binder.clearCallingIdentity();
8875 try {
8876 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008877 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008878 .commit();
8879 } finally {
8880 Binder.restoreCallingIdentity(identity);
8881 }
8882 }
8883
8884 @Override
Michele0ea7d782019-03-19 14:58:42 -07008885 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008886 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008888 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8889 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008890 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008891 }
Michelecea4cf22018-12-21 15:00:11 -08008892
8893 final long identity = Binder.clearCallingIdentity();
8894 try {
Michele0ea7d782019-03-19 14:58:42 -07008895 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008896 } finally {
8897 Binder.restoreCallingIdentity(identity);
8898 }
8899 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008900
Michele0ea7d782019-03-19 14:58:42 -07008901 @TelephonyManager.IsMultiSimSupportedResult
8902 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008903 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8904 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8905 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008906 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8907 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008908 }
8909 // Check if the hardware supports multisim functionality. If usage of multisim is not
8910 // supported by the modem, indicate that it is restricted.
8911 PhoneCapability staticCapability =
8912 mPhoneConfigurationManager.getStaticPhoneCapability();
8913 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008914 loge("isMultiSimSupportedInternal: no static configuration available");
8915 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008916 }
SongFerngWang2c4309d2021-01-17 21:51:44 +08008917 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008918 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8919 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008920 }
8921 // Check if support of multiple SIMs is restricted by carrier
8922 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008923 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008924 }
8925
Michele0ea7d782019-03-19 14:58:42 -07008926 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008927 }
8928
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008929 /**
8930 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008931 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8932 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8933 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008934 * @param numOfSims number of active sims we want to switch to
8935 */
8936 @Override
8937 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008938 if (numOfSims == 1) {
8939 enforceModifyPermission();
8940 } else {
8941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8942 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8943 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008944 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008945
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008946 try {
Michele30b57b22019-03-01 12:01:14 -08008947 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008948 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008949 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8950 return;
8951 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008952 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8953 } finally {
8954 Binder.restoreCallingIdentity(identity);
8955 }
8956 }
8957
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008958 @Override
8959 public boolean isApplicationOnUicc(int subId, int appType) {
8960 enforceReadPrivilegedPermission("isApplicationOnUicc");
8961 Phone phone = getPhone(subId);
8962 if (phone == null) {
8963 return false;
8964 }
8965 final long identity = Binder.clearCallingIdentity();
8966 try {
8967 UiccCard uiccCard = phone.getUiccCard();
8968 if (uiccCard == null) {
8969 return false;
8970 }
8971 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8972 if (uiccProfile == null) {
8973 return false;
8974 }
8975 if (TelephonyManager.APPTYPE_SIM <= appType
8976 && appType <= TelephonyManager.APPTYPE_ISIM) {
8977 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8978 }
8979 return false;
8980 } finally {
8981 Binder.restoreCallingIdentity(identity);
8982 }
8983 }
8984
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008985 /**
chen xub4baa772019-04-03 10:23:41 -07008986 * Get whether making changes to modem configurations will trigger reboot.
8987 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008988 */
8989 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008990 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8991 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008993 mApp, subId, callingPackage, callingFeatureId,
8994 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008995 return false;
8996 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008997 final long identity = Binder.clearCallingIdentity();
8998 try {
8999 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9000 } finally {
9001 Binder.restoreCallingIdentity(identity);
9002 }
9003 }
9004
Nathan Harold29f5f052019-02-15 13:41:57 -08009005 private void updateModemStateMetrics() {
9006 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9007 // TODO: check the state for each modem if the api is ready.
9008 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9009 }
9010
Pengquan Meng3889a572019-01-23 11:16:29 -08009011 @Override
9012 public int[] getSlotsMapping() {
9013 enforceReadPrivilegedPermission("getSlotsMapping");
9014
9015 final long identity = Binder.clearCallingIdentity();
9016 try {
9017 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9018 // All logical slots should have a mapping to a physical slot.
9019 int[] logicalSlotsMapping = new int[phoneCount];
9020 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9021 for (int i = 0; i < slotInfos.length; i++) {
9022 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9023 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9024 }
9025 }
9026 return logicalSlotsMapping;
9027 } finally {
9028 Binder.restoreCallingIdentity(identity);
9029 }
9030 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009031
9032 /**
9033 * Get the IRadio HAL Version
9034 */
9035 @Override
9036 public int getRadioHalVersion() {
9037 Phone phone = getDefaultPhone();
9038 if (phone == null) return -1;
9039 HalVersion hv = phone.getHalVersion();
9040 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9041 return hv.major * 100 + hv.minor;
9042 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009043
9044 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08009045 * Get the current calling package name.
9046 * @return the current calling package name
9047 */
9048 @Override
9049 public String getCurrentPackageName() {
9050 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9051 }
9052
9053 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009054 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9055 * corresponding network requests on a subId.
9056 *
9057 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009058 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009059 * 2) APN is un-metered for this subscription, or
9060 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07009061 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009062 *
9063 * @return whether data is allowed for a apn type.
9064 *
9065 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009066 */
9067 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009068 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009069 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9070 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009071
9072 // Now that all security checks passes, perform the operation as ourselves.
9073 final long identity = Binder.clearCallingIdentity();
9074 try {
9075 Phone phone = getPhone(subId);
9076 if (phone == null) return false;
9077
Jack Yu41407ee2019-05-13 16:54:09 -07009078 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009079 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9080 } finally {
9081 Binder.restoreCallingIdentity(identity);
9082 }
9083 }
9084
9085 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009086 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009087 enforceReadPrivilegedPermission("isApnMetered");
9088
9089 // Now that all security checks passes, perform the operation as ourselves.
9090 final long identity = Binder.clearCallingIdentity();
9091 try {
9092 Phone phone = getPhone(subId);
9093 if (phone == null) return true; // By default return true.
9094
Jack Yu41407ee2019-05-13 16:54:09 -07009095 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009100
9101 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009102 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9103 int subscriptionId, IBooleanConsumer resultCallback) {
9104 enforceModifyPermission();
9105 long token = Binder.clearCallingIdentity();
9106 try {
9107 Phone phone = getPhone(subscriptionId);
9108 if (phone == null) {
9109 try {
9110 if (resultCallback != null) {
9111 resultCallback.accept(false);
9112 }
9113 } catch (RemoteException e) {
9114 // ignore
9115 }
9116 return;
9117 }
9118 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9119 Pair.create(specifiers, (x) -> {
9120 try {
9121 if (resultCallback != null) {
9122 resultCallback.accept(x);
9123 }
9124 } catch (RemoteException e) {
9125 // ignore
9126 }
9127 });
9128 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9129 } finally {
9130 Binder.restoreCallingIdentity(token);
9131 }
9132 }
9133
9134 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009135 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9136 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07009137 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08009138 mApp, subId, "getSystemSelectionChannels");
9139 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9140 final long identity = Binder.clearCallingIdentity();
9141 try {
Sarah Chin58691872021-03-13 03:17:40 -08009142 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9143 if (result instanceof IllegalStateException) {
9144 throw (IllegalStateException) result;
9145 }
9146 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chincc055732020-11-18 13:39:35 -08009147 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9148 return specifiers;
9149 } finally {
9150 Binder.restoreCallingIdentity(identity);
9151 }
9152 }
9153
9154 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009155 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009156 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009157 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9158 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9159 if (iccRecords == null) {
9160 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9161 return false;
9162 }
9163 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9164 }
9165
9166 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009167 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9168 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009169 if (callingPackage == null) {
9170 callingPackage = getCurrentPackageName();
9171 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009172 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9173 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009174 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9175 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009176 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9177 }
9178 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9179 Intent intent = new Intent();
9180 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9181 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9182 // Bring up choose default SMS subscription dialog right now
9183 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9184 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9185 mApp.startActivity(intent);
9186 }
chen xud5ca2d52019-05-28 15:20:57 -07009187
9188 @Override
9189 public String getMmsUAProfUrl(int subId) {
9190 //TODO investigate if this API should require proper permission check in R b/133791609
9191 final long identity = Binder.clearCallingIdentity();
9192 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009193 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9194 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9195 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9196 return carrierUAProfUrl;
9197 }
chen xud5ca2d52019-05-28 15:20:57 -07009198 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9199 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9200 } finally {
9201 Binder.restoreCallingIdentity(identity);
9202 }
9203 }
9204
9205 @Override
9206 public String getMmsUserAgent(int subId) {
9207 //TODO investigate if this API should require proper permission check in R b/133791609
9208 final long identity = Binder.clearCallingIdentity();
9209 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009210 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9211 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9212 if (!TextUtils.isEmpty(carrierUserAgent)) {
9213 return carrierUserAgent;
9214 }
chen xud5ca2d52019-05-28 15:20:57 -07009215 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9216 .getString(com.android.internal.R.string.config_mms_user_agent);
9217 } finally {
9218 Binder.restoreCallingIdentity(identity);
9219 }
9220 }
Jack Yub07d4972019-05-28 16:12:25 -07009221
9222 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009223 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9224 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9225
9226 final long identity = Binder.clearCallingIdentity();
9227 try {
9228 Phone phone = getPhone(subscriptionId);
9229 if (phone == null) return false;
9230
9231 switch (policy) {
9232 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9233 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9234 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9235 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9236 default:
9237 throw new IllegalArgumentException(policy + " is not a valid policy");
9238 }
9239 } finally {
9240 Binder.restoreCallingIdentity(identity);
9241 }
9242 }
9243
9244 @Override
9245 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9246 boolean enabled) {
9247 enforceModifyPermission();
9248
9249 final long identity = Binder.clearCallingIdentity();
9250 try {
9251 Phone phone = getPhone(subscriptionId);
9252 if (phone == null) return;
9253
9254 switch (policy) {
9255 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9256 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9257 break;
9258 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9259 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9260 break;
9261 default:
9262 throw new IllegalArgumentException(policy + " is not a valid policy");
9263 }
9264 } finally {
9265 Binder.restoreCallingIdentity(identity);
9266 }
9267 }
9268
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009269 /**
Hall Liub48cf452020-09-25 11:13:49 -07009270 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009271 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9272 * otherwise.
9273 */
9274 @Override
9275 public void setCepEnabled(boolean isCepEnabled) {
9276 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9277
9278 final long identity = Binder.clearCallingIdentity();
9279 try {
9280 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9281 for (Phone phone : PhoneFactory.getPhones()) {
9282 Phone defaultPhone = phone.getImsPhone();
9283 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9284 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9285 ImsPhoneCallTracker imsPhoneCallTracker =
9286 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9287 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9288 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9289 + imsPhone.getMsisdn());
9290 }
9291 }
9292 } finally {
9293 Binder.restoreCallingIdentity(identity);
9294 }
9295 }
allenwtsu46dcc572020-01-08 18:24:03 +08009296
9297 /**
9298 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9299 *
9300 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9301 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9302 * before being read.
9303 */
9304 @Override
9305 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9306 isCompressed) {
9307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9308 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009309 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9310 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9311 }
9312 if (!isImsAvailableOnDevice()) {
9313 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9314 "IMS not available on device.");
9315 }
9316
9317 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009318 try {
Hui Wang068ab862020-10-31 05:12:53 +00009319 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9320 } finally {
9321 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009322 }
9323 }
zoey chenf95ca592019-12-30 16:11:23 +08009324
9325 @Override
9326 public boolean isIccLockEnabled(int subId) {
9327 enforceReadPrivilegedPermission("isIccLockEnabled");
9328
9329 // Now that all security checks passes, perform the operation as ourselves.
9330 final long identity = Binder.clearCallingIdentity();
9331 try {
9332 Phone phone = getPhone(subId);
9333 if (phone != null && phone.getIccCard() != null) {
9334 return phone.getIccCard().getIccLockEnabled();
9335 } else {
9336 return false;
9337 }
9338 } finally {
9339 Binder.restoreCallingIdentity(identity);
9340 }
9341 }
9342
9343 /**
zoey chene02881a2019-12-30 16:11:23 +08009344 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009345 *
zoey chene02881a2019-12-30 16:11:23 +08009346 * @return an integer representing the status of IccLock enabled or disabled in the following
9347 * three cases:
9348 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9349 * successfully.
9350 * - Positive number and zero for remaining password attempts.
9351 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009352 *
9353 */
9354 @Override
9355 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9356 enforceModifyPermission();
9357
9358 Phone phone = getPhone(subId);
9359 if (phone == null) {
9360 return 0;
9361 }
9362 // Now that all security checks passes, perform the operation as ourselves.
9363 final long identity = Binder.clearCallingIdentity();
9364 try {
9365 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9366 new Pair<Boolean, String>(enabled, password), phone, null);
9367 return attemptsRemaining;
9368
9369 } catch (Exception e) {
9370 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9371 } finally {
9372 Binder.restoreCallingIdentity(identity);
9373 }
9374 return 0;
9375 }
9376
9377 /**
9378 * Change the ICC password used in ICC pin lock.
9379 *
zoey chene02881a2019-12-30 16:11:23 +08009380 * @return an integer representing the status of IccLock changed in the following three cases:
9381 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9382 * - Positive number and zero for remaining password attempts.
9383 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009384 *
9385 */
9386 @Override
9387 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9388 enforceModifyPermission();
9389
9390 Phone phone = getPhone(subId);
9391 if (phone == null) {
9392 return 0;
9393 }
9394 // Now that all security checks passes, perform the operation as ourselves.
9395 final long identity = Binder.clearCallingIdentity();
9396 try {
9397 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9398 new Pair<String, String>(oldPassword, newPassword), phone, null);
9399 return attemptsRemaining;
9400
9401 } catch (Exception e) {
9402 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
9405 }
9406 return 0;
9407 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009408
Peter Wangdafb9ac2020-01-15 14:13:38 -08009409 /**
9410 * Request for receiving user activity notification
9411 */
9412 @Override
9413 public void requestUserActivityNotification() {
9414 if (!mNotifyUserActivity.get()
9415 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9416 mNotifyUserActivity.set(true);
9417 }
9418 }
9419
9420 /**
9421 * Called when userActivity is signalled in the power manager.
9422 * This is safe to call from any thread, with any window manager locks held or not.
9423 */
9424 @Override
9425 public void userActivity() {
9426 // ***************************************
9427 // * Inherited from PhoneWindowManager *
9428 // ***************************************
9429 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9430 // WITH ITS LOCKS HELD.
9431 //
9432 // This code must be VERY careful about the locks
9433 // it acquires.
9434 // In fact, the current code acquires way too many,
9435 // and probably has lurking deadlocks.
9436
9437 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9438 throw new SecurityException("Only the OS may call notifyUserActivity()");
9439 }
9440
9441 if (mNotifyUserActivity.getAndSet(false)) {
9442 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9443 USER_ACTIVITY_NOTIFICATION_DELAY);
9444 }
9445 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009446
Malcolm Chen884180b2020-04-13 11:59:40 -07009447 @Override
9448 public boolean canConnectTo5GInDsdsMode() {
9449 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9450 }
Jack Yud10cdd42020-09-28 20:28:01 -07009451
9452 @Override
9453 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9454 String callingFeatureId) {
9455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9456 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9457 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9458 }
9459
9460 Phone phone = getPhone(subId);
9461 if (phone == null) {
9462 throw new RuntimeException("phone is not available");
9463 }
9464 // Now that all security checks passes, perform the operation as ourselves.
9465 final long identity = Binder.clearCallingIdentity();
9466 try {
9467 return phone.getEquivalentHomePlmns();
9468 } finally {
9469 Binder.restoreCallingIdentity(identity);
9470 }
9471 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009472
Hui Wang0866fcc2020-10-12 12:14:23 -07009473 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009474 public boolean isRadioInterfaceCapabilitySupported(
9475 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009476 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009477 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009478 if (radioInterfaceCapabilities == null) {
9479 throw new RuntimeException("radio interface capabilities are not available");
9480 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009481 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009482 }
9483 }
9484
9485 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009486 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9487 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009488 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9489 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9490 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9491 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9492 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009493 if (DBG) {
9494 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9495 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9496 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9497 }
9498
9499 if (!SubscriptionManager.isValidSubscriptionId(subId)
9500 || appType < TelephonyManager.APPTYPE_UNKNOWN
9501 || appType > TelephonyManager.APPTYPE_ISIM
9502 || nafUrl == null || securityProtocol == null || callback == null) {
9503 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9504 if (callback != null) {
9505 try {
9506 callback.onAuthenticationFailure(
9507 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9508 } catch (RemoteException exception) {
9509 log("Fail to notify onAuthenticationFailure due to " + exception);
9510 }
9511 return;
9512 }
9513 }
9514
9515 final long token = Binder.clearCallingIdentity();
9516 try {
9517 getGbaManager(subId).bootstrapAuthenticationRequest(
9518 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9519 forceBootStrapping, callback));
9520 } finally {
9521 Binder.restoreCallingIdentity(token);
9522 }
9523 }
9524
Jack Nudelman24d51a52020-11-24 12:08:04 -08009525 /**
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009526 * Attempts to set the radio power state for all phones for thermal reason.
9527 * This does not guarantee that the
Jack Nudelman24d51a52020-11-24 12:08:04 -08009528 * requested radio power state will actually be set. See {@link
9529 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9530 *
Jack Nudelman24d51a52020-11-24 12:08:04 -08009531 * @param enable {@code true} if trying to turn radio on.
9532 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9533 * false}.
9534 */
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009535 private boolean setRadioPowerForThermal(boolean enable) {
9536 boolean isPhoneAvailable = false;
9537 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9538 Phone phone = PhoneFactory.getPhone(i);
9539 if (phone != null) {
9540 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9541 isPhoneAvailable = true;
9542 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009543 }
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009544
9545 // return true if successfully informed the phone object about the thermal radio power
9546 // request.
9547 return isPhoneAvailable;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009548 }
9549
9550 private int handleDataThrottlingRequest(int subId,
9551 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009552 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9553 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9554 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9555 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9556 throw new IllegalArgumentException("modem does not support data throttling");
9557 }
9558
Jack Nudelman24d51a52020-11-24 12:08:04 -08009559 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9560 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009561 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009562 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9563 }
9564
9565 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9566
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009567 if (isDataThrottlingSupported) {
9568 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009569 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009570 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9571 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9572 } else if (thermalMitigationResult
9573 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman20352592021-05-20 13:57:30 -07009574 log("Modem likely does not support data throttling on secondary carrier. Data " +
9575 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9576 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009577 }
9578 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009579 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009580
9581 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009582 }
9583
Jack Nudelman644b91a2021-03-12 14:09:48 -08009584 private static List<String> getThermalMitigationAllowlist(Context context) {
9585 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9586 for (String pckg : context.getResources()
9587 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9588 sThermalMitigationAllowlistedPackages.add(pckg);
9589 }
9590 }
9591
9592 return sThermalMitigationAllowlistedPackages;
9593 }
9594
Jack Nudelmane634f962021-05-13 10:00:15 -07009595 private boolean isAnyPhoneInEmergencyState() {
9596 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9597 if (tm.isInEmergencyCall()) {
9598 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9599 return true;
9600 }
9601 for (Phone phone : PhoneFactory.getPhones()) {
9602 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9603 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9604 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9605 + phone.isInEcm());
9606 return true;
9607 }
9608 }
9609
9610 return false;
9611 }
9612
Jack Nudelman644b91a2021-03-12 14:09:48 -08009613 /**
9614 * Used by shell commands to add an authorized package name for thermal mitigation.
9615 * @param packageName name of package to be allowlisted
9616 * @param context
9617 */
9618 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9619 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9620 sThermalMitigationAllowlistedPackages.add(packageName);
9621 }
9622
9623 /**
9624 * Used by shell commands to remove an authorized package name for thermal mitigation.
9625 * @param packageName name of package to remove from allowlist
9626 * @param context
9627 */
9628 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9629 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9630 sThermalMitigationAllowlistedPackages.remove(packageName);
9631 }
9632
Jack Nudelman24d51a52020-11-24 12:08:04 -08009633 /**
9634 * Thermal mitigation request to control functionalities at modem.
9635 *
9636 * @param subId the id of the subscription.
9637 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009638 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009639 *
9640 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9641 */
9642 @Override
9643 @ThermalMitigationResult
9644 public int sendThermalMitigationRequest(
9645 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009646 ThermalMitigationRequest thermalMitigationRequest,
9647 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009648 enforceModifyPermission();
9649
Jack Nudelman644b91a2021-03-12 14:09:48 -08009650 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9651 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9652 .contains(callingPackage)) {
9653 throw new SecurityException("Calling package must be configured in the device config. "
9654 + "calling package: " + callingPackage);
9655 }
9656
Jack Nudelman24d51a52020-11-24 12:08:04 -08009657 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9658 final long identity = Binder.clearCallingIdentity();
9659
9660 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9661 try {
9662 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9663 switch (thermalMitigationAction) {
9664 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9665 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009666 handleDataThrottlingRequest(subId,
9667 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009668 break;
9669 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9670 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9671 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9672 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9673 }
9674
9675 // Ensure that radio is on. If not able to power on due to phone being
9676 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009677 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009678 thermalMitigationResult =
9679 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9680 break;
9681 }
9682
9683 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9684 false);
9685 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9686 break;
9687 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9688 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9689 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9690 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9691 }
9692
9693 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9694 if (registry != null) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009695 Phone phone = getPhone(subId);
9696 if (phone == null) {
9697 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009698 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009699 break;
9700 }
9701
Jack Nudelmane634f962021-05-13 10:00:15 -07009702 TelephonyConnectionService service =
9703 registry.getTelephonyConnectionService();
Jack Nudelmana80c0012021-06-17 15:39:58 -07009704 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane634f962021-05-13 10:00:15 -07009705 Log.e(LOG_TAG, "An emergency call is pending");
9706 thermalMitigationResult =
9707 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9708 break;
9709 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009710 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009711 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009712 break;
9713 }
9714 } else {
9715 thermalMitigationResult =
9716 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9717 break;
9718 }
9719
9720 // Turn radio off. If not able to power off due to phone being unavailable,
9721 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009722 if (!setRadioPowerForThermal(false)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009723 thermalMitigationResult =
9724 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9725 break;
9726 }
9727 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009728 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009729 break;
9730 default:
9731 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9732 + "not exist. Requested action: " + thermalMitigationAction);
9733 }
9734 } catch (IllegalArgumentException e) {
9735 throw e;
9736 } catch (Exception e) {
9737 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9738 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9739 } finally {
9740 Binder.restoreCallingIdentity(identity);
9741 }
9742
9743 if (DBG) {
9744 log("thermalMitigationRequest returning with thermalMitigationResult: "
9745 + thermalMitigationResult);
9746 }
9747
9748 return thermalMitigationResult;
9749 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009750
9751 /**
9752 * Set the GbaService Package Name that Telephony will bind to.
9753 *
9754 * @param subId The sim that the GbaService is associated with.
9755 * @param packageName The name of the package to be replaced with.
9756 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9757 */
9758 @Override
9759 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9760 enforceModifyPermission();
9761
9762 final long identity = Binder.clearCallingIdentity();
9763 try {
9764 return getGbaManager(subId).overrideServicePackage(packageName);
9765 } finally {
9766 Binder.restoreCallingIdentity(identity);
9767 }
9768 }
9769
9770 /**
9771 * Return the package name of the currently bound GbaService.
9772 *
9773 * @param subId The sim that the GbaService is associated with.
9774 * @return the package name of the GbaService configuration, null if GBA is not supported.
9775 */
9776 @Override
9777 public String getBoundGbaService(int subId) {
9778 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9779
9780 final long identity = Binder.clearCallingIdentity();
9781 try {
9782 return getGbaManager(subId).getServicePackage();
9783 } finally {
9784 Binder.restoreCallingIdentity(identity);
9785 }
9786 }
9787
9788 /**
9789 * Set the release time for telephony to unbind GbaService.
9790 *
9791 * @param subId The sim that the GbaService is associated with.
9792 * @param interval The release time to unbind GbaService by millisecond.
9793 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9794 */
9795 @Override
9796 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9797 enforceModifyPermission();
9798
9799 final long identity = Binder.clearCallingIdentity();
9800 try {
9801 return getGbaManager(subId).overrideReleaseTime(interval);
9802 } finally {
9803 Binder.restoreCallingIdentity(identity);
9804 }
9805 }
9806
9807 /**
9808 * Return the release time for telephony to unbind GbaService.
9809 *
9810 * @param subId The sim that the GbaService is associated with.
9811 * @return The release time to unbind GbaService by millisecond.
9812 */
9813 @Override
9814 public int getGbaReleaseTime(int subId) {
9815 enforceReadPrivilegedPermission("getGbaReleaseTime");
9816
9817 final long identity = Binder.clearCallingIdentity();
9818 try {
9819 return getGbaManager(subId).getReleaseTime();
9820 } finally {
9821 Binder.restoreCallingIdentity(identity);
9822 }
9823 }
9824
9825 private GbaManager getGbaManager(int subId) {
9826 GbaManager instance = GbaManager.getInstance(subId);
9827 if (instance == null) {
9828 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9829 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9830 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9831 }
9832 return instance;
9833 }
Hui Wang068ab862020-10-31 05:12:53 +00009834
9835 /**
9836 * indicate whether the device and the carrier can support
9837 * RCS VoLTE single registration.
9838 */
9839 @Override
9840 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009841 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9842 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9843 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9844 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009845
9846 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9847 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9848 }
9849
9850 final long identity = Binder.clearCallingIdentity();
9851 try {
9852 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9853 if (rpm != null) {
Hui Wang048c10a2021-06-21 18:05:57 +00009854 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
9855 if (isCapable != null) {
9856 return isCapable;
9857 }
Hui Wang068ab862020-10-31 05:12:53 +00009858 }
Hui Wang048c10a2021-06-21 18:05:57 +00009859 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
9860 "service is temporarily unavailable.");
Hui Wang068ab862020-10-31 05:12:53 +00009861 } finally {
9862 Binder.restoreCallingIdentity(identity);
9863 }
9864 }
9865
9866 /**
9867 * Register RCS provisioning callback.
9868 */
9869 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009870 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009871 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009872 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009873 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009874 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9875 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009876
9877 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9878 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9879 }
9880 if (!isImsAvailableOnDevice()) {
9881 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9882 "IMS not available on device.");
9883 }
9884
9885 final long identity = Binder.clearCallingIdentity();
9886 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009887 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009888 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009889 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9890 "Service not available for the subscription.");
9891 }
Hui Wang068ab862020-10-31 05:12:53 +00009892 } finally {
9893 Binder.restoreCallingIdentity(identity);
9894 }
9895 }
9896
9897 /**
9898 * Unregister RCS provisioning callback.
9899 */
9900 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009901 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009902 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009903 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009904 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009905 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9906 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009907
9908 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9909 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9910 }
9911 if (!isImsAvailableOnDevice()) {
9912 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9913 "IMS not available on device.");
9914 }
9915
9916 final long identity = Binder.clearCallingIdentity();
9917 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009918 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009919 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009920 } finally {
9921 Binder.restoreCallingIdentity(identity);
9922 }
9923 }
9924
9925 /**
9926 * trigger RCS reconfiguration.
9927 */
9928 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009929 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9930 "triggerRcsReconfiguration",
9931 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009932
9933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9934 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9935 }
9936 if (!isImsAvailableOnDevice()) {
9937 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9938 "IMS not available on device.");
9939 }
9940
9941 final long identity = Binder.clearCallingIdentity();
9942 try {
9943 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9944 } finally {
9945 Binder.restoreCallingIdentity(identity);
9946 }
9947 }
9948
9949 /**
9950 * Provide the client configuration parameters of the RCS application.
9951 */
9952 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009953 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9954 "setRcsClientConfiguration",
9955 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009956
9957 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9958 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9959 }
9960 if (!isImsAvailableOnDevice()) {
9961 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9962 "IMS not available on device.");
9963 }
9964
9965 final long identity = Binder.clearCallingIdentity();
9966
9967 try {
9968 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9969 if (configBinder == null) {
9970 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9971 } else {
9972 configBinder.setRcsClientConfiguration(rcc);
9973 }
9974 } catch (RemoteException e) {
9975 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9976 } finally {
9977 Binder.restoreCallingIdentity(identity);
9978 }
9979 }
9980
9981 /**
Hui Wang19a21872021-02-19 20:45:36 -08009982 * Enables or disables the test mode for RCS VoLTE single registration.
9983 */
9984 @Override
9985 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9986 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9987 "setRcsSingleRegistrationTestModeEnabled");
9988
9989 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9990 }
9991
9992 /**
9993 * Gets the test mode for RCS VoLTE single registration.
9994 */
9995 @Override
9996 public boolean getRcsSingleRegistrationTestModeEnabled() {
9997 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9998 "getRcsSingleRegistrationTestModeEnabled");
9999
10000 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10001 }
10002
10003 /**
Hui Wang068ab862020-10-31 05:12:53 +000010004 * Overrides the config of RCS VoLTE single registration enabled for the device.
10005 */
10006 @Override
10007 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10009 "setDeviceSingleRegistrationEnabledOverride");
10010 enforceModifyPermission();
10011
10012 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10013 : Boolean.parseBoolean(enabledStr);
10014 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010015 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +000010016 }
10017
10018 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010019 * Sends a device to device communication message. Only usable via shell.
10020 * @param message message to send.
10021 * @param value message value.
10022 */
10023 @Override
10024 public void sendDeviceToDeviceMessage(int message, int value) {
10025 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10026 "setCarrierSingleRegistrationEnabledOverride");
10027 enforceModifyPermission();
10028
10029 final long identity = Binder.clearCallingIdentity();
10030 try {
10031 TelephonyConnectionService service =
10032 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10033 if (service == null) {
10034 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10035 return;
10036 }
10037 service.sendTestDeviceToDeviceMessage(message, value);
10038 } finally {
10039 Binder.restoreCallingIdentity(identity);
10040 }
10041 }
10042
10043
10044 /**
Hui Wang068ab862020-10-31 05:12:53 +000010045 * Gets the config of RCS VoLTE single registration enabled for the device.
10046 */
10047 @Override
10048 public boolean getDeviceSingleRegistrationEnabled() {
10049 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10050 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10051 }
10052
10053 /**
10054 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10055 */
10056 @Override
10057 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10058 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10059 "setCarrierSingleRegistrationEnabledOverride");
10060 enforceModifyPermission();
10061
10062 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10063 : Boolean.parseBoolean(enabledStr);
10064 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10065 subId, enabled);
10066 }
10067
10068 /**
10069 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10070 */
10071 @Override
10072 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10073 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10074 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10075 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010076
10077 /**
Hui Wangeadb2562021-02-26 09:33:38 -080010078 * Overrides the ims feature validation result
10079 */
10080 @Override
10081 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10082 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10083 "setImsFeatureValidationOverride");
10084
10085 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10086 : Boolean.parseBoolean(enabledStr);
10087 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10088 subId, enabled);
10089 }
10090
10091 /**
10092 * Gets the ims feature validation override value
10093 */
10094 @Override
10095 public boolean getImsFeatureValidationOverride(int subId) {
10096 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10097 "getImsFeatureValidationOverride");
10098 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10099 }
10100
10101 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010102 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10103 * their mobile plan.
10104 */
10105 @Override
10106 public String getMobileProvisioningUrl() {
10107 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10108 final long identity = Binder.clearCallingIdentity();
10109 try {
10110 return getDefaultPhone().getMobileProvisioningUrl();
10111 } finally {
10112 Binder.restoreCallingIdentity(identity);
10113 }
10114 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010115
James.cf Linbcdf8b32021-01-14 16:44:13 +080010116 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010117 * Get the EAB contact from the EAB database.
10118 */
10119 @Override
10120 public String getContactFromEab(String contact) {
10121 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10122 enforceModifyPermission();
10123 final long identity = Binder.clearCallingIdentity();
10124 try {
10125 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10126 } finally {
10127 Binder.restoreCallingIdentity(identity);
10128 }
10129 }
10130
10131 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010132 * Remove the EAB contacts from the EAB database.
10133 */
10134 @Override
10135 public int removeContactFromEab(int subId, String contacts) {
10136 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10137 enforceModifyPermission();
10138 final long identity = Binder.clearCallingIdentity();
10139 try {
10140 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10141 } finally {
10142 Binder.restoreCallingIdentity(identity);
10143 }
10144 }
10145
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010146 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010147 public boolean getDeviceUceEnabled() {
10148 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10149 final long identity = Binder.clearCallingIdentity();
10150 try {
10151 return mApp.getDeviceUceEnabled();
10152 } finally {
10153 Binder.restoreCallingIdentity(identity);
10154 }
10155 }
10156
10157 @Override
10158 public void setDeviceUceEnabled(boolean isEnabled) {
10159 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10160 final long identity = Binder.clearCallingIdentity();
10161 try {
10162 mApp.setDeviceUceEnabled(isEnabled);
10163 } finally {
10164 Binder.restoreCallingIdentity(identity);
10165 }
10166 }
10167
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010168 /**
10169 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10170 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10171 */
10172 // Used for SHELL command only right now.
10173 @Override
10174 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10175 List<String> featureTags) {
10176 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10177 "addUceRegistrationOverrideShell");
10178 final long identity = Binder.clearCallingIdentity();
10179 try {
10180 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10181 new ArraySet<>(featureTags));
10182 } catch (ImsException e) {
10183 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10184 } finally {
10185 Binder.restoreCallingIdentity(identity);
10186 }
10187 }
10188
10189 /**
10190 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10191 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10192 */
10193 // Used for SHELL command only right now.
10194 @Override
10195 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10196 List<String> featureTags) {
10197 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10198 "removeUceRegistrationOverrideShell");
10199 final long identity = Binder.clearCallingIdentity();
10200 try {
10201 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10202 new ArraySet<>(featureTags));
10203 } catch (ImsException e) {
10204 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10205 } finally {
10206 Binder.restoreCallingIdentity(identity);
10207 }
10208 }
10209
10210 /**
10211 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10212 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10213 */
10214 // Used for SHELL command only right now.
10215 @Override
10216 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10217 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10218 "clearUceRegistrationOverrideShell");
10219 final long identity = Binder.clearCallingIdentity();
10220 try {
10221 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10222 } catch (ImsException e) {
10223 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10224 } finally {
10225 Binder.restoreCallingIdentity(identity);
10226 }
10227 }
10228
10229 /**
10230 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10231 */
10232 // Used for SHELL command only right now.
10233 @Override
10234 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10235 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10236 "getLatestRcsContactUceCapabilityShell");
10237 final long identity = Binder.clearCallingIdentity();
10238 try {
10239 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10240 } catch (ImsException e) {
10241 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10242 } finally {
10243 Binder.restoreCallingIdentity(identity);
10244 }
10245 }
10246
10247 /**
10248 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10249 * device does not have an active PUBLISH.
10250 */
10251 // Used for SHELL command only right now.
10252 @Override
10253 public String getLastUcePidfXmlShell(int subId) {
10254 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10255 final long identity = Binder.clearCallingIdentity();
10256 try {
10257 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10258 } catch (ImsException e) {
10259 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10260 } finally {
10261 Binder.restoreCallingIdentity(identity);
10262 }
10263 }
10264
James.cf Line8713a42021-04-29 16:04:26 +080010265 /**
10266 * Remove UCE requests cannot be sent to the network status.
10267 */
10268 // Used for SHELL command only right now.
10269 @Override
10270 public boolean removeUceRequestDisallowedStatus(int subId) {
10271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10272 final long identity = Binder.clearCallingIdentity();
10273 try {
10274 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10275 } catch (ImsException e) {
10276 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10277 } finally {
10278 Binder.restoreCallingIdentity(identity);
10279 }
10280 }
10281
James.cf Lin18bb9002021-05-25 01:37:38 +080010282 /**
10283 * Remove UCE requests cannot be sent to the network status.
10284 */
10285 // Used for SHELL command only.
10286 @Override
10287 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10288 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10289 final long identity = Binder.clearCallingIdentity();
10290 try {
10291 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10292 } catch (ImsException e) {
10293 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10294 } finally {
10295 Binder.restoreCallingIdentity(identity);
10296 }
10297 }
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010298
James.cf Lin4b784aa2021-01-31 03:25:15 +080010299 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010300 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10301 String callingPackage) {
10302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10303 mApp, subId, "setSignalStrengthUpdateRequest");
10304
10305 final int callingUid = Binder.getCallingUid();
10306 // Verify that tha callingPackage belongs to the calling UID
10307 mApp.getSystemService(AppOpsManager.class)
10308 .checkPackage(callingUid, callingPackage);
10309
10310 validateSignalStrengthUpdateRequest(request, callingUid);
10311
10312 final long identity = Binder.clearCallingIdentity();
10313 try {
10314 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10315 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10316
10317 if (result instanceof IllegalStateException) {
10318 throw (IllegalStateException) result;
10319 }
10320 } finally {
10321 Binder.restoreCallingIdentity(identity);
10322 }
10323 }
10324
10325 @Override
10326 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10327 String callingPackage) {
10328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10329 mApp, subId, "clearSignalStrengthUpdateRequest");
10330
10331 final int callingUid = Binder.getCallingUid();
10332 // Verify that tha callingPackage belongs to the calling UID
10333 mApp.getSystemService(AppOpsManager.class)
10334 .checkPackage(callingUid, callingPackage);
10335
10336 final long identity = Binder.clearCallingIdentity();
10337 try {
10338 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10339 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10340
10341 if (result instanceof IllegalStateException) {
10342 throw (IllegalStateException) result;
10343 }
10344 } finally {
10345 Binder.restoreCallingIdentity(identity);
10346 }
10347 }
10348
10349 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10350 int callingUid) {
10351 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10352 // phone/system process do not have further restriction on request
10353 return;
10354 }
10355
10356 // Applications has restrictions on how to use the request:
10357 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10358 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10359 // This is not system caller which has been checked above
10360 throw new IllegalArgumentException(
10361 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10362 }
10363
10364 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10365 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10366 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10367 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10368 || info.isEnabled()) {
10369 throw new IllegalArgumentException(
10370 "Only system can set hide fields in SignalThresholdInfo");
10371 }
10372
10373 // Thresholds length for each RAN need in range. This has been validated in
10374 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10375 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10376 final int[] thresholds = info.getThresholds();
10377 Objects.requireNonNull(thresholds);
10378 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10379 || thresholds.length
10380 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10381 throw new IllegalArgumentException(
10382 "thresholds length is out of range: " + thresholds.length);
10383 }
10384 }
10385 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010386
10387 /**
10388 * Prepare TelephonyManager for an unattended reboot. The reboot is
10389 * required to be done shortly after the API is invoked.
10390 */
10391 @Override
10392 @TelephonyManager.PrepareUnattendedRebootResult
10393 public int prepareForUnattendedReboot() {
10394 enforceRebootPermission();
10395
10396 final long identity = Binder.clearCallingIdentity();
10397 try {
10398 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10399 } finally {
10400 Binder.restoreCallingIdentity(identity);
10401 }
10402 }
SongFerngWang2c4309d2021-01-17 21:51:44 +080010403
10404 /**
10405 * Gets the current phone capability.
10406 *
10407 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10408 * @return the PhoneCapability which describes the data connection capability of modem.
10409 * It's used to evaluate possible phone config change, for example from single
10410 * SIM device to multi-SIM device.
10411 */
10412 @Override
10413 public PhoneCapability getPhoneCapability() {
10414 enforceReadPrivilegedPermission("getPhoneCapability");
10415 final long identity = Binder.clearCallingIdentity();
10416 try {
10417 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10418 } finally {
10419 Binder.restoreCallingIdentity(identity);
10420 }
10421 }
Hongbo Zengd31d3a32021-02-08 21:50:28 +080010422
10423 /**
10424 * Request to get the current slicing configuration including URSP rules and
10425 * NSSAIs (configured, allowed and rejected).
10426 *
10427 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10428 */
10429 @Override
10430 public void getSlicingConfig(ResultReceiver callback) {
10431 enforceReadPrivilegedPermission("getSlicingConfig");
10432
10433 final long identity = Binder.clearCallingIdentity();
10434 try {
10435 Phone phone = getDefaultPhone();
10436 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10437 } finally {
10438 Binder.restoreCallingIdentity(identity);
10439 }
10440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010441}