blob: a09c6ad02de7c4618f74d7889c5b371f2ce72ca5 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qian479dd9e2021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger4df7e242021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070032import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070033import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.content.Context;
35import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070036import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070037import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080038import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070039import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.net.Uri;
41import android.os.AsyncResult;
42import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080043import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Bundle;
45import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.Looper;
48import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070049import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080050import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070051import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070052import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080053import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080054import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070055import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070056import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080057import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070059import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070060import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070061import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070062import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080063import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070064import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090065import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080066import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080067import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070068import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070069import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080070import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080071import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070072import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080073import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070074import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080075import android.telephony.CellIdentityCdma;
76import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070078import android.telephony.CellInfoGsm;
79import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070080import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080081import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070082import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070083import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070084import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080085import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070086import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080087import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070088import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080089import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080090import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070091import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080092import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080094import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080095import android.telephony.SignalStrengthUpdateRequest;
96import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080097import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080098import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080099import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700100import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700101import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800102import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800103import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800104import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000105import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700106import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800108import android.telephony.data.ApnSetting;
109import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700110import android.telephony.gba.GbaAuthRequest;
111import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700112import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000114import android.telephony.ims.RcsClientConfiguration;
Brad Ebingerd4c5bde2021-02-12 06:18:28 +0000115import android.telephony.ims.RcsContactUceCapability;
Brad Ebinger774ba362019-10-22 17:36:18 -0700116import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700117import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800118import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700119import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800120import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700121import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000122import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700123import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800125import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800126import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800127import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800129import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700130import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800132import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800133
Andrew Lee312e8172014-10-23 17:01:36 -0700134import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800135import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800136import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWang51ee2b12021-05-27 22:44:54 +0800137import com.android.internal.annotations.VisibleForTesting;
sqian80370722020-01-29 15:02:51 -0800138import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700140import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700141import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800142import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700143import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700144import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800145import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700147import com.android.internal.telephony.GbaManager;
Shuo Qian479dd9e2021-02-22 18:32:21 -0800148import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800149import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800150import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700151import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800153import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800155import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700156import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700157import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700158import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700160import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800161import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700162import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700163import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700164import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700165import com.android.internal.telephony.RIL;
SongFerngWang522637d2021-03-02 22:09:29 +0800166import com.android.internal.telephony.RILConstants;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800167import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700168import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700169import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800171import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800172import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800173import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700174import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800175import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700176import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800177import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700178import com.android.internal.telephony.imsphone.ImsPhone;
179import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800180import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900181import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800183import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800185import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700186import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800187import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800189import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000190import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800191import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700192import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700193import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800194import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700195import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700196import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800197import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700198import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700199import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800200import com.android.services.telephony.TelecomAccountRegistry;
201import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800202import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800203
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700204import java.io.FileDescriptor;
205import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800208import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800209import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800210import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100211import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800212import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700213import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800214import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800215import java.util.Set;
SongFerngWangc63cf522021-03-31 22:08:45 +0800216import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800217import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800218import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700219
220/**
221 * Implementation of the ITelephony interface.
222 */
Santos Cordon117fee72014-05-16 17:56:12 -0700223public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700224 private static final String LOG_TAG = "PhoneInterfaceManager";
225 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
226 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800227 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228
229 // Message codes used with mMainThreadHandler
230 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700231 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
232 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700233 private static final int CMD_OPEN_CHANNEL = 9;
234 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
235 private static final int CMD_CLOSE_CHANNEL = 11;
236 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800237 private static final int CMD_NV_READ_ITEM = 13;
238 private static final int EVENT_NV_READ_ITEM_DONE = 14;
239 private static final int CMD_NV_WRITE_ITEM = 15;
240 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
241 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
242 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700243 private static final int CMD_RESET_MODEM_CONFIG = 19;
244 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800245 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
246 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800247 private static final int CMD_SEND_ENVELOPE = 25;
248 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000249 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
250 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700251 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
252 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
253 private static final int CMD_EXCHANGE_SIM_IO = 31;
254 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800255 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
256 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700257 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
258 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700259 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
260 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700261 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
262 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
263 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
264 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700265 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
266 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
267 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
268 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700269 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800270 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
271 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000272 private static final int CMD_SWITCH_SLOTS = 50;
273 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700274 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
275 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
276 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
277 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
278 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
279 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
280 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
281 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700282 private static final int CMD_GET_ALL_CELL_INFO = 60;
283 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
284 private static final int CMD_GET_CELL_LOCATION = 62;
285 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700286 private static final int CMD_MODEM_REBOOT = 64;
287 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700288 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
289 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800290 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
291 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700292 private static final int CMD_GET_MODEM_STATUS = 70;
293 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700294 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
295 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700296 private static final int CMD_ERASE_MODEM_CONFIG = 74;
297 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800298 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
299 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
300 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
301 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800302 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
303 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800304 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800305 private static final int CMD_GET_CALL_FORWARDING = 83;
306 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
307 private static final int CMD_SET_CALL_FORWARDING = 85;
308 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
309 private static final int CMD_GET_CALL_WAITING = 87;
310 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
311 private static final int CMD_SET_CALL_WAITING = 89;
312 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700313 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
314 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
315 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
316 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700317 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
318 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800319 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
320 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800321 private static final int CMD_SET_DATA_THROTTLING = 99;
322 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800323 private static final int CMD_SET_SIM_POWER = 101;
324 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800325 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
326 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
327 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
328 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800329 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
330 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000331 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800333 // Parameters of select command.
334 private static final int SELECT_COMMAND = 0xA4;
335 private static final int SELECT_P1 = 0x04;
336 private static final int SELECT_P2 = 0;
337 private static final int SELECT_P3 = 0x10;
338
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 /** The singleton instance. */
340 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800341 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
Wink Saville3ab207e2014-11-20 13:07:20 -0800343 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800344 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800345 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700346 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800347 private AppOpsManager mAppOps;
348 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800349 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800350 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700351 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800352 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
Peter Wangdafb9ac2020-01-15 14:13:38 -0800354 /** User Activity */
355 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800356 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
357
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700358 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
359
Derek Tan97ebb422014-09-05 16:55:38 -0700360 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
361 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800362 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800363 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700364
Michelecea4cf22018-12-21 15:00:11 -0800365 // String to store multi SIM allowed
366 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
367
Derek Tan740e1672017-06-27 14:56:27 -0700368 // The AID of ISD-R.
369 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
370
yinxub1bed742017-04-17 11:45:04 -0700371 private NetworkScanRequestTracker mNetworkScanRequestTracker;
372
David Kelly5e06a7f2018-03-12 14:10:59 +0000373 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
374 private static final int MANUFACTURER_CODE_LENGTH = 8;
375
Jack Nudelman24d51a52020-11-24 12:08:04 -0800376 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800377 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800378
Derek Tan89e89d42014-07-08 17:00:10 -0700379 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700380 * Experiment flag to enable erase modem config on reset network, default value is false
381 */
382 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
383 "reset_network_erase_modem_config_enabled";
384
Rambo Wang0f050d82021-02-12 11:43:36 -0800385 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
386
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700387 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700388 * A request object to use for transmitting data to an ICC.
389 */
390 private static final class IccAPDUArgument {
391 public int channel, cla, command, p1, p2, p3;
392 public String data;
393
394 public IccAPDUArgument(int channel, int cla, int command,
395 int p1, int p2, int p3, String data) {
396 this.channel = channel;
397 this.cla = cla;
398 this.command = command;
399 this.p1 = p1;
400 this.p2 = p2;
401 this.p3 = p3;
402 this.data = data;
403 }
404 }
405
406 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700407 * A request object to use for transmitting data to an ICC.
408 */
409 private static final class ManualNetworkSelectionArgument {
410 public OperatorInfo operatorInfo;
411 public boolean persistSelection;
412
413 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
414 this.operatorInfo = operatorInfo;
415 this.persistSelection = persistSelection;
416 }
417 }
418
419 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
421 * request after sending. The main thread will notify the request when it is complete.
422 */
423 private static final class MainThreadRequest {
424 /** The argument to use for the request */
425 public Object argument;
426 /** The result of the request that is run on the main thread */
427 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800428 // The subscriber id that this request applies to. Defaults to
429 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
430 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431
Nathan Harold92bed182018-10-12 18:16:49 -0700432 // In cases where subId is unavailable, the caller needs to specify the phone.
433 public Phone phone;
434
vagdeviaf9a5b92018-08-15 16:01:53 -0700435 public WorkSource workSource;
436
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 public MainThreadRequest(Object argument) {
438 this.argument = argument;
439 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800440
Nathan Harold92bed182018-10-12 18:16:49 -0700441 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
442 this.argument = argument;
443 if (phone != null) {
444 this.phone = phone;
445 }
446 this.workSource = workSource;
447 }
448
vagdeviaf9a5b92018-08-15 16:01:53 -0700449 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800450 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800451 if (subId != null) {
452 this.subId = subId;
453 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700454 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 }
457
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800458 private static final class IncomingThirdPartyCallArgs {
459 public final ComponentName component;
460 public final String callId;
461 public final String callerDisplayName;
462
463 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
464 String callerDisplayName) {
465 this.component = component;
466 this.callId = callId;
467 this.callerDisplayName = callerDisplayName;
468 }
469 }
470
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471 /**
472 * A handler that processes messages on the main thread in the phone process. Since many
473 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
474 * inbound binder threads to the main thread in the phone process. The Binder thread
475 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
476 * on, which will be notified when the operation completes and will contain the result of the
477 * request.
478 *
479 * <p>If a MainThreadRequest object is provided in the msg.obj field,
480 * note that request.result must be set to something non-null for the calling thread to
481 * unblock.
482 */
483 private final class MainThreadHandler extends Handler {
484 @Override
485 public void handleMessage(Message msg) {
486 MainThreadRequest request;
487 Message onCompleted;
488 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800491 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700492
493 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 case CMD_HANDLE_USSD_REQUEST: {
495 request = (MainThreadRequest) msg.obj;
496 final Phone phone = getPhoneFromRequest(request);
497 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
498 String ussdRequest = ussdObject.first;
499 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700500
Pengquan Menga1bb6272018-09-06 09:59:22 -0700501 if (!isUssdApiAllowed(request.subId)) {
502 // Carrier does not support use of this API, return failure.
503 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
504 UssdResponse response = new UssdResponse(ussdRequest, null);
505 Bundle returnData = new Bundle();
506 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
507 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700508
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 request.result = true;
510 notifyRequester(request);
511 return;
512 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700513
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 try {
515 request.result = phone != null
516 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
517 } catch (CallStateException cse) {
518 request.result = false;
519 }
520 // Wake up the requesting thread
521 notifyRequester(request);
522 break;
pkanwar32d516d2016-10-14 19:37:38 -0700523 }
524
Yorke Lee716f67e2015-06-17 15:39:16 -0700525 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700526 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700527 final Phone phone = getPhoneFromRequest(request);
528 request.result = phone != null ?
529 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
530 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700531 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700533 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700534 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700537 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800539 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 if (uiccCard == null) {
541 loge("iccTransmitApduLogicalChannel: No UICC");
542 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700544 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
546 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 iccArgument.channel, iccArgument.cla, iccArgument.command,
549 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700552 break;
553
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 ar = (AsyncResult) msg.obj;
556 request = (MainThreadRequest) ar.userObj;
557 if (ar.exception == null && ar.result != null) {
558 request.result = ar.result;
559 } else {
560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
561 if (ar.result == null) {
562 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800563 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800565 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 } else {
567 loge("iccTransmitApduLogicalChannel: Unknown exception");
568 }
569 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 break;
572
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
574 request = (MainThreadRequest) msg.obj;
575 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800576 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 if (uiccCard == null) {
578 loge("iccTransmitApduBasicChannel: No UICC");
579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 } else {
582 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
583 request);
584 uiccCard.iccTransmitApduBasicChannel(
585 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
586 iccArgument.p3, iccArgument.data, onCompleted);
587 }
588 break;
589
590 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
591 ar = (AsyncResult) msg.obj;
592 request = (MainThreadRequest) ar.userObj;
593 if (ar.exception == null && ar.result != null) {
594 request.result = ar.result;
595 } else {
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
597 if (ar.result == null) {
598 loge("iccTransmitApduBasicChannel: Empty response");
599 } else if (ar.exception instanceof CommandException) {
600 loge("iccTransmitApduBasicChannel: CommandException: " +
601 ar.exception);
602 } else {
603 loge("iccTransmitApduBasicChannel: Unknown exception");
604 }
605 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 break;
608
609 case CMD_EXCHANGE_SIM_IO:
610 request = (MainThreadRequest) msg.obj;
611 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800612 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 if (uiccCard == null) {
614 loge("iccExchangeSimIO: No UICC");
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 } else {
618 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
619 request);
620 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
621 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
622 iccArgument.data, onCompleted);
623 }
624 break;
625
626 case EVENT_EXCHANGE_SIM_IO_DONE:
627 ar = (AsyncResult) msg.obj;
628 request = (MainThreadRequest) ar.userObj;
629 if (ar.exception == null && ar.result != null) {
630 request.result = ar.result;
631 } else {
632 request.result = new IccIoResult(0x6f, 0, (byte[])null);
633 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 break;
636
Derek Tan4d5e5c12014-02-04 11:54:58 -0800637 case CMD_SEND_ENVELOPE:
638 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800639 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 if (uiccCard == null) {
641 loge("sendEnvelopeWithStatus: No UICC");
642 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 } else {
645 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
646 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
647 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800648 break;
649
650 case EVENT_SEND_ENVELOPE_DONE:
651 ar = (AsyncResult) msg.obj;
652 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700653 if (ar.exception == null && ar.result != null) {
654 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800655 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700656 request.result = new IccIoResult(0x6F, 0, (byte[])null);
657 if (ar.result == null) {
658 loge("sendEnvelopeWithStatus: Empty response");
659 } else if (ar.exception instanceof CommandException) {
660 loge("sendEnvelopeWithStatus: CommandException: " +
661 ar.exception);
662 } else {
663 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
664 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800665 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800667 break;
668
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 case CMD_OPEN_CHANNEL:
670 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800671 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800672 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700673 if (uiccCard == null) {
674 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800675 request.result = new IccOpenLogicalChannelResponse(-1,
676 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 } else {
679 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800680 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
681 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 break;
684
685 case EVENT_OPEN_CHANNEL_DONE:
686 ar = (AsyncResult) msg.obj;
687 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700688 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700690 int[] result = (int[]) ar.result;
691 int channelId = result[0];
692 byte[] selectResponse = null;
693 if (result.length > 1) {
694 selectResponse = new byte[result.length - 1];
695 for (int i = 1; i < result.length; ++i) {
696 selectResponse[i - 1] = (byte) result[i];
697 }
698 }
699 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700700 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 if (ar.result == null) {
703 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 if (ar.exception != null) {
706 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
707 }
708
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700709 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700710 if (ar.exception instanceof CommandException) {
711 CommandException.Error error =
712 ((CommandException) (ar.exception)).getCommandError();
713 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700714 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700715 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700716 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700717 }
718 }
719 openChannelResp = new IccOpenLogicalChannelResponse(
720 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700722 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700723 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 break;
725
726 case CMD_CLOSE_CHANNEL:
727 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800728 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700729 if (uiccCard == null) {
730 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900731 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 } else {
734 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
735 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
736 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 break;
738
739 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800740 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
741 break;
742
743 case CMD_NV_READ_ITEM:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800746 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
747 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800748 break;
749
750 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700751 ar = (AsyncResult) msg.obj;
752 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800753 if (ar.exception == null && ar.result != null) {
754 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800756 request.result = "";
757 if (ar.result == null) {
758 loge("nvReadItem: Empty response");
759 } else if (ar.exception instanceof CommandException) {
760 loge("nvReadItem: CommandException: " +
761 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800763 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 }
765 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700766 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 break;
768
Jake Hambye994d462014-02-03 13:10:13 -0800769 case CMD_NV_WRITE_ITEM:
770 request = (MainThreadRequest) msg.obj;
771 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
772 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800773 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700774 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800775 break;
776
777 case EVENT_NV_WRITE_ITEM_DONE:
778 handleNullReturnEvent(msg, "nvWriteItem");
779 break;
780
781 case CMD_NV_WRITE_CDMA_PRL:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
787 case EVENT_NV_WRITE_CDMA_PRL_DONE:
788 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
789 break;
790
chen xu6dac5ab2018-10-26 17:39:23 -0700791 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800792 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700793 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800794 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800795 break;
796
chen xu6dac5ab2018-10-26 17:39:23 -0700797 case EVENT_RESET_MODEM_CONFIG_DONE:
798 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800799 break;
800
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700801 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
804 request);
805 Phone phone = getPhoneFromRequest(request);
806 if (phone != null) {
807 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
808 } else {
809 loge("isNRDualConnectivityEnabled: No phone object");
810 request.result = false;
811 notifyRequester(request);
812 }
813 break;
814 }
815
816 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
817 ar = (AsyncResult) msg.obj;
818 request = (MainThreadRequest) ar.userObj;
819 if (ar.exception == null && ar.result != null) {
820 request.result = ar.result;
821 } else {
822 // request.result must be set to something non-null
823 // for the calling thread to unblock
824 if (request.result != null) {
825 request.result = ar.result;
826 } else {
827 request.result = false;
828 }
829 if (ar.result == null) {
830 loge("isNRDualConnectivityEnabled: Empty response");
831 } else if (ar.exception instanceof CommandException) {
832 loge("isNRDualConnectivityEnabled: CommandException: "
833 + ar.exception);
834 } else {
835 loge("isNRDualConnectivityEnabled: Unknown exception");
836 }
837 }
838 notifyRequester(request);
839 break;
840
841 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
842 request = (MainThreadRequest) msg.obj;
843 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
844 Phone phone = getPhoneFromRequest(request);
845 if (phone != null) {
846 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
847 request.workSource);
848 } else {
849 loge("enableNrDualConnectivity: No phone object");
850 request.result =
851 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
852 notifyRequester(request);
853 }
854 break;
855 }
856
857 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
858 ar = (AsyncResult) msg.obj;
859 request = (MainThreadRequest) ar.userObj;
860 if (ar.exception == null) {
861 request.result =
862 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
863 } else {
864 request.result =
865 TelephonyManager
866 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
867 if (ar.exception instanceof CommandException) {
868 CommandException.Error error =
869 ((CommandException) (ar.exception)).getCommandError();
870 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
871 request.result =
872 TelephonyManager
873 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000874 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
875 request.result =
876 TelephonyManager
877 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700878 }
879 loge("enableNrDualConnectivity" + ": CommandException: "
880 + ar.exception);
881 } else {
882 loge("enableNrDualConnectivity" + ": Unknown exception");
883 }
884 }
885 notifyRequester(request);
886 break;
887 }
888
SongFerngWang9e060372020-12-21 16:41:52 +0800889 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800890 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800891 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
892 request);
893 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800894 break;
895
SongFerngWang9e060372020-12-21 16:41:52 +0800896 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result; // Integer
901 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530902 // request.result must be set to something non-null
903 // for the calling thread to unblock
904 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800906 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800908 loge("getAllowedNetworkTypesBitmask: CommandException: "
909 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800911 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800912 }
913 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700914 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800915 break;
916
SongFerngWang9e060372020-12-21 16:41:52 +0800917 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800919 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
920 request);
921 Pair<Integer, Long> reasonWithNetworkTypes =
922 (Pair<Integer, Long>) request.argument;
923 getPhoneFromRequest(request).setAllowedNetworkTypes(
924 reasonWithNetworkTypes.first,
925 reasonWithNetworkTypes.second,
926 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800927 break;
928
SongFerngWang9e060372020-12-21 16:41:52 +0800929 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
930 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800931 break;
932
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000933 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
934 request = (MainThreadRequest)msg.obj;
935 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800936 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000937 break;
938
939 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
940 ar = (AsyncResult)msg.obj;
941 request = (MainThreadRequest)ar.userObj;
942 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700943 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000944 break;
945
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800946 case CMD_SET_VOICEMAIL_NUMBER:
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
949 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800950 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
951 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800952 break;
953
954 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
955 handleNullReturnEvent(msg, "setVoicemailNumber");
956 break;
957
Stuart Scott54788802015-03-30 13:18:01 -0700958 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
961 request);
962 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
963 break;
964
965 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
966 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
967 break;
968
Shishir Agrawal302c8692015-06-19 13:49:39 -0700969 case CMD_PERFORM_NETWORK_SCAN:
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
972 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
973 break;
974
Hall Liua1acea22020-09-18 19:04:59 -0700975 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800976 request = (MainThreadRequest) msg.obj;
977 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700978 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
979 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
980 request.argument;
981 int callForwardingReason = args.first;
982 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800983 break;
Hall Liua1acea22020-09-18 19:04:59 -0700984 }
985 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700988 TelephonyManager.CallForwardingInfoCallback callback =
989 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
990 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800991 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700992 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800993 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
994 for (CallForwardInfo callForwardInfo : callForwardInfos) {
995 // Service Class is a bit mask per 3gpp 27.007. Search for
996 // any service for voice call.
997 if ((callForwardInfo.serviceClass
998 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700999 callForwardingInfo = new CallForwardingInfo(true,
1000 callForwardInfo.reason,
1001 callForwardInfo.number,
1002 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -08001003 break;
1004 }
1005 }
1006 // Didn't find a call forward info for voice call.
1007 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -07001008 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1009 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001010 }
Hall Liua1acea22020-09-18 19:04:59 -07001011 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001012 } else {
1013 if (ar.result == null) {
1014 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1015 }
1016 if (ar.exception != null) {
1017 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1018 }
Hall Liuae527aa2020-09-29 17:10:18 -07001019 int errorCode = TelephonyManager
1020 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001021 if (ar.exception instanceof CommandException) {
1022 CommandException.Error error =
1023 ((CommandException) (ar.exception)).getCommandError();
1024 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001025 errorCode = TelephonyManager
1026 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001027 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001028 errorCode = TelephonyManager
1029 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001030 }
1031 }
Hall Liua1acea22020-09-18 19:04:59 -07001032 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001033 }
sqian80370722020-01-29 15:02:51 -08001034 break;
Hall Liua1acea22020-09-18 19:04:59 -07001035 }
sqian80370722020-01-29 15:02:51 -08001036
Hall Liua1acea22020-09-18 19:04:59 -07001037 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001038 request = (MainThreadRequest) msg.obj;
1039 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001040 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001041 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001042 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1043 request.argument).first;
1044 request.phone.setCallForwardingOption(
1045 callForwardingInfoToSet.isEnabled()
1046 ? CommandsInterface.CF_ACTION_ENABLE
1047 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001048 callForwardingInfoToSet.getReason(),
1049 callForwardingInfoToSet.getNumber(),
1050 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1051 break;
Hall Liua1acea22020-09-18 19:04:59 -07001052 }
sqian80370722020-01-29 15:02:51 -08001053
Hall Liua1acea22020-09-18 19:04:59 -07001054 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001057 Consumer<Integer> callback =
1058 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1059 request.argument).second;
1060 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001061 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001062 int errorCode = TelephonyManager.CallForwardingInfoCallback
1063 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001064 if (ar.exception instanceof CommandException) {
1065 CommandException.Error error =
1066 ((CommandException) (ar.exception)).getCommandError();
1067 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001068 errorCode = TelephonyManager.CallForwardingInfoCallback
1069 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001070 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001071 errorCode = TelephonyManager.CallForwardingInfoCallback
1072 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001073 }
1074 }
1075 callback.accept(errorCode);
1076 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001077 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001078 }
sqian80370722020-01-29 15:02:51 -08001079 break;
Hall Liua1acea22020-09-18 19:04:59 -07001080 }
sqian80370722020-01-29 15:02:51 -08001081
Hall Liua1acea22020-09-18 19:04:59 -07001082 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001083 request = (MainThreadRequest) msg.obj;
1084 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1085 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1086 break;
Hall Liua1acea22020-09-18 19:04:59 -07001087 }
sqian80370722020-01-29 15:02:51 -08001088
Hall Liua1acea22020-09-18 19:04:59 -07001089 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001090 ar = (AsyncResult) msg.obj;
1091 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001092 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001093 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1094 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001095 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001096 // Service Class is a bit mask per 3gpp 27.007.
1097 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001098 if (callForwardResults.length > 1
1099 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001100 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001101 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001102 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1103 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001104 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001105 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001106 }
1107 } else {
1108 if (ar.result == null) {
1109 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1110 }
1111 if (ar.exception != null) {
1112 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1113 }
1114 if (ar.exception instanceof CommandException) {
1115 CommandException.Error error =
1116 ((CommandException) (ar.exception)).getCommandError();
1117 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1118 callForwardingStatus =
1119 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1120 }
1121 }
1122 }
Hall Liua1acea22020-09-18 19:04:59 -07001123 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001124 break;
Hall Liua1acea22020-09-18 19:04:59 -07001125 }
sqian80370722020-01-29 15:02:51 -08001126
Hall Liua1acea22020-09-18 19:04:59 -07001127 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001128 request = (MainThreadRequest) msg.obj;
1129 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001130 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1131 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001132 break;
Hall Liua1acea22020-09-18 19:04:59 -07001133 }
sqian80370722020-01-29 15:02:51 -08001134
Hall Liua1acea22020-09-18 19:04:59 -07001135 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001136 ar = (AsyncResult) msg.obj;
1137 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001138 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1139 Consumer<Integer> callback =
1140 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1141 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001142 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001143 if (ar.exception instanceof CommandException) {
1144 CommandException.Error error =
1145 ((CommandException) (ar.exception)).getCommandError();
1146 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1147 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1148 } else {
1149 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1150 }
1151 } else {
1152 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1153 }
1154 } else {
1155 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1156 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001157 }
sqian80370722020-01-29 15:02:51 -08001158 break;
Hall Liua1acea22020-09-18 19:04:59 -07001159 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001160 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1161 ar = (AsyncResult) msg.obj;
1162 request = (MainThreadRequest) ar.userObj;
1163 CellNetworkScanResult cellScanResult;
1164 if (ar.exception == null && ar.result != null) {
1165 cellScanResult = new CellNetworkScanResult(
1166 CellNetworkScanResult.STATUS_SUCCESS,
1167 (List<OperatorInfo>) ar.result);
1168 } else {
1169 if (ar.result == null) {
1170 loge("getCellNetworkScanResults: Empty response");
1171 }
1172 if (ar.exception != null) {
1173 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1174 }
1175 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1176 if (ar.exception instanceof CommandException) {
1177 CommandException.Error error =
1178 ((CommandException) (ar.exception)).getCommandError();
1179 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1180 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1181 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1182 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1183 }
1184 }
1185 cellScanResult = new CellNetworkScanResult(errorCode, null);
1186 }
1187 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001188 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001189 break;
1190
1191 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1192 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001193 ManualNetworkSelectionArgument selArg =
1194 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001195 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1196 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001197 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1198 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001199 break;
1200
1201 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001202 ar = (AsyncResult) msg.obj;
1203 request = (MainThreadRequest) ar.userObj;
1204 if (ar.exception == null) {
1205 request.result = true;
1206 } else {
1207 request.result = false;
1208 loge("setNetworkSelectionModeManual " + ar.exception);
1209 }
1210 notifyRequester(request);
1211 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001212 break;
1213
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001214 case CMD_GET_MODEM_ACTIVITY_INFO:
1215 request = (MainThreadRequest) msg.obj;
1216 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001217 if (defaultPhone != null) {
1218 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001219 } else {
1220 ResultReceiver result = (ResultReceiver) request.argument;
1221 Bundle bundle = new Bundle();
1222 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1223 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1224 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001225 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001226 break;
1227
1228 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1229 ar = (AsyncResult) msg.obj;
1230 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001231 ResultReceiver result = (ResultReceiver) request.argument;
1232
1233 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001234 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001235 // Update the last modem activity info and the result of the request.
1236 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1237 if (isModemActivityInfoValid(info)) {
1238 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1239 int[] txTimeMs = info.getTransmitTimeMillis();
1240 int[] lastModemTxTimeMs = mLastModemActivityInfo
1241 .getTransmitTimeMillis();
1242 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1243 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1244 }
1245 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1246 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1247 + mLastModemActivityInfo.getSleepTimeMillis());
1248 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1249 + mLastModemActivityInfo.getIdleTimeMillis());
1250 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1251 mLastModemActivityInfo.setReceiveTimeMillis(
1252 info.getReceiveTimeMillis()
1253 + mLastModemActivityInfo.getReceiveTimeMillis());
1254 }
1255 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1256 mLastModemActivityInfo.getSleepTimeMillis(),
1257 mLastModemActivityInfo.getIdleTimeMillis(),
1258 mLastModemActivityInfo.getTransmitTimeMillis(),
1259 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001260 } else {
1261 if (ar.result == null) {
1262 loge("queryModemActivityInfo: Empty response");
1263 } else if (ar.exception instanceof CommandException) {
1264 loge("queryModemActivityInfo: CommandException: " +
1265 ar.exception);
1266 } else {
1267 loge("queryModemActivityInfo: Unknown exception");
1268 }
1269 }
sqian1a1be542020-03-05 11:37:28 -08001270 Bundle bundle = new Bundle();
1271 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1272 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001273 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001274 break;
1275
Meng Wang1a7c35a2016-05-05 20:56:15 -07001276 case CMD_SET_ALLOWED_CARRIERS:
1277 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001278 CarrierRestrictionRules argument =
1279 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001280 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001281 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001282 break;
1283
1284 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1285 ar = (AsyncResult) msg.obj;
1286 request = (MainThreadRequest) ar.userObj;
1287 if (ar.exception == null && ar.result != null) {
1288 request.result = ar.result;
1289 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001290 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1291 if (ar.exception instanceof CommandException) {
1292 loge("setAllowedCarriers: CommandException: " + ar.exception);
1293 CommandException.Error error =
1294 ((CommandException) (ar.exception)).getCommandError();
1295 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1296 request.result =
1297 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1298 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 } else {
1300 loge("setAllowedCarriers: Unknown exception");
1301 }
1302 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001303 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001304 break;
1305
1306 case CMD_GET_ALLOWED_CARRIERS:
1307 request = (MainThreadRequest) msg.obj;
1308 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001309 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001310 break;
1311
1312 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1313 ar = (AsyncResult) msg.obj;
1314 request = (MainThreadRequest) ar.userObj;
1315 if (ar.exception == null && ar.result != null) {
1316 request.result = ar.result;
1317 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001318 request.result = new IllegalStateException(
1319 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001320 if (ar.result == null) {
1321 loge("getAllowedCarriers: Empty response");
1322 } else if (ar.exception instanceof CommandException) {
1323 loge("getAllowedCarriers: CommandException: " +
1324 ar.exception);
1325 } else {
1326 loge("getAllowedCarriers: Unknown exception");
1327 }
1328 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001329 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001330 break;
1331
Nathan Haroldb3014052017-01-25 15:57:32 -08001332 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1333 ar = (AsyncResult) msg.obj;
1334 request = (MainThreadRequest) ar.userObj;
1335 if (ar.exception == null && ar.result != null) {
1336 request.result = ar.result;
1337 } else {
1338 request.result = new IllegalArgumentException(
1339 "Failed to retrieve Forbidden Plmns");
1340 if (ar.result == null) {
1341 loge("getForbiddenPlmns: Empty response");
1342 } else {
1343 loge("getForbiddenPlmns: Unknown exception");
1344 }
1345 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001346 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001347 break;
1348
1349 case CMD_GET_FORBIDDEN_PLMNS:
1350 request = (MainThreadRequest) msg.obj;
1351 uiccCard = getUiccCardFromRequest(request);
1352 if (uiccCard == null) {
1353 loge("getForbiddenPlmns() UiccCard is null");
1354 request.result = new IllegalArgumentException(
1355 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001356 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001357 break;
1358 }
1359 Integer appType = (Integer) request.argument;
1360 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1361 if (uiccApp == null) {
1362 loge("getForbiddenPlmns() no app with specified type -- "
1363 + appType);
1364 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001365 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001366 break;
1367 } else {
1368 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1369 + " specified type -- " + appType);
1370 }
1371 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1372 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1373 onCompleted);
1374 break;
1375
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001376 case CMD_SWITCH_SLOTS:
1377 request = (MainThreadRequest) msg.obj;
1378 int[] physicalSlots = (int[]) request.argument;
1379 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1380 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1381 break;
1382
1383 case EVENT_SWITCH_SLOTS_DONE:
1384 ar = (AsyncResult) msg.obj;
1385 request = (MainThreadRequest) ar.userObj;
1386 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001387 notifyRequester(request);
1388 break;
1389 case CMD_GET_NETWORK_SELECTION_MODE:
1390 request = (MainThreadRequest) msg.obj;
1391 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1392 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1393 break;
1394
1395 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1396 ar = (AsyncResult) msg.obj;
1397 request = (MainThreadRequest) ar.userObj;
1398 if (ar.exception != null) {
1399 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1400 } else {
1401 int mode = ((int[]) ar.result)[0];
1402 if (mode == 0) {
1403 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1404 } else {
1405 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1406 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001407 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001408 notifyRequester(request);
1409 break;
1410 case CMD_GET_CDMA_ROAMING_MODE:
1411 request = (MainThreadRequest) msg.obj;
1412 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1413 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1414 break;
1415 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1416 ar = (AsyncResult) msg.obj;
1417 request = (MainThreadRequest) ar.userObj;
1418 if (ar.exception != null) {
1419 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1420 } else {
1421 request.result = ((int[]) ar.result)[0];
1422 }
1423 notifyRequester(request);
1424 break;
1425 case CMD_SET_CDMA_ROAMING_MODE:
1426 request = (MainThreadRequest) msg.obj;
1427 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1428 int mode = (int) request.argument;
1429 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1430 break;
1431 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1432 ar = (AsyncResult) msg.obj;
1433 request = (MainThreadRequest) ar.userObj;
1434 request.result = ar.exception == null;
1435 notifyRequester(request);
1436 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001437 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1438 request = (MainThreadRequest) msg.obj;
1439 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1440 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1441 break;
1442 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1443 ar = (AsyncResult) msg.obj;
1444 request = (MainThreadRequest) ar.userObj;
1445 if (ar.exception != null) {
1446 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1447 } else {
1448 request.result = ((int[]) ar.result)[0];
1449 }
1450 notifyRequester(request);
1451 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001452 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1453 request = (MainThreadRequest) msg.obj;
1454 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1455 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001456 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1457 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001458 break;
1459 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 request.result = ar.exception == null;
1463 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001464 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001465 case CMD_GET_ALL_CELL_INFO:
1466 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001467 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001468 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001469 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001470 case EVENT_GET_ALL_CELL_INFO_DONE:
1471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001473 // If a timeout occurs, the response will be null
1474 request.result = (ar.exception == null && ar.result != null)
1475 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001476 synchronized (request) {
1477 request.notifyAll();
1478 }
1479 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001480 case CMD_REQUEST_CELL_INFO_UPDATE:
1481 request = (MainThreadRequest) msg.obj;
1482 request.phone.requestCellInfoUpdate(request.workSource,
1483 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1484 break;
1485 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1486 ar = (AsyncResult) msg.obj;
1487 request = (MainThreadRequest) ar.userObj;
1488 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1489 try {
1490 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001491 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001492 cb.onError(
1493 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1494 ar.exception.getClass().getName(),
1495 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001496 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001497 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001498 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001499 } else {
1500 // use the result as returned
1501 cb.onCellInfo((List<CellInfo>) ar.result);
1502 }
1503 } catch (RemoteException re) {
1504 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1505 }
1506 break;
Sarah Chincc055732020-11-18 13:39:35 -08001507 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001508 request = (MainThreadRequest) msg.obj;
1509 WorkSource ws = (WorkSource) request.argument;
1510 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001511 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001512 break;
Sarah Chincc055732020-11-18 13:39:35 -08001513 }
1514 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001515 ar = (AsyncResult) msg.obj;
1516 request = (MainThreadRequest) ar.userObj;
1517 if (ar.exception == null) {
1518 request.result = ar.result;
1519 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001520 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001521 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001522 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001523 }
1524
1525 synchronized (request) {
1526 request.notifyAll();
1527 }
1528 break;
Sarah Chincc055732020-11-18 13:39:35 -08001529 }
chen xu6dac5ab2018-10-26 17:39:23 -07001530 case CMD_MODEM_REBOOT:
1531 request = (MainThreadRequest) msg.obj;
1532 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001533 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001534 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001535 case EVENT_CMD_MODEM_REBOOT_DONE:
1536 handleNullReturnEvent(msg, "rebootModem");
1537 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001538 case CMD_REQUEST_ENABLE_MODEM:
1539 request = (MainThreadRequest) msg.obj;
1540 boolean enable = (boolean) request.argument;
1541 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001542 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001543 PhoneConfigurationManager.getInstance()
1544 .enablePhone(request.phone, enable, onCompleted);
1545 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001546 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001547 ar = (AsyncResult) msg.obj;
1548 request = (MainThreadRequest) ar.userObj;
1549 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001550 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001551 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001552 if ((boolean) request.result) {
1553 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1554 updateModemStateMetrics();
1555 } else {
1556 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1557 + ar.exception);
1558 }
1559 notifyRequester(request);
1560 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001561 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001562 case CMD_GET_MODEM_STATUS:
1563 request = (MainThreadRequest) msg.obj;
1564 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1565 PhoneConfigurationManager.getInstance()
1566 .getPhoneStatusFromModem(request.phone, onCompleted);
1567 break;
1568 case EVENT_GET_MODEM_STATUS_DONE:
1569 ar = (AsyncResult) msg.obj;
1570 request = (MainThreadRequest) ar.userObj;
1571 int id = request.phone.getPhoneId();
1572 if (ar.exception == null && ar.result != null) {
1573 request.result = ar.result;
1574 //update the cache as modem status has changed
1575 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1576 (boolean) request.result);
1577 } else {
1578 // Return true if modem status cannot be retrieved. For most cases,
1579 // modem status is on. And for older version modems, GET_MODEM_STATUS
1580 // and disable modem are not supported. Modem is always on.
1581 // TODO: this should be fixed in R to support a third
1582 // status UNKNOWN b/131631629
1583 request.result = true;
1584 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1585 + ar.exception);
1586 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001587 notifyRequester(request);
1588 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001589 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1590 request = (MainThreadRequest) msg.obj;
1591 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1592 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1593 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1594 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1595 break;
1596 }
1597 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1598 ar = (AsyncResult) msg.obj;
1599 request = (MainThreadRequest) ar.userObj;
1600 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1601 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1602 args.second.accept(ar.exception == null);
1603 notifyRequester(request);
1604 break;
1605 }
Sarah Chincc055732020-11-18 13:39:35 -08001606 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1607 request = (MainThreadRequest) msg.obj;
1608 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1609 Phone phone = getPhoneFromRequest(request);
1610 if (phone != null) {
1611 phone.getSystemSelectionChannels(onCompleted);
1612 } else {
1613 loge("getSystemSelectionChannels: No phone object");
1614 request.result = new ArrayList<RadioAccessSpecifier>();
1615 notifyRequester(request);
1616 }
1617 break;
1618 }
1619 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 if (ar.exception == null && ar.result != null) {
1623 request.result = ar.result;
1624 } else {
Sarah Chin58691872021-03-13 03:17:40 -08001625 request.result = new IllegalStateException(
1626 "Failed to retrieve system selecton channels");
Sarah Chincc055732020-11-18 13:39:35 -08001627 if (ar.result == null) {
1628 loge("getSystemSelectionChannels: Empty response");
1629 } else {
1630 loge("getSystemSelectionChannels: Unknown exception");
1631 }
1632 }
1633 notifyRequester(request);
1634 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001635 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1636 ar = (AsyncResult) msg.obj;
1637 request = (MainThreadRequest) ar.userObj;
1638 if (ar.exception == null && ar.result != null) {
1639 request.result = ar.result;
1640 } else {
1641 request.result = -1;
1642 loge("Failed to set Forbidden Plmns");
1643 if (ar.result == null) {
1644 loge("setForbidenPlmns: Empty response");
1645 } else if (ar.exception != null) {
1646 loge("setForbiddenPlmns: Exception: " + ar.exception);
1647 request.result = -1;
1648 } else {
1649 loge("setForbiddenPlmns: Unknown exception");
1650 }
1651 }
1652 notifyRequester(request);
1653 break;
1654 case CMD_SET_FORBIDDEN_PLMNS:
1655 request = (MainThreadRequest) msg.obj;
1656 uiccCard = getUiccCardFromRequest(request);
1657 if (uiccCard == null) {
1658 loge("setForbiddenPlmns: UiccCard is null");
1659 request.result = -1;
1660 notifyRequester(request);
1661 break;
1662 }
1663 Pair<Integer, List<String>> setFplmnsArgs =
1664 (Pair<Integer, List<String>>) request.argument;
1665 appType = setFplmnsArgs.first;
1666 List<String> fplmns = setFplmnsArgs.second;
1667 uiccApp = uiccCard.getApplicationByType(appType);
1668 if (uiccApp == null) {
1669 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1670 request.result = -1;
1671 loge("Failed to get UICC App");
1672 notifyRequester(request);
1673 } else {
1674 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1675 ((SIMRecords) uiccApp.getIccRecords())
1676 .setForbiddenPlmns(onCompleted, fplmns);
1677 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001678 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001679 case CMD_ERASE_MODEM_CONFIG:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1682 defaultPhone.eraseModemConfig(onCompleted);
1683 break;
1684 case EVENT_ERASE_MODEM_CONFIG_DONE:
1685 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001686 break;
zoey chenf95ca592019-12-30 16:11:23 +08001687
1688 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1689 request = (MainThreadRequest) msg.obj;
1690 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1691 Pair<String, String> changed = (Pair<String, String>) request.argument;
1692 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1693 changed.first, changed.second, onCompleted);
1694 break;
1695 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1696 ar = (AsyncResult) msg.obj;
1697 request = (MainThreadRequest) ar.userObj;
1698 if (ar.exception == null) {
1699 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001700 // If the operation is successful, update the PIN storage
1701 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1702 int phoneId = getPhoneFromRequest(request).getPhoneId();
1703 UiccController.getInstance().getPinStorage()
1704 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001705 } else {
1706 request.result = msg.arg1;
1707 }
1708 notifyRequester(request);
1709 break;
1710
Michele Berionned9fbae52020-11-13 02:36:59 +00001711 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001712 request = (MainThreadRequest) msg.obj;
1713 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1714 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1715 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1716 enabled.first, enabled.second, onCompleted);
1717 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001718 }
zoey chenf95ca592019-12-30 16:11:23 +08001719 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1720 ar = (AsyncResult) msg.obj;
1721 request = (MainThreadRequest) ar.userObj;
1722 if (ar.exception == null) {
1723 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001724 // If the operation is successful, update the PIN storage
1725 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1726 int phoneId = getPhoneFromRequest(request).getPhoneId();
1727 if (enabled.first) {
1728 UiccController.getInstance().getPinStorage()
1729 .storePin(enabled.second, phoneId);
1730 } else {
1731 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1732 }
zoey chenf95ca592019-12-30 16:11:23 +08001733 } else {
1734 request.result = msg.arg1;
1735 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001736
1737
zoey chenf95ca592019-12-30 16:11:23 +08001738 notifyRequester(request);
1739 break;
1740
Peter Wangdafb9ac2020-01-15 14:13:38 -08001741 case MSG_NOTIFY_USER_ACTIVITY:
1742 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001743 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001744 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1745 getDefaultPhone().getContext().sendBroadcastAsUser(
1746 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1747 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001748
1749 case CMD_SET_DATA_THROTTLING: {
1750 request = (MainThreadRequest) msg.obj;
1751 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1752 DataThrottlingRequest dataThrottlingRequest =
1753 (DataThrottlingRequest) request.argument;
1754 Phone phone = getPhoneFromRequest(request);
1755 if (phone != null) {
1756 phone.setDataThrottling(onCompleted,
1757 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1758 dataThrottlingRequest.getCompletionDurationMillis());
1759 } else {
1760 loge("setDataThrottling: No phone object");
1761 request.result =
1762 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1763 notifyRequester(request);
1764 }
1765
1766 break;
1767 }
1768 case EVENT_SET_DATA_THROTTLING_DONE:
1769 ar = (AsyncResult) msg.obj;
1770 request = (MainThreadRequest) ar.userObj;
1771
1772 if (ar.exception == null) {
1773 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1774 } else if (ar.exception instanceof CommandException) {
1775 loge("setDataThrottling: CommandException: " + ar.exception);
1776 CommandException.Error error =
1777 ((CommandException) (ar.exception)).getCommandError();
1778
1779 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1780 request.result = TelephonyManager
1781 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1782 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1783 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001784 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1785 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001786 } else {
1787 request.result =
1788 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1789 }
1790 } else {
1791 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1792 }
1793 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1794 notifyRequester(request);
1795 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001796
1797 case CMD_SET_SIM_POWER: {
1798 request = (MainThreadRequest) msg.obj;
1799 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1800 request = (MainThreadRequest) msg.obj;
1801 int stateToSet =
1802 ((Pair<Integer, IIntegerConsumer>)
1803 request.argument).first;
1804 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1805 break;
1806 }
1807 case EVENT_SET_SIM_POWER_DONE: {
1808 ar = (AsyncResult) msg.obj;
1809 request = (MainThreadRequest) ar.userObj;
1810 IIntegerConsumer callback =
1811 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1812 if (ar.exception != null) {
1813 loge("setSimPower exception: " + ar.exception);
1814 int errorCode = TelephonyManager.CallForwardingInfoCallback
1815 .RESULT_ERROR_UNKNOWN;
1816 if (ar.exception instanceof CommandException) {
1817 CommandException.Error error =
1818 ((CommandException) (ar.exception)).getCommandError();
1819 if (error == CommandException.Error.SIM_ERR) {
1820 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1821 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1822 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1823 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1824 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1825 } else {
1826 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1827 }
1828 }
1829 try {
1830 callback.accept(errorCode);
1831 } catch (RemoteException e) {
1832 // Ignore if the remote process is no longer available to call back.
1833 Log.w(LOG_TAG, "setSimPower: callback not available.");
1834 }
1835 } else {
1836 try {
1837 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1838 } catch (RemoteException e) {
1839 // Ignore if the remote process is no longer available to call back.
1840 Log.w(LOG_TAG, "setSimPower: callback not available.");
1841 }
1842 }
1843 break;
1844 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001845 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1846 request = (MainThreadRequest) msg.obj;
1847
1848 final Phone phone = getPhoneFromRequest(request);
1849 if (phone == null || phone.getServiceStateTracker() == null) {
1850 request.result = new IllegalStateException("Phone or SST is null");
1851 notifyRequester(request);
1852 break;
1853 }
1854
1855 Pair<Integer, SignalStrengthUpdateRequest> pair =
1856 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1857 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1858 request);
1859 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1860 request.subId, pair.first /*callingUid*/,
1861 pair.second /*request*/, onCompleted);
1862 break;
1863 }
1864 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1865 ar = (AsyncResult) msg.obj;
1866 request = (MainThreadRequest) ar.userObj;
1867 // request.result will be the exception of ar if present, true otherwise.
1868 // Be cautious not to leave result null which will wait() forever
1869 request.result = ar.exception != null ? ar.exception : true;
1870 notifyRequester(request);
1871 break;
1872 }
1873 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1874 request = (MainThreadRequest) msg.obj;
1875
1876 Phone phone = getPhoneFromRequest(request);
1877 if (phone == null || phone.getServiceStateTracker() == null) {
1878 request.result = new IllegalStateException("Phone or SST is null");
1879 notifyRequester(request);
1880 break;
1881 }
1882
1883 Pair<Integer, SignalStrengthUpdateRequest> pair =
1884 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1885 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1886 request);
1887 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1888 request.subId, pair.first /*callingUid*/,
1889 pair.second /*request*/, onCompleted);
1890 break;
1891 }
1892 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1893 ar = (AsyncResult) msg.obj;
1894 request = (MainThreadRequest) ar.userObj;
1895 request.result = ar.exception != null ? ar.exception : true;
1896 notifyRequester(request);
1897 break;
1898 }
Jordan Liud5366d92020-11-24 14:50:34 -08001899
Michele Berionned9fbae52020-11-13 02:36:59 +00001900 case CMD_PREPARE_UNATTENDED_REBOOT:
1901 request = (MainThreadRequest) msg.obj;
1902 request.result =
1903 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1904 notifyRequester(request);
1905 break;
1906
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 default:
1908 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1909 break;
1910 }
1911 }
Jake Hambye994d462014-02-03 13:10:13 -08001912
Pengquan Menga1bb6272018-09-06 09:59:22 -07001913 private void notifyRequester(MainThreadRequest request) {
1914 synchronized (request) {
1915 request.notifyAll();
1916 }
1917 }
1918
Jake Hambye994d462014-02-03 13:10:13 -08001919 private void handleNullReturnEvent(Message msg, String command) {
1920 AsyncResult ar = (AsyncResult) msg.obj;
1921 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1922 if (ar.exception == null) {
1923 request.result = true;
1924 } else {
1925 request.result = false;
1926 if (ar.exception instanceof CommandException) {
1927 loge(command + ": CommandException: " + ar.exception);
1928 } else {
1929 loge(command + ": Unknown exception");
1930 }
1931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001932 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 }
1935
1936 /**
1937 * Posts the specified command to be executed on the main thread,
1938 * waits for the request to complete, and returns the result.
1939 * @see #sendRequestAsync
1940 */
1941 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001942 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1943 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001944 }
1945
1946 /**
1947 * Posts the specified command to be executed on the main thread,
1948 * waits for the request to complete, and returns the result.
1949 * @see #sendRequestAsync
1950 */
1951 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1952 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001953 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001954 }
1955
1956 /**
1957 * Posts the specified command to be executed on the main thread,
1958 * waits for the request to complete, and returns the result.
1959 * @see #sendRequestAsync
1960 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001961 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001962 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1963 }
1964
1965 /**
1966 * Posts the specified command to be executed on the main thread,
1967 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1968 * if not timeout or null otherwise.
1969 * @see #sendRequestAsync
1970 */
1971 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1972 long timeoutInMs) {
1973 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001974 }
1975
1976 /**
1977 * Posts the specified command to be executed on the main thread,
1978 * waits for the request to complete, and returns the result.
1979 * @see #sendRequestAsync
1980 */
Nathan Harold92bed182018-10-12 18:16:49 -07001981 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001982 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001983 }
1984
1985 /**
1986 * Posts the specified command to be executed on the main thread,
1987 * waits for the request to complete, and returns the result.
1988 * @see #sendRequestAsync
1989 */
1990 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001991 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1992 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001993 }
1994
1995 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001996 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1997 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1998 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001999 * @see #sendRequestAsync
2000 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002001 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2002 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2004 throw new RuntimeException("This method will deadlock if called from the main thread.");
2005 }
2006
Nathan Harold92bed182018-10-12 18:16:49 -07002007 MainThreadRequest request = null;
2008 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2009 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2010 } else if (phone != null) {
2011 request = new MainThreadRequest(argument, phone, workSource);
2012 } else {
2013 request = new MainThreadRequest(argument, subId, workSource);
2014 }
2015
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 Message msg = mMainThreadHandler.obtainMessage(command, request);
2017 msg.sendToTarget();
2018
Rambo Wang0f050d82021-02-12 11:43:36 -08002019
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002021 if (timeoutInMs >= 0) {
2022 // Wait for at least timeoutInMs before returning null request result
2023 long now = SystemClock.elapsedRealtime();
2024 long deadline = now + timeoutInMs;
2025 while (request == null && now < deadline) {
2026 try {
2027 request.wait(deadline - now);
2028 } catch (InterruptedException e) {
2029 // Do nothing, go back and check if request is completed or timeout
2030 } finally {
2031 now = SystemClock.elapsedRealtime();
2032 }
2033 }
2034 } else {
2035 // Wait for the request to complete
2036 while (request.result == null) {
2037 try {
2038 request.wait();
2039 } catch (InterruptedException e) {
2040 // Do nothing, go back and wait until the request is complete
2041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 }
2043 }
2044 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002045 if (request.result == null) {
2046 Log.wtf(LOG_TAG,
2047 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 return request.result;
2050 }
2051
2052 /**
2053 * Asynchronous ("fire and forget") version of sendRequest():
2054 * Posts the specified command to be executed on the main thread, and
2055 * returns immediately.
2056 * @see #sendRequest
2057 */
2058 private void sendRequestAsync(int command) {
2059 mMainThreadHandler.sendEmptyMessage(command);
2060 }
2061
2062 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002063 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002064 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002065 */
2066 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002067 sendRequestAsync(command, argument, null, null);
2068 }
2069
2070 /**
2071 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2072 * @see {@link #sendRequest(int,Object)}
2073 */
2074 private void sendRequestAsync(
2075 int command, Object argument, Phone phone, WorkSource workSource) {
2076 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002077 Message msg = mMainThreadHandler.obtainMessage(command, request);
2078 msg.sendToTarget();
2079 }
2080
2081 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 * Initialize the singleton PhoneInterfaceManager instance.
2083 * This is only done once, at startup, from PhoneApp.onCreate().
2084 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002085 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 synchronized (PhoneInterfaceManager.class) {
2087 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002088 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 } else {
2090 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2091 }
2092 return sInstance;
2093 }
2094 }
2095
2096 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002097 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerc9c432e2021-05-17 20:54:49 +00002100 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002101 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2103 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002104 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002105 mTelephonySharedPreferences =
2106 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002107 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002108 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002109 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002110 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002111
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 publish();
2113 }
2114
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002115 private Phone getDefaultPhone() {
2116 Phone thePhone = getPhone(getDefaultSubscription());
2117 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2118 }
2119
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 private void publish() {
2121 if (DBG) log("publish: " + this);
2122
Peter Wangc035ce42020-01-08 21:00:22 -08002123 TelephonyFrameworkInitializer
2124 .getTelephonyServiceManager()
2125 .getTelephonyServiceRegisterer()
2126 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002127 }
2128
Stuart Scott584921c2015-01-15 17:10:34 -08002129 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002130 if (request.phone != null) {
2131 return request.phone;
2132 } else {
2133 return getPhoneFromSubId(request.subId);
2134 }
2135 }
2136
2137 private Phone getPhoneFromSubId(int subId) {
2138 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2139 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002140 }
2141
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002142 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2143 Phone phone = getPhoneFromRequest(request);
2144 return phone == null ? null :
2145 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2146 }
2147
Wink Saville36469e72014-06-11 15:17:00 -07002148 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002149 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002150 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002153 private void sendEraseModemConfig(Phone phone) {
2154 if (phone != null) {
2155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2156 mApp, phone.getSubId(), "eraseModemConfig");
2157 final long identity = Binder.clearCallingIdentity();
2158 try {
2159 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2160 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2161 } finally {
2162 Binder.restoreCallingIdentity(identity);
2163 }
2164 }
2165 }
2166
Peter Wang050bb052020-01-13 23:33:09 -08002167 private boolean isImsAvailableOnDevice() {
2168 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2169 if (pm == null) {
2170 // For some reason package manger is not available.. This will fail internally anyway,
2171 // so do not throw error and allow.
2172 return true;
2173 }
2174 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2175 }
2176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002178 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002179 }
2180
Wink Savilleb564aae2014-10-23 10:18:09 -07002181 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 if (DBG) log("dial: " + number);
2183 // No permission check needed here: This is just a wrapper around the
2184 // ACTION_DIAL intent, which is available to any app since it puts up
2185 // the UI before it does anything.
2186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002187 final long identity = Binder.clearCallingIdentity();
2188 try {
2189 String url = createTelUrl(number);
2190 if (url == null) {
2191 return;
2192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002194 // PENDING: should we just silently fail if phone is offhook or ringing?
2195 PhoneConstants.State state = mCM.getState(subId);
2196 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2197 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2198 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2199 mApp.startActivity(intent);
2200 }
2201 } finally {
2202 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 }
2204 }
2205
2206 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002207 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002208 }
2209
Wink Savilleb564aae2014-10-23 10:18:09 -07002210 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 if (DBG) log("call: " + number);
2212
2213 // This is just a wrapper around the ACTION_CALL intent, but we still
2214 // need to do a permission check since we're calling startActivity()
2215 // from the context of the phone app.
2216 enforceCallPermission();
2217
Jordan Liu1617b712019-07-10 15:06:26 -07002218 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 != AppOpsManager.MODE_ALLOWED) {
2220 return;
2221 }
2222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 String url = createTelUrl(number);
2226 if (url == null) {
2227 return;
2228 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230 boolean isValid = false;
2231 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2232 if (slist != null) {
2233 for (SubscriptionInfo subInfoRecord : slist) {
2234 if (subInfoRecord.getSubscriptionId() == subId) {
2235 isValid = true;
2236 break;
2237 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002238 }
Wink Saville08874612014-08-31 19:19:58 -07002239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002240 if (!isValid) {
2241 return;
2242 }
Wink Saville08874612014-08-31 19:19:58 -07002243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002244 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2245 intent.putExtra(SUBSCRIPTION_KEY, subId);
2246 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2247 mApp.startActivity(intent);
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
2250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
Wink Savilleb564aae2014-10-23 10:18:09 -07002253 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002254 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002255 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2256 }
2257
Wink Savilleb564aae2014-10-23 10:18:09 -07002258 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002259 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002260 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2261 }
2262
Wink Savilleb564aae2014-10-23 10:18:09 -07002263 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002265
2266 final long identity = Binder.clearCallingIdentity();
2267 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002268 Phone phone = getPhone(subId);
2269 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002270 checkSimPin.start();
2271 return checkSimPin.unlockSim(null, pin);
2272 } finally {
2273 Binder.restoreCallingIdentity(identity);
2274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 }
2276
Wink Savilleb564aae2014-10-23 10:18:09 -07002277 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279
2280 final long identity = Binder.clearCallingIdentity();
2281 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002282 Phone phone = getPhone(subId);
2283 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284 checkSimPuk.start();
2285 return checkSimPuk.unlockSim(puk, pin);
2286 } finally {
2287 Binder.restoreCallingIdentity(identity);
2288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 }
2290
2291 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002292 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 * a synchronous one.
2294 */
2295 private static class UnlockSim extends Thread {
2296
2297 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002298 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299
2300 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002301 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2302 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303
2304 // For replies from SimCard interface
2305 private Handler mHandler;
2306
2307 // For async handler to identify request type
2308 private static final int SUPPLY_PIN_COMPLETE = 100;
2309
Michele Berionned9fbae52020-11-13 02:36:59 +00002310 UnlockSim(int phoneId, IccCard simCard) {
2311 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 mSimCard = simCard;
2313 }
2314
2315 @Override
2316 public void run() {
2317 Looper.prepare();
2318 synchronized (UnlockSim.this) {
2319 mHandler = new Handler() {
2320 @Override
2321 public void handleMessage(Message msg) {
2322 AsyncResult ar = (AsyncResult) msg.obj;
2323 switch (msg.what) {
2324 case SUPPLY_PIN_COMPLETE:
2325 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2326 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002327 mRetryCount = msg.arg1;
2328 if (ar.exception != null) {
2329 if (ar.exception instanceof CommandException &&
2330 ((CommandException)(ar.exception)).getCommandError()
2331 == CommandException.Error.PASSWORD_INCORRECT) {
2332 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002333 } //When UiccCardApp dispose,handle message and return exception
2334 else if (ar.exception instanceof CommandException &&
2335 ((CommandException) (ar.exception)).getCommandError()
2336 == CommandException.Error.ABORTED) {
2337 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002338 } else {
2339 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2340 }
2341 } else {
2342 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 mDone = true;
2345 UnlockSim.this.notifyAll();
2346 }
2347 break;
2348 }
2349 }
2350 };
2351 UnlockSim.this.notifyAll();
2352 }
2353 Looper.loop();
2354 }
2355
2356 /*
2357 * Use PIN or PUK to unlock SIM card
2358 *
2359 * If PUK is null, unlock SIM card with PIN
2360 *
2361 * If PUK is not null, unlock SIM card with PUK and set PIN code
2362 */
Wink Saville9de0f752013-10-22 19:04:03 -07002363 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364
2365 while (mHandler == null) {
2366 try {
2367 wait();
2368 } catch (InterruptedException e) {
2369 Thread.currentThread().interrupt();
2370 }
2371 }
2372 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2373
2374 if (puk == null) {
2375 mSimCard.supplyPin(pin, callback);
2376 } else {
2377 mSimCard.supplyPuk(puk, pin, callback);
2378 }
2379
2380 while (!mDone) {
2381 try {
2382 Log.d(LOG_TAG, "wait for done");
2383 wait();
2384 } catch (InterruptedException e) {
2385 // Restore the interrupted status
2386 Thread.currentThread().interrupt();
2387 }
2388 }
2389 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002390 int[] resultArray = new int[2];
2391 resultArray[0] = mResult;
2392 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002393
2394 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2395 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2396 }
2397
Wink Saville9de0f752013-10-22 19:04:03 -07002398 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 }
2400 }
2401
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002402 /**
2403 * This method has been removed due to privacy and stability concerns.
2404 */
2405 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002407 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2408 return;
Wink Saville36469e72014-06-11 15:17:00 -07002409 }
2410
Nathan Harold1f889d82020-06-04 17:05:26 -07002411 @Override
2412 public void updateServiceLocationWithPackageName(String callingPackage) {
2413 mApp.getSystemService(AppOpsManager.class)
2414 .checkPackage(Binder.getCallingUid(), callingPackage);
2415
Nathan Haroldf096d982020-11-18 17:18:06 -08002416 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002417 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2418 // Callers targeting S have no business invoking this method.
2419 return;
2420 }
2421
2422 LocationAccessPolicy.LocationPermissionResult locationResult =
2423 LocationAccessPolicy.checkLocationPermission(mApp,
2424 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2425 .setCallingPackage(callingPackage)
2426 .setCallingFeatureId(null)
2427 .setCallingPid(Binder.getCallingPid())
2428 .setCallingUid(Binder.getCallingUid())
2429 .setMethod("updateServiceLocation")
2430 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2431 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2432 .build());
2433 // Apps that lack location permission have no business calling this method;
2434 // however, because no permission was declared in the public API, denials must
2435 // all be "soft".
2436 switch (locationResult) {
2437 case DENIED_HARD: /* fall through */
2438 case DENIED_SOFT:
2439 return;
2440 }
2441
2442 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002443 final long identity = Binder.clearCallingIdentity();
2444 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002445 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002447 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448 }
2449 } finally {
2450 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 }
2453
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002454 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002455 @Override
2456 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002457 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002458 }
2459
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002460
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002461 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002462 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2463 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2464 callingFeatureId);
2465 }
2466
2467 @Deprecated
2468 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002469 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002470 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2471 }
2472
2473 @Override
2474 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2475 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002477 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002478 return false;
2479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002480
2481 final long identity = Binder.clearCallingIdentity();
2482 try {
2483 return isRadioOnForSubscriber(subId);
2484 } finally {
2485 Binder.restoreCallingIdentity(identity);
2486 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002487 }
2488
2489 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490 final long identity = Binder.clearCallingIdentity();
2491 try {
2492 final Phone phone = getPhone(subId);
2493 if (phone != null) {
2494 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2495 } else {
2496 return false;
2497 }
2498 } finally {
2499 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 }
2502
2503 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002504 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 }
Wink Saville36469e72014-06-11 15:17:00 -07002506
Wink Savilleb564aae2014-10-23 10:18:09 -07002507 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002508 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509
2510 final long identity = Binder.clearCallingIdentity();
2511 try {
2512 final Phone phone = getPhone(subId);
2513 if (phone != null) {
2514 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 }
Wink Saville36469e72014-06-11 15:17:00 -07002519 }
2520
2521 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002522 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002523 }
2524
Wink Savilleb564aae2014-10-23 10:18:09 -07002525 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527
2528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 final Phone phone = getPhone(subId);
2531 if (phone == null) {
2532 return false;
2533 }
2534 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2535 toggleRadioOnOffForSubscriber(subId);
2536 }
2537 return true;
2538 } finally {
2539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002541 }
Wink Saville36469e72014-06-11 15:17:00 -07002542
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002543 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002544 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002545 /*
2546 * If any of the Radios are available, it will need to be
2547 * shutdown. So return true if any Radio is available.
2548 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2552 Phone phone = PhoneFactory.getPhone(i);
2553 if (phone != null && phone.isRadioAvailable()) return true;
2554 }
2555 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2556 return false;
2557 } finally {
2558 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002559 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002560 }
2561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002563 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564 enforceModifyPermission();
2565
2566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2569 logv("Shutting down Phone " + i);
2570 shutdownRadioUsingPhoneId(i);
2571 }
2572 } finally {
2573 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002574 }
2575 }
2576
2577 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002578 Phone phone = PhoneFactory.getPhone(phoneId);
2579 if (phone != null && phone.isRadioAvailable()) {
2580 phone.shutdownRadio();
2581 }
2582 }
2583
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002584 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002585 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002586
2587 final long identity = Binder.clearCallingIdentity();
2588 try {
2589 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2590 if (defaultPhone != null) {
2591 defaultPhone.setRadioPower(turnOn);
2592 return true;
2593 } else {
2594 loge("There's no default phone.");
2595 return false;
2596 }
2597 } finally {
2598 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002599 }
Wink Saville36469e72014-06-11 15:17:00 -07002600 }
2601
Wink Savilleb564aae2014-10-23 10:18:09 -07002602 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604
2605 final long identity = Binder.clearCallingIdentity();
2606 try {
2607 final Phone phone = getPhone(subId);
2608 if (phone != null) {
2609 phone.setRadioPower(turnOn);
2610 return true;
2611 } else {
2612 return false;
2613 }
2614 } finally {
2615 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002616 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 }
2618
Wink Saville36469e72014-06-11 15:17:00 -07002619 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002620 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 public boolean enableDataConnectivity() {
2622 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 int subId = mSubscriptionController.getDefaultDataSubId();
2627 final Phone phone = getPhone(subId);
2628 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002629 phone.getDataEnabledSettings().setDataEnabled(
2630 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 return true;
2632 } else {
2633 return false;
2634 }
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002638 }
2639
Wink Saville36469e72014-06-11 15:17:00 -07002640 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002641 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 public boolean disableDataConnectivity() {
2643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644
2645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 int subId = mSubscriptionController.getDefaultDataSubId();
2648 final Phone phone = getPhone(subId);
2649 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002650 phone.getDataEnabledSettings().setDataEnabled(
2651 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 return true;
2653 } else {
2654 return false;
2655 }
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002659 }
2660
Sanket Padawe356d7632015-06-22 14:03:32 -07002661 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002662 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
2666 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002667 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 } else {
2669 return false;
2670 }
2671 } finally {
2672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002674 }
2675
2676 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002677 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002678 }
2679
pkanwarae03a6b2016-11-06 20:37:09 -08002680 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681 enforceCallPermission();
2682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2686 return;
2687 }
2688 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2689 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
2692 }
pkanwar32d516d2016-10-14 19:37:38 -07002693 };
2694
Wink Savilleb564aae2014-10-23 10:18:09 -07002695 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697
2698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2701 return false;
2702 }
2703 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 }
2708
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002710 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002711 }
2712
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002713 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 Phone phone = PhoneFactory.getPhone(slotIndex);
2717 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2718 PhoneConstantConversions.convertCallState(phone.getState());
2719 } finally {
2720 Binder.restoreCallingIdentity(identity);
2721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 }
2723
Sanket Padawe356d7632015-06-22 14:03:32 -07002724 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002725 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002726 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2727 }
2728
2729 @Override
2730 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 final long identity = Binder.clearCallingIdentity();
2732 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002733 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 if (phone != null) {
2735 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2736 } else {
2737 return PhoneConstantConversions.convertDataState(
2738 PhoneConstants.DataState.DISCONNECTED);
2739 }
2740 } finally {
2741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 }
2744
Sanket Padawe356d7632015-06-22 14:03:32 -07002745 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002746 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002747 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2748 }
2749
2750 @Override
2751 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752 final long identity = Binder.clearCallingIdentity();
2753 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002754 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 if (phone != null) {
2756 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2757 } else {
2758 return TelephonyManager.DATA_ACTIVITY_NONE;
2759 }
2760 } finally {
2761 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002762 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 }
2764
2765 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002766 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002767 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002768 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002769
2770 LocationAccessPolicy.LocationPermissionResult locationResult =
2771 LocationAccessPolicy.checkLocationPermission(mApp,
2772 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2773 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002774 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002775 .setCallingPid(Binder.getCallingPid())
2776 .setCallingUid(Binder.getCallingUid())
2777 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002778 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002779 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2780 .build());
2781 switch (locationResult) {
2782 case DENIED_HARD:
2783 throw new SecurityException("Not allowed to access cell location");
2784 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002785 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2786 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002787 }
2788
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002789 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790 final long identity = Binder.clearCallingIdentity();
2791 try {
2792 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002793 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002794 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795 } finally {
2796 Binder.restoreCallingIdentity(identity);
2797 }
Svetoslav64fad262015-04-14 14:35:21 -07002798 }
2799
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002800 @Override
Jack Yu01425032020-02-22 19:38:58 -08002801 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002802 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2803 // registered cell info, so return a NULL country instead.
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002806 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2807 // Get default phone in this case.
2808 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2809 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002810 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002812 if (phone == null) return "";
2813 ServiceStateTracker sst = phone.getServiceStateTracker();
2814 if (sst == null) return "";
2815 LocaleTracker lt = sst.getLocaleTracker();
2816 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002817 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002818 } finally {
2819 Binder.restoreCallingIdentity(identity);
2820 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002821 }
2822
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002823 /**
2824 * This method was removed due to potential issues caused by performing partial
2825 * updates of service state, and lack of a credible use case.
2826 *
2827 * This has the ability to break the telephony implementation by disabling notification of
2828 * changes in device connectivity. DO NOT USE THIS!
2829 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002830 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 public void enableLocationUpdates() {
2832 mApp.enforceCallingOrSelfPermission(
2833 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834 }
2835
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002836 /**
2837 * This method was removed due to potential issues caused by performing partial
2838 * updates of service state, and lack of a credible use case.
2839 *
2840 * This has the ability to break the telephony implementation by disabling notification of
2841 * changes in device connectivity. DO NOT USE THIS!
2842 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002843 @Override
2844 public void disableLocationUpdates() {
2845 mApp.enforceCallingOrSelfPermission(
2846 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
2849 @Override
2850 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002851 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2852 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002853 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002854 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2855 throw new SecurityException(
2856 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2857 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002858
Jordan Liu1617b712019-07-10 15:06:26 -07002859 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2861 return null;
2862 }
Svetoslav64fad262015-04-14 14:35:21 -07002863
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002864 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002866 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002867 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868
Nathan Haroldf180aac2018-06-01 18:43:55 -07002869 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2870 for (CellInfo ci : info) {
2871 if (ci instanceof CellInfoGsm) {
2872 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2873 } else if (ci instanceof CellInfoWcdma) {
2874 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002877 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878 }
2879
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002880 private List<CellInfo> getCachedCellInfo() {
2881 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2882 for (Phone phone : PhoneFactory.getPhones()) {
2883 List<CellInfo> info = phone.getAllCellInfo();
2884 if (info != null) cellInfos.addAll(info);
2885 }
2886 return cellInfos;
2887 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888
2889 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002890 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002891 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002892 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002893
2894 LocationAccessPolicy.LocationPermissionResult locationResult =
2895 LocationAccessPolicy.checkLocationPermission(mApp,
2896 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2897 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002898 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002899 .setCallingPid(Binder.getCallingPid())
2900 .setCallingUid(Binder.getCallingUid())
2901 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002902 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002903 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2904 .build());
2905 switch (locationResult) {
2906 case DENIED_HARD:
2907 throw new SecurityException("Not allowed to access cell info");
2908 case DENIED_SOFT:
2909 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 }
2911
Nathan Haroldf096d982020-11-18 17:18:06 -08002912 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002913 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2914 return getCachedCellInfo();
2915 }
2916
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002917 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002918 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2922 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002923 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002924 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002925 if (info != null) cellInfos.addAll(info);
2926 }
2927 return cellInfos;
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931 }
2932
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002933 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002934 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2935 String callingFeatureId) {
2936 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2937 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002938 }
2939
2940 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002941 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2942 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002943 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002944 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002945 }
2946
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002947 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2948 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002949 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002950 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002951
2952 LocationAccessPolicy.LocationPermissionResult locationResult =
2953 LocationAccessPolicy.checkLocationPermission(mApp,
2954 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2955 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002956 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002957 .setCallingPid(Binder.getCallingPid())
2958 .setCallingUid(Binder.getCallingUid())
2959 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002960 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2961 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002962 .build());
2963 switch (locationResult) {
2964 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002965 if (TelephonyPermissions
2966 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002967 // Safetynet logging for b/154934934
2968 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2969 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002970 throw new SecurityException("Not allowed to access cell info");
2971 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002972 if (TelephonyPermissions
2973 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002974 // Safetynet logging for b/154934934
2975 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2976 }
Nathan Harold5320c422019-05-09 10:26:08 -07002977 try {
2978 cb.onCellInfo(new ArrayList<CellInfo>());
2979 } catch (RemoteException re) {
2980 // Drop without consequences
2981 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002982 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002983 }
2984
Nathan Harolda939a962019-05-09 10:13:47 -07002985
2986 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002987 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2988
2989 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2990 }
2991
2992 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002994 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002995 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002999 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003003 }
3004
Shishir Agrawala9f32182016-04-12 12:00:16 -07003005 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003006 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003007 Phone phone = PhoneFactory.getPhone(slotIndex);
3008 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003009 return null;
3010 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003011 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003012 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003013 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003014 return null;
3015 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 return phone.getImei();
3020 } finally {
3021 Binder.restoreCallingIdentity(identity);
3022 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003023 }
3024
3025 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003026 public String getTypeAllocationCodeForSlot(int slotIndex) {
3027 Phone phone = PhoneFactory.getPhone(slotIndex);
3028 String tac = null;
3029 if (phone != null) {
3030 String imei = phone.getImei();
3031 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3032 }
3033 return tac;
3034 }
3035
3036 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003037 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003038 Phone phone = PhoneFactory.getPhone(slotIndex);
3039 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003040 return null;
3041 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003042
Jeff Davidson913390f2018-02-23 17:11:49 -08003043 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003044 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003045 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003046 return null;
3047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 return phone.getMeid();
3052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
Jack Yu2af8d712017-03-15 17:14:14 -07003055 }
3056
3057 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003058 public String getManufacturerCodeForSlot(int slotIndex) {
3059 Phone phone = PhoneFactory.getPhone(slotIndex);
3060 String manufacturerCode = null;
3061 if (phone != null) {
3062 String meid = phone.getMeid();
3063 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3064 }
3065 return manufacturerCode;
3066 }
3067
3068 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003069 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3070 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003071 Phone phone = PhoneFactory.getPhone(slotIndex);
3072 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003073 return null;
3074 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003075 int subId = phone.getSubId();
3076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003077 mApp, subId, callingPackage, callingFeatureId,
3078 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003079 return null;
3080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003081
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 return phone.getDeviceSvn();
3085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003088 }
3089
fionaxu43304da2017-11-27 22:51:16 -08003090 @Override
3091 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092 final long identity = Binder.clearCallingIdentity();
3093 try {
3094 final Phone phone = getPhone(subId);
3095 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
fionaxu43304da2017-11-27 22:51:16 -08003099 }
3100
3101 @Override
3102 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103 final long identity = Binder.clearCallingIdentity();
3104 try {
3105 final Phone phone = getPhone(subId);
3106 return phone == null ? null : phone.getCarrierName();
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
fionaxu43304da2017-11-27 22:51:16 -08003110 }
3111
calvinpanffe225e2018-11-01 19:43:06 +08003112 @Override
chen xu0026ca62019-03-06 15:28:50 -08003113 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 final Phone phone = getPhone(subId);
3117 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003118 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
3124 @Override
chen xu0026ca62019-03-06 15:28:50 -08003125 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003126 final long identity = Binder.clearCallingIdentity();
3127 try {
3128 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003129 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003130 } finally {
3131 Binder.restoreCallingIdentity(identity);
3132 }
3133 }
3134
chen xu651eec72018-11-11 19:03:44 -08003135 @Override
chen xu864e11c2018-12-06 22:10:03 -08003136 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3137 if (!isSubscriptionMccMnc) {
3138 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3139 }
chen xu651eec72018-11-11 19:03:44 -08003140 final Phone phone = PhoneFactory.getPhone(slotIndex);
3141 if (phone == null) {
3142 return TelephonyManager.UNKNOWN_CARRIER_ID;
3143 }
3144 final long identity = Binder.clearCallingIdentity();
3145 try {
3146 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3147 } finally {
3148 Binder.restoreCallingIdentity(identity);
3149 }
3150 }
3151
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003152 //
3153 // Internal helper methods.
3154 //
3155
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003156 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3158 *
3159 * @throws SecurityException if the caller does not have the required permission
3160 */
3161 private void enforceModifyPermission() {
3162 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3163 }
3164
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003165 /**
3166 * Make sure the caller is system.
3167 *
3168 * @throws SecurityException if the caller is not system.
3169 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003170 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003171 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3172 throw new SecurityException("Caller must be system");
3173 }
3174 }
3175
Shuo Qianf2b2df42019-11-13 17:43:31 -08003176 private void enforceActiveEmergencySessionPermission() {
3177 mApp.enforceCallingOrSelfPermission(
3178 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3179 }
3180
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 /**
3182 * Make sure the caller has the CALL_PHONE permission.
3183 *
3184 * @throws SecurityException if the caller does not have the required permission
3185 */
3186 private void enforceCallPermission() {
3187 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3188 }
3189
paulhu423b5f22019-08-23 19:17:33 +08003190 private void enforceSettingsPermission() {
3191 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003192 }
3193
Michele Berionned9fbae52020-11-13 02:36:59 +00003194 private void enforceRebootPermission() {
3195 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3196 }
3197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 private String createTelUrl(String number) {
3199 if (TextUtils.isEmpty(number)) {
3200 return null;
3201 }
3202
Jake Hambye994d462014-02-03 13:10:13 -08003203 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 }
3205
Ihab Awadf9e92732013-12-05 18:02:52 -08003206 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3208 }
3209
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003210 private static void logv(String msg) {
3211 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3212 }
3213
Ihab Awadf9e92732013-12-05 18:02:52 -08003214 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003215 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3216 }
3217
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003218 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003219 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003220 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003221 }
3222
Sanket Padawe356d7632015-06-22 14:03:32 -07003223 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003224 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 final Phone phone = PhoneFactory.getPhone(slotIndex);
3228 if (phone == null) {
3229 return PhoneConstants.PHONE_TYPE_NONE;
3230 } else {
3231 return phone.getPhoneType();
3232 }
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 }
3237
3238 /**
3239 * Returns the CDMA ERI icon index to display
3240 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003241 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003242 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3243 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3244 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003245 }
3246
Sanket Padawe356d7632015-06-22 14:03:32 -07003247 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003248 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3249 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003251 mApp, subId, callingPackage, callingFeatureId,
3252 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003253 return -1;
3254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003255
3256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 final Phone phone = getPhone(subId);
3259 if (phone != null) {
3260 return phone.getCdmaEriIconIndex();
3261 } else {
3262 return -1;
3263 }
3264 } finally {
3265 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003267 }
3268
3269 /**
3270 * Returns the CDMA ERI icon mode,
3271 * 0 - ON
3272 * 1 - FLASHING
3273 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003274 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003275 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3276 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3277 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003278 }
3279
Sanket Padawe356d7632015-06-22 14:03:32 -07003280 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003281 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3282 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003284 mApp, subId, callingPackage, callingFeatureId,
3285 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003286 return -1;
3287 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003288
3289 final long identity = Binder.clearCallingIdentity();
3290 try {
3291 final Phone phone = getPhone(subId);
3292 if (phone != null) {
3293 return phone.getCdmaEriIconMode();
3294 } else {
3295 return -1;
3296 }
3297 } finally {
3298 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003300 }
3301
3302 /**
3303 * Returns the CDMA ERI text,
3304 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003305 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003306 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3307 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3308 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003309 }
3310
Sanket Padawe356d7632015-06-22 14:03:32 -07003311 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003312 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3313 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003315 mApp, subId, callingPackage, callingFeatureId,
3316 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003317 return null;
3318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319
3320 final long identity = Binder.clearCallingIdentity();
3321 try {
3322 final Phone phone = getPhone(subId);
3323 if (phone != null) {
3324 return phone.getCdmaEriText();
3325 } else {
3326 return null;
3327 }
3328 } finally {
3329 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003331 }
3332
3333 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003334 * Returns the CDMA MDN.
3335 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003336 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003337 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3339 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340
3341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003344 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345 return phone.getLine1Number();
3346 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003347 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348 return null;
3349 }
3350 } finally {
3351 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003352 }
3353 }
3354
3355 /**
3356 * Returns the CDMA MIN.
3357 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003358 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003359 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3361 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362
3363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 final Phone phone = getPhone(subId);
3366 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3367 return phone.getCdmaMin();
3368 } else {
3369 return null;
3370 }
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003373 }
3374 }
3375
Hall Liud892bec2018-11-30 14:51:45 -08003376 @Override
3377 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3378 INumberVerificationCallback callback, String callingPackage) {
3379 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3380 != PERMISSION_GRANTED) {
3381 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3382 }
3383 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3384
3385 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3386 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003387 throw new SecurityException("Calling package must be configured in the device config: "
3388 + "calling package: " + callingPackage
3389 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003390 }
3391
3392 if (range == null) {
3393 throw new NullPointerException("Range must be non-null");
3394 }
3395
3396 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003397 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003398
3399 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3400 }
3401
Junda Liuca05d5d2014-08-14 22:36:34 -07003402 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003403 * Returns true if CDMA provisioning needs to run.
3404 */
3405 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003406 final long identity = Binder.clearCallingIdentity();
3407 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003408 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003409 } finally {
3410 Binder.restoreCallingIdentity(identity);
3411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003412 }
3413
3414 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003415 * Sets the voice mail number of a given subId.
3416 */
3417 @Override
3418 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003419 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3420 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3425 new Pair<String, String>(alphaTag, number), new Integer(subId));
3426 return success;
3427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003430 }
3431
Ta-wei Yen87c49842016-05-13 21:19:52 -07003432 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003433 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3434 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003435 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3436 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003437 if (!TextUtils.equals(callingPackage, systemDialer)) {
3438 throw new SecurityException("caller must be system dialer");
3439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003440
3441 final long identity = Binder.clearCallingIdentity();
3442 try {
3443 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3444 if (phoneAccountHandle == null) {
3445 return null;
3446 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003447 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448 } finally {
3449 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003450 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003451 }
3452
3453 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003454 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3455 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003457 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003458 mApp, subId, callingPackage, callingFeatureId,
3459 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003460 return null;
3461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003463 final long identity = Binder.clearCallingIdentity();
3464 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003465 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003469 }
3470
3471 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003472 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3473 VisualVoicemailSmsFilterSettings settings) {
3474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003475
3476 final long identity = Binder.clearCallingIdentity();
3477 try {
3478 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003479 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480 } finally {
3481 Binder.restoreCallingIdentity(identity);
3482 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003483 }
3484
3485 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003486 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003492 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003496 }
3497
3498 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003499 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3500 String callingPackage, int subId) {
3501 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003502
3503 final long identity = Binder.clearCallingIdentity();
3504 try {
3505 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003506 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507 } finally {
3508 Binder.restoreCallingIdentity(identity);
3509 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003510 }
3511
3512 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003513 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003519 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520 } finally {
3521 Binder.restoreCallingIdentity(identity);
3522 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003523 }
3524
3525 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003526 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3527 String callingAttributionTag, int subId, String number, int port, String text,
3528 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003530 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003531 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003532 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003533 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3534 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003535 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003536
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003537 /**
fionaxu0152e512016-11-14 13:36:14 -08003538 * Sets the voice activation state of a given subId.
3539 */
3540 @Override
3541 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3543 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 final Phone phone = getPhone(subId);
3548 if (phone != null) {
3549 phone.setVoiceActivationState(activationState);
3550 } else {
3551 loge("setVoiceActivationState fails with invalid subId: " + subId);
3552 }
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003555 }
3556 }
3557
3558 /**
3559 * Sets the data activation state of a given subId.
3560 */
3561 @Override
3562 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3564 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 final Phone phone = getPhone(subId);
3569 if (phone != null) {
3570 phone.setDataActivationState(activationState);
3571 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003572 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 }
3574 } finally {
3575 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003576 }
3577 }
3578
3579 /**
3580 * Returns the voice activation state of a given subId.
3581 */
3582 @Override
3583 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003585
fionaxu0152e512016-11-14 13:36:14 -08003586 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 if (phone != null) {
3590 return phone.getVoiceActivationState();
3591 } else {
3592 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3593 }
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003596 }
3597 }
3598
3599 /**
3600 * Returns the data activation state of a given subId.
3601 */
3602 @Override
3603 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605
fionaxu0152e512016-11-14 13:36:14 -08003606 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 if (phone != null) {
3610 return phone.getDataActivationState();
3611 } else {
3612 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3613 }
3614 } finally {
3615 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003616 }
3617 }
3618
3619 /**
Wink Saville36469e72014-06-11 15:17:00 -07003620 * Returns the unread count of voicemails for a subId
3621 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003622 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003623 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3624 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003626 mApp, subId, callingPackage, callingFeatureId,
3627 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003628 return 0;
3629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630 final long identity = Binder.clearCallingIdentity();
3631 try {
3632 final Phone phone = getPhone(subId);
3633 if (phone != null) {
3634 return phone.getVoiceMessageCount();
3635 } else {
3636 return 0;
3637 }
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003641 }
3642
3643 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003644 * returns true, if the device is in a state where both voice and data
3645 * are supported simultaneously. This can change based on location or network condition.
3646 */
3647 @Override
3648 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 final Phone phone = getPhone(subId);
3652 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
3655 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003656 }
3657
3658 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003659 * Send the dialer code if called from the current default dialer or the caller has
3660 * carrier privilege.
3661 * @param inputCode The dialer code to send
3662 */
3663 @Override
3664 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003665 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003667 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3668 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003669 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003670 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003671 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003676 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003677 } finally {
3678 Binder.restoreCallingIdentity(identity);
3679 }
fionaxu235cc5e2017-03-06 22:25:57 -08003680 }
3681
Pengquan Menga1bb6272018-09-06 09:59:22 -07003682 @Override
3683 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003684 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07003685 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003686 mApp, subId, "getNetworkSelectionMode");
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 if (!isActiveSubscription(subId)) {
3690 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3691 }
3692 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3693 } finally {
3694 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003695 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003696 }
3697
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003699 public boolean isInEmergencySmsMode() {
3700 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 for (Phone phone : PhoneFactory.getPhones()) {
3704 if (phone.isInEmergencySmsMode()) {
3705 return true;
3706 }
3707 }
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
3711 return false;
3712 }
3713
shilu366312e2019-12-17 09:28:10 -08003714 /**
3715 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3716 * @param subId The subscription to use to check the configuration.
3717 * @param c The callback that will be used to send the result.
3718 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003719 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003720 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3721 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003722 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003723 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003724
Brad Ebinger77b832e2019-10-17 17:03:22 -07003725 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3726 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3727 "IMS not available on device.");
3728 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 final long token = Binder.clearCallingIdentity();
3730 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003731 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003732 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003734 } catch (ImsException e) {
3735 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 } finally {
3737 Binder.restoreCallingIdentity(token);
3738 }
3739 }
3740
shilu366312e2019-12-17 09:28:10 -08003741 /**
3742 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3743 * @param subId The subscription to use to check the configuration.
3744 * @param c The callback that will be used to send the result.
3745 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003747 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003748 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003749 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003750 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3751 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3752 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003753 final long token = Binder.clearCallingIdentity();
3754 try {
3755 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3756 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3757 .removeRegistrationCallbackForSubscription(c, subId);
3758 } catch (ImsException e) {
3759 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3760 + "is inactive, ignoring unregister.");
3761 // If the subscription is no longer active, just return, since the callback
3762 // will already have been removed internally.
3763 } finally {
3764 Binder.restoreCallingIdentity(token);
3765 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003766 }
3767
Brad Ebinger774ba362019-10-22 17:36:18 -07003768 /**
3769 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3770 */
3771 @Override
3772 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3773 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3774 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3775 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3776 "IMS not available on device.");
3777 }
3778 final long token = Binder.clearCallingIdentity();
3779 try {
3780 Phone phone = getPhone(subId);
3781 if (phone == null) {
3782 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3783 + subId + "'");
3784 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3785 }
3786 phone.getImsRegistrationState(regState -> {
3787 try {
3788 consumer.accept((regState == null)
3789 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3790 } catch (RemoteException e) {
3791 // Ignore if the remote process is no longer available to call back.
3792 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3793 }
3794 });
3795 } finally {
3796 Binder.restoreCallingIdentity(token);
3797 }
3798 }
3799
3800 /**
3801 * Get the transport type for the IMS service registration state.
3802 */
3803 @Override
3804 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003805 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003806 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003807 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3808 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3809 "IMS not available on device.");
3810 }
3811 final long token = Binder.clearCallingIdentity();
3812 try {
3813 Phone phone = getPhone(subId);
3814 if (phone == null) {
3815 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3816 + subId + "'");
3817 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3818 }
3819 phone.getImsRegistrationTech(regTech -> {
3820 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3821 int regTechConverted = (regTech == null)
3822 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3823 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3824 regTechConverted);
3825 try {
3826 consumer.accept(regTechConverted);
3827 } catch (RemoteException e) {
3828 // Ignore if the remote process is no longer available to call back.
3829 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3830 }
3831 });
3832 } finally {
3833 Binder.restoreCallingIdentity(token);
3834 }
3835 }
3836
shilu366312e2019-12-17 09:28:10 -08003837 /**
3838 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3839 * @param subId The subscription to use to check the configuration.
3840 * @param c The callback that will be used to send the result.
3841 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003842 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003843 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3844 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003845 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003846 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003847 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3848 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3849 "IMS not available on device.");
3850 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3852 final long token = Binder.clearCallingIdentity();
3853 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003854 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003855 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003856 } catch (ImsException e) {
3857 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003858 } finally {
3859 Binder.restoreCallingIdentity(token);
3860 }
3861 }
3862
shilu366312e2019-12-17 09:28:10 -08003863 /**
3864 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3865 * @param subId The subscription to use to check the configuration.
3866 * @param c The callback that will be used to send the result.
3867 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003868 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003869 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003870 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003871 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003872 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3873 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3874 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003875
3876 final long token = Binder.clearCallingIdentity();
3877 try {
3878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3879 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003880 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003881 } catch (ImsException e) {
3882 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3883 + "is inactive, ignoring unregister.");
3884 // If the subscription is no longer active, just return, since the callback
3885 // will already have been removed internally.
3886 } finally {
3887 Binder.restoreCallingIdentity(token);
3888 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 }
3890
3891 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003892 public boolean isCapable(int subId, int capability, int regTech) {
3893 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3895 final long token = Binder.clearCallingIdentity();
3896 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003897 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003899 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003900 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3901 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003902 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003903 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3904 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 } finally {
3906 Binder.restoreCallingIdentity(token);
3907 }
3908 }
3909
3910 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003911 public boolean isAvailable(int subId, int capability, int regTech) {
3912 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 final long token = Binder.clearCallingIdentity();
3914 try {
3915 Phone phone = getPhone(subId);
3916 if (phone == null) return false;
3917 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003918 } catch (com.android.ims.ImsException e) {
3919 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3920 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 } finally {
3922 Binder.restoreCallingIdentity(token);
3923 }
3924 }
3925
Brad Ebinger77b832e2019-10-17 17:03:22 -07003926 /**
3927 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3928 * subscription.
3929 * @param subId The subscription to use to check the configuration.
3930 * @param callback The callback that will be used to send the result.
3931 * @param capability The MmTelFeature capability that will be used to send the result.
3932 * @param transportType The transport type of the MmTelFeature capability.
3933 */
3934 @Override
3935 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3936 int transportType) {
3937 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3938 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3939 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3940 "IMS not available on device.");
3941 }
3942 final long token = Binder.clearCallingIdentity();
3943 try {
3944 int slotId = getSlotIndex(subId);
3945 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3946 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3947 + subId + "'");
3948 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3949 }
3950 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3951 transportType, aBoolean -> {
3952 try {
3953 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3954 } catch (RemoteException e) {
3955 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3956 + "running. Ignore");
3957 }
3958 });
3959 } finally {
3960 Binder.restoreCallingIdentity(token);
3961 }
3962 }
3963
shilu366312e2019-12-17 09:28:10 -08003964 /**
3965 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3966 * @param subId The subscription to use to check the configuration.
3967 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 @Override
3969 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003970 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003971 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003972
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3974 final long token = Binder.clearCallingIdentity();
3975 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003976 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003978 } catch (ImsException e) {
3979 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 } finally {
3981 Binder.restoreCallingIdentity(token);
3982 }
3983 }
3984
3985 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003986 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003988 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 final long identity = Binder.clearCallingIdentity();
3990 try {
3991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003992 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003994 } catch (ImsException e) {
3995 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003996 } finally {
3997 Binder.restoreCallingIdentity(identity);
3998 }
3999 }
4000
shilu366312e2019-12-17 09:28:10 -08004001 /**
4002 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4003 * @param subId The subscription to use to check the configuration.
4004 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004006 public boolean isVtSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004007 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004008 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004012 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4013 } catch (ImsException e) {
4014 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 } finally {
4016 Binder.restoreCallingIdentity(identity);
4017 }
4018 }
4019
4020 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004021 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004023 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 final long identity = Binder.clearCallingIdentity();
4025 try {
4026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004027 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004028 } catch (ImsException e) {
4029 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 } finally {
4031 Binder.restoreCallingIdentity(identity);
4032 }
4033 }
4034
shilu366312e2019-12-17 09:28:10 -08004035 /**
4036 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4037 * @param subId The subscription to use to check the configuration.
4038 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 @Override
4040 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004041 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004042 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004046 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004047 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004048 } catch (ImsException e) {
4049 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 } finally {
4051 Binder.restoreCallingIdentity(identity);
4052 }
4053 }
4054
4055 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004056 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004058 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 final long identity = Binder.clearCallingIdentity();
4060 try {
4061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004062 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004063 } catch (ImsException e) {
4064 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004065 } finally {
4066 Binder.restoreCallingIdentity(identity);
4067 }
4068 }
4069
shilu366312e2019-12-17 09:28:10 -08004070 /**
4071 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4072 * @param subId The subscription to use to check the configuration.
4073 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 @Override
4075 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004076 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004077 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004081 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004083 } catch (ImsException e) {
4084 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 } finally {
4086 Binder.restoreCallingIdentity(identity);
4087 }
4088 }
4089
4090 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004091 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004093 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004097 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (ImsException e) {
4100 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
4104 }
4105
4106 @Override
4107 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4109 "setVoWiFiNonPersistent");
4110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004113 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004114 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004115 } catch (ImsException e) {
4116 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
4120 }
4121
shilu366312e2019-12-17 09:28:10 -08004122 /**
4123 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4124 * @param subId The subscription to use to check the configuration.
4125 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 @Override
4127 public int getVoWiFiModeSetting(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004128 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004129 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004135 } catch (ImsException e) {
4136 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
4140 }
4141
4142 @Override
4143 public void setVoWiFiModeSetting(int subId, int mode) {
4144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4145 "setVoWiFiModeSetting");
4146 final long identity = Binder.clearCallingIdentity();
4147 try {
4148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004149 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004151 } catch (ImsException e) {
4152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 } finally {
4154 Binder.restoreCallingIdentity(identity);
4155 }
4156 }
4157
4158 @Override
4159 public int getVoWiFiRoamingModeSetting(int subId) {
4160 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004164 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004166 } catch (ImsException e) {
4167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
4171 }
4172
4173 @Override
4174 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4176 "setVoWiFiRoamingModeSetting");
4177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004180 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004182 } catch (ImsException e) {
4183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
4187 }
4188
4189 @Override
4190 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4192 "setRttCapabilityEnabled");
4193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004196 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4197 } catch (ImsException e) {
4198 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 } finally {
4200 Binder.restoreCallingIdentity(identity);
4201 }
4202 }
4203
shilu366312e2019-12-17 09:28:10 -08004204 /**
4205 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4206 * @param subId The subscription to use to check the configuration.
4207 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004208 @Override
4209 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004210 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004211 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 final long identity = Binder.clearCallingIdentity();
4213 try {
4214 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004215 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004217 } catch (ImsException e) {
4218 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
4222 }
4223
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004224 @Override
4225 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4226 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4227 final long identity = Binder.clearCallingIdentity();
4228 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004229 if (!isImsAvailableOnDevice()) {
4230 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4231 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004232 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004233 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004234 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004235 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004236 } catch (ImsException e) {
4237 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004238 } finally {
4239 Binder.restoreCallingIdentity(identity);
4240 }
4241 }
4242
4243 @Override
4244 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4245 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4246 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004247 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4248 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4249 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004250 try {
4251 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004252 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004253 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004254 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004255 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4256 + "is inactive, ignoring unregister.");
4257 // If the subscription is no longer active, just return, since the callback will already
4258 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
4262 }
4263
allenwtsu99c623b2020-01-03 18:24:23 +08004264
4265 private void checkModifyPhoneStatePermission(int subId, String message) {
4266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4267 message);
4268 }
4269
4270 private boolean isImsProvisioningRequired(int subId, int capability,
4271 boolean isMmtelCapability) {
4272 Phone phone = getPhone(subId);
4273 if (phone == null) {
4274 loge("phone instance null for subid " + subId);
4275 return false;
4276 }
4277 if (isMmtelCapability) {
4278 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4279 return false;
4280 }
4281 } else {
4282 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4283 return false;
4284 }
4285 }
4286 return true;
4287 }
4288
4289 @Override
4290 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4291 boolean isProvisioned) {
4292 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4293
4294 final long identity = Binder.clearCallingIdentity();
4295 try {
4296 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4297 if (!isImsProvisioningRequired(subId, capability, false)) {
4298 return;
4299 }
4300
4301 // this capability requires provisioning, route to the correct API.
4302 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4303 switch (capability) {
4304 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4305 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4306 ims.setEabProvisioned(isProvisioned);
4307 break;
4308 default: {
4309 throw new IllegalArgumentException("Tried to set provisioning for "
4310 + "rcs capability '" + capability + "', which does not require "
4311 + "provisioning.");
4312 }
4313 }
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
4316 }
4317
4318 }
4319
4320
4321 @Override
4322 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4323 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4324 final long identity = Binder.clearCallingIdentity();
4325 try {
4326 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4327 if (!isImsProvisioningRequired(subId, capability, false)) {
4328 return true;
4329 }
4330
4331 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4332 switch (capability) {
4333 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4334 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4335 return ims.isEabProvisionedOnDevice();
4336
4337 default: {
4338 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4339 + "capability '" + capability + "', which does not require "
4340 + "provisioning.");
4341 }
4342 }
4343
4344 } finally {
4345 Binder.restoreCallingIdentity(identity);
4346 }
4347 }
4348
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004349 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004350 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4351 boolean isProvisioned) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004352 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4353 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004354 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4355 }
allenwtsu99c623b2020-01-03 18:24:23 +08004356 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004360 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004361 return;
4362 }
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004363 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4364 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4365 loge("setImsProvisioningStatusForCapability: called for technology that does "
4366 + "not support provisioning - " + tech);
4367 return;
4368 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004369
4370 // this capability requires provisioning, route to the correct API.
4371 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4372 switch (capability) {
4373 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4374 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4375 ims.setVolteProvisioned(isProvisioned);
4376 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4377 ims.setWfcProvisioned(isProvisioned);
4378 }
4379 break;
4380 }
4381 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4382 // There is currently no difference in VT provisioning type.
4383 ims.setVtProvisioned(isProvisioned);
4384 break;
4385 }
4386 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4387 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4388 // change the capability of the feature instead if needed.
4389 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4390 == isProvisioned) {
4391 // No change in provisioning.
4392 return;
4393 }
4394 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4395 try {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004396 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004397 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004398 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4399 + ", Exception" + e.getMessage());
4400 }
4401 break;
4402 }
4403 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004404 throw new IllegalArgumentException("Tried to set provisioning for "
4405 + "MmTel capability '" + capability + "', which does not require "
4406 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004407 }
4408 }
4409
4410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
4413 }
4414
4415 @Override
4416 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004417 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4418 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004419 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4420 }
4421 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004425 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004426 return true;
4427 }
4428
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004429 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4430 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4431 loge("getImsProvisioningStatusForCapability: called for technology that does "
4432 + "not support provisioning - " + tech);
4433 return true;
4434 }
4435
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004436 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4437 switch (capability) {
4438 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4439 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4440 return ims.isVolteProvisionedOnDevice();
4441 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4442 return ims.isWfcProvisionedOnDevice();
4443 }
4444 // This should never happen, since we are checking tech above to make sure it
4445 // is either LTE or IWLAN.
4446 throw new IllegalArgumentException("Invalid radio technology for voice "
4447 + "capability.");
4448 }
4449 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4450 // There is currently no difference in VT provisioning type.
4451 return ims.isVtProvisionedOnDevice();
4452 }
4453 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4454 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4455 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4456 }
4457 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004458 throw new IllegalArgumentException(
4459 "Tried to get provisioning for MmTel capability '" + capability
4460 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004461 }
4462 }
4463
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
4467 }
4468
4469 @Override
4470 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4471 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4472 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4473 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4474 }
4475 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4476 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4477 return (provisionedBits & capability) > 0;
4478 }
4479
4480 @Override
4481 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4482 boolean isProvisioned) {
4483 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4484 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4485 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4486 }
4487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4488 "setProvisioningStatusForCapability");
4489 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4490 // If the current provisioning status for capability already matches isProvisioned,
4491 // do nothing.
4492 if (((provisionedBits & capability) > 0) == isProvisioned) {
4493 return;
4494 }
4495 if (isProvisioned) {
4496 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4497 } else {
4498 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4499 }
4500 }
4501
4502 /**
4503 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4504 * technology. The bitfield should mirror the bitfield defined by
4505 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4506 */
4507 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4508 String key = getMmTelProvisioningKey(subId, tech);
4509 // Default is no capabilities are provisioned.
4510 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4511 }
4512
4513 /**
4514 * Sets the MmTel capability provisioning bitfield (defined by
4515 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4516 * technology specified.
4517 *
4518 * Note: This is a synchronous command and should not be called on UI thread.
4519 */
4520 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4521 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4522 String key = getMmTelProvisioningKey(subId, tech);
4523 editor.putInt(key, newField);
4524 editor.commit();
4525 }
4526
4527 private static String getMmTelProvisioningKey(int subId, int tech) {
4528 // resulting key is provision_ims_mmtel_{subId}_{tech}
4529 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4530 }
4531
4532 /**
4533 * Query CarrierConfig to see if the specified capability requires provisioning for the
4534 * carrier associated with the subscription id.
4535 */
4536 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4537 int capability) {
4538 CarrierConfigManager configManager = new CarrierConfigManager(context);
4539 PersistableBundle c = configManager.getConfigForSubId(subId);
4540 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004541 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004542 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4543 false);
4544 boolean requireVoiceVtProvisioning = c.getBoolean(
4545 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4546
4547 // First check to make sure that the capability requires provisioning.
4548 switch (capability) {
4549 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4550 // intentional fallthrough
4551 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4552 if (requireVoiceVtProvisioning) {
4553 // Voice and Video requires provisioning
4554 return true;
4555 }
4556 break;
4557 }
4558 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4559 if (requireUtProvisioning) {
4560 // UT requires provisioning
4561 return true;
4562 }
4563 break;
4564 }
4565 }
4566 return false;
4567 }
4568
allenwtsu99c623b2020-01-03 18:24:23 +08004569 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4570 int capability) {
4571 CarrierConfigManager configManager = new CarrierConfigManager(context);
4572 PersistableBundle c = configManager.getConfigForSubId(subId);
4573
4574 boolean requireRcsProvisioning = c.getBoolean(
4575 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4576
4577 // First check to make sure that the capability requires provisioning.
4578 switch (capability) {
4579 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4580 // intentional fallthrough
4581 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4582 if (requireRcsProvisioning) {
4583 // OPTION or PRESENCE requires provisioning
4584 return true;
4585 }
4586 break;
4587 }
4588 }
4589 return false;
4590 }
4591
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004592 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004594 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4595 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4596 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004597 enforceReadPrivilegedPermission("getImsProvisioningInt");
4598 final long identity = Binder.clearCallingIdentity();
4599 try {
4600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004601 int slotId = getSlotIndex(subId);
4602 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4603 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4604 + subId + "' for key:" + key);
4605 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4606 }
calvinpan9cfff472021-02-08 19:59:36 +08004607 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004608 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004609 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4610 + subId + "' for key:" + key);
4611 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004612 } finally {
4613 Binder.restoreCallingIdentity(identity);
4614 }
4615 }
4616
4617 @Override
4618 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004619 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4620 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4621 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004622 enforceReadPrivilegedPermission("getImsProvisioningString");
4623 final long identity = Binder.clearCallingIdentity();
4624 try {
4625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004626 int slotId = getSlotIndex(subId);
4627 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4628 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4629 + subId + "' for key:" + key);
4630 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4631 }
calvinpan9cfff472021-02-08 19:59:36 +08004632 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004633 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004634 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4635 + subId + "' for key:" + key);
4636 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004637 } finally {
4638 Binder.restoreCallingIdentity(identity);
4639 }
4640 }
4641
4642 @Override
4643 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004644 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4645 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4646 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4648 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004649 final long identity = Binder.clearCallingIdentity();
4650 try {
4651 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004652 int slotId = getSlotIndex(subId);
4653 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4654 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4655 + subId + "' for key:" + key);
4656 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4657 }
calvinpan9cfff472021-02-08 19:59:36 +08004658 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4659 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004660 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004661 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004662 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
4666 }
4667
4668 @Override
4669 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004670 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4671 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4672 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4674 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004675 final long identity = Binder.clearCallingIdentity();
4676 try {
4677 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004678 int slotId = getSlotIndex(subId);
4679 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4680 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4681 + subId + "' for key:" + key);
4682 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4683 }
calvinpan9cfff472021-02-08 19:59:36 +08004684 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4685 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004686 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004687 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004688 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004689 } finally {
4690 Binder.restoreCallingIdentity(identity);
4691 }
4692 }
4693
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004694 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004695 int slotId = SubscriptionManager.getSlotIndex(subId);
4696 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004697 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4698 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004699 }
4700 return slotId;
4701 }
4702
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004703 private int getSlotIndex(int subId) {
4704 int slotId = SubscriptionManager.getSlotIndex(subId);
4705 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4706 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4707 }
4708 return slotId;
4709 }
4710
Wink Saville36469e72014-06-11 15:17:00 -07004711 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004712 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004713 */
4714 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004715 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4716 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004717 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004718 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004719 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004720 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004721 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004722 mApp, subId, callingPackage, callingFeatureId,
4723 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004724 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4725 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 final Phone phone = getPhone(subId);
4730 if (phone != null) {
4731 return phone.getServiceState().getDataNetworkType();
4732 } else {
4733 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4734 }
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004738 }
4739
4740 /**
4741 * Returns the data network type
4742 */
4743 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004744 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004745 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4746 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004747 }
4748
4749 /**
4750 * Returns the data network type for a subId
4751 */
4752 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004753 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4754 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004756 mApp, subId, callingPackage, callingFeatureId,
4757 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004758 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4759 }
4760
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004761 final long identity = Binder.clearCallingIdentity();
4762 try {
4763 final Phone phone = getPhone(subId);
4764 if (phone != null) {
4765 return phone.getServiceState().getDataNetworkType();
4766 } else {
4767 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4768 }
4769 } finally {
4770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004772 }
4773
4774 /**
Wink Saville36469e72014-06-11 15:17:00 -07004775 * Returns the Voice network type for a subId
4776 */
4777 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004778 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4779 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004781 mApp, subId, callingPackage, callingFeatureId,
4782 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004783 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4784 }
4785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786 final long identity = Binder.clearCallingIdentity();
4787 try {
4788 final Phone phone = getPhone(subId);
4789 if (phone != null) {
4790 return phone.getServiceState().getVoiceNetworkType();
4791 } else {
4792 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4793 }
4794 } finally {
4795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004797 }
4798
4799 /**
4800 * @return true if a ICC card is present
4801 */
4802 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004803 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004804 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4805 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004806 }
4807
4808 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004809 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004810 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004811 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004812 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813 final long identity = Binder.clearCallingIdentity();
4814 try {
4815 final Phone phone = PhoneFactory.getPhone(slotIndex);
4816 if (phone != null) {
4817 return phone.getIccCard().hasIccCard();
4818 } else {
4819 return false;
4820 }
4821 } finally {
4822 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004824 }
4825
4826 /**
4827 * Return if the current radio is LTE on CDMA. This
4828 * is a tri-state return value as for a period of time
4829 * the mode may be unknown.
4830 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004831 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004832 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004833 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004834 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004835 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004836 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4837 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4838 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004839 }
4840
Sanket Padawe356d7632015-06-22 14:03:32 -07004841 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004842 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4843 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004844 try {
4845 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4846 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004847 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4848 }
4849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 final Phone phone = getPhone(subId);
4853 if (phone == null) {
4854 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4855 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004856 return TelephonyProperties.lte_on_cdma_device()
4857 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858 }
4859 } finally {
4860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004861 }
Wink Saville36469e72014-06-11 15:17:00 -07004862 }
4863
Wink Saville36469e72014-06-11 15:17:00 -07004864 /**
4865 * {@hide}
4866 * Returns Default subId, 0 in the case of single standby.
4867 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004868 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004869 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004870 }
4871
Shishir Agrawala9f32182016-04-12 12:00:16 -07004872 private int getSlotForDefaultSubscription() {
4873 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4874 }
4875
Wink Savilleb564aae2014-10-23 10:18:09 -07004876 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004877 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004878 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004879
Pengquan Menge92a50d2018-09-21 15:54:48 -07004880 private boolean isActiveSubscription(int subId) {
4881 return mSubscriptionController.isActiveSubId(subId);
4882 }
4883
Ihab Awadf2177b72013-11-25 13:33:23 -08004884 /**
4885 * @see android.telephony.TelephonyManager.WifiCallingChoices
4886 */
4887 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 final long identity = Binder.clearCallingIdentity();
4889 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004890 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004891 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4892 getWhenToMakeWifiCallsDefaultPreference());
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
4895 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004896 }
4897
4898 /**
4899 * @see android.telephony.TelephonyManager.WifiCallingChoices
4900 */
4901 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 final long identity = Binder.clearCallingIdentity();
4903 try {
4904 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004905 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4907 } finally {
4908 Binder.restoreCallingIdentity(identity);
4909 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004910 }
4911
Sailesh Nepald1e68152013-12-12 19:08:02 -08004912 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004913 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004914 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004915 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004916
Jordan Liu4c733742019-02-28 12:03:40 -08004917 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4918 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4919 if (phoneId == -1) {
4920 throw new IllegalArgumentException("Given slot index: " + slotIndex
4921 + " does not correspond to an active phone");
4922 }
4923 return PhoneFactory.getPhone(phoneId);
4924 }
4925
Shishir Agrawal566b7612013-10-28 14:41:00 -07004926 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004927 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4928 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4930 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004932 if (DBG) {
4933 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4934 }
4935 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4936 p2);
4937 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004938
Jordan Liu4c733742019-02-28 12:03:40 -08004939
4940 @Override
4941 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4942 int slotIndex, String callingPackage, String aid, int p2) {
4943 enforceModifyPermission();
4944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4945 if (DBG) {
4946 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4947 }
4948 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4949 callingPackage, aid, p2);
4950 }
4951
4952 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4953 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 final long identity = Binder.clearCallingIdentity();
4955 try {
4956 if (TextUtils.equals(ISDR_AID, aid)) {
4957 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004958 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4959 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 if (bestComponent == null
4961 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4962 loge("The calling package is not allowed to access ISD-R.");
4963 throw new SecurityException(
4964 "The calling package is not allowed to access ISD-R.");
4965 }
Derek Tan740e1672017-06-27 14:56:27 -07004966 }
Derek Tan740e1672017-06-27 14:56:27 -07004967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004969 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4970 null /* workSource */);
4971 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 return response;
4973 } finally {
4974 Binder.restoreCallingIdentity(identity);
4975 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004976 }
4977
4978 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004979 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4981 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004982 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4983 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4984 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004985
Jordan Liu4c733742019-02-28 12:03:40 -08004986 @Override
4987 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4988 enforceModifyPermission();
4989 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4990 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4991 channel);
4992 }
4993
4994 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 final long identity = Binder.clearCallingIdentity();
4996 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004997 if (channel < 0) {
4998 return false;
4999 }
Jordan Liu4c733742019-02-28 12:03:40 -08005000 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5001 null /* workSource */);
5002 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 return success;
5004 } finally {
5005 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005006 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005007 }
5008
5009 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005010 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005011 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5013 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005014 if (DBG) {
5015 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5016 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5017 + p3 + " data=" + data);
5018 }
5019 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5020 command, p1, p2, p3, data);
5021 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005022
Jordan Liu4c733742019-02-28 12:03:40 -08005023 @Override
5024 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5025 int command, int p1, int p2, int p3, String data) {
5026 enforceModifyPermission();
5027 if (DBG) {
5028 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5029 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5030 + p3 + " data=" + data);
5031 }
5032 return iccTransmitApduLogicalChannelWithPermission(
5033 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5034 data);
5035 }
5036
5037 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5038 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039 final long identity = Binder.clearCallingIdentity();
5040 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005041 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 return "";
5043 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005045 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005046 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5047 null /* workSource */);
5048 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 // Append the returned status code to the end of the response payload.
5051 String s = Integer.toHexString(
5052 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5053 if (response.payload != null) {
5054 s = IccUtils.bytesToHexString(response.payload) + s;
5055 }
5056 return s;
5057 } finally {
5058 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005059 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005060 }
Jake Hambye994d462014-02-03 13:10:13 -08005061
Evan Charltonc66da362014-05-16 14:06:40 -07005062 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005063 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5064 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5066 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005068 if (DBG) {
5069 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5070 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5071 }
5072 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5073 cla, command, p1, p2, p3, data);
5074 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005075
Jordan Liu4c733742019-02-28 12:03:40 -08005076 @Override
5077 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5078 int command, int p1, int p2, int p3, String data) {
5079 enforceModifyPermission();
5080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5081 if (DBG) {
5082 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5083 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5084 + " data=" + data);
5085 }
5086
5087 return iccTransmitApduBasicChannelWithPermission(
5088 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5089 p2, p3, data);
5090 }
5091
5092 // open APDU basic channel assuming the caller has sufficient permissions
5093 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5094 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 final long identity = Binder.clearCallingIdentity();
5096 try {
5097 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5098 && TextUtils.equals(ISDR_AID, data)) {
5099 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005100 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5101 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 if (bestComponent == null
5103 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5104 loge("The calling package is not allowed to select ISD-R.");
5105 throw new SecurityException(
5106 "The calling package is not allowed to select ISD-R.");
5107 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005108 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005111 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5112 null /* workSource */);
5113 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 // Append the returned status code to the end of the response payload.
5116 String s = Integer.toHexString(
5117 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5118 if (response.payload != null) {
5119 s = IccUtils.bytesToHexString(response.payload) + s;
5120 }
5121 return s;
5122 } finally {
5123 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005124 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005125 }
5126
5127 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005128 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005129 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5131 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 if (DBG) {
5136 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5137 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5138 }
5139
5140 IccIoResult response =
5141 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5142 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5143 subId);
5144
5145 if (DBG) {
5146 log("Exchange SIM_IO [R]" + response);
5147 }
5148
5149 byte[] result = null;
5150 int length = 2;
5151 if (response.payload != null) {
5152 length = 2 + response.payload.length;
5153 result = new byte[length];
5154 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5155 } else {
5156 result = new byte[length];
5157 }
5158
5159 result[length - 1] = (byte) response.sw2;
5160 result[length - 2] = (byte) response.sw1;
5161 return result;
5162 } finally {
5163 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005164 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005165 }
5166
Nathan Haroldb3014052017-01-25 15:57:32 -08005167 /**
5168 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5169 * on a particular subscription
5170 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005171 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5172 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005174 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005175 return null;
5176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177
5178 final long identity = Binder.clearCallingIdentity();
5179 try {
5180 if (appType != TelephonyManager.APPTYPE_USIM
5181 && appType != TelephonyManager.APPTYPE_SIM) {
5182 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5183 return null;
5184 }
5185 Object response = sendRequest(
5186 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5187 if (response instanceof String[]) {
5188 return (String[]) response;
5189 }
yincheng zhaod698b842019-09-06 17:06:54 -07005190 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005192 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 } finally {
5194 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005195 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005196 }
5197
yincheng zhaod698b842019-09-06 17:06:54 -07005198 /**
5199 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5200 * subscription.
5201 *
5202 * @param subId the id of the subscription.
5203 * @param appType the uicc app type, must be USIM or SIM.
5204 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5205 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005206 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005207 * @return number of fplmns that is successfully written to the SIM.
5208 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005209 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5210 String callingFeatureId) {
5211 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5212 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005213 if (DBG) logv("no permissions for setForbiddenplmns");
5214 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5215 }
5216 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5217 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5218 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5219 }
5220 if (fplmns == null) {
5221 throw new IllegalArgumentException("Fplmn List provided is null");
5222 }
5223 for (String fplmn : fplmns) {
5224 if (!CellIdentity.isValidPlmn(fplmn)) {
5225 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5226 }
5227 }
5228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 Object response = sendRequest(
5231 CMD_SET_FORBIDDEN_PLMNS,
5232 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5233 subId);
5234 return (int) response;
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
5238 }
5239
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005240 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005241 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5243 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 final long identity = Binder.clearCallingIdentity();
5246 try {
5247 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5248 if (response.payload == null) {
5249 return "";
5250 }
Evan Charltonc66da362014-05-16 14:06:40 -07005251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 // Append the returned status code to the end of the response payload.
5253 String s = Integer.toHexString(
5254 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5255 s = IccUtils.bytesToHexString(response.payload) + s;
5256 return s;
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
Evan Charltonc66da362014-05-16 14:06:40 -07005260 }
5261
Jake Hambye994d462014-02-03 13:10:13 -08005262 /**
5263 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5264 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5265 *
5266 * @param itemID the ID of the item to read
5267 * @return the NV item as a String, or null on error.
5268 */
5269 @Override
5270 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005271 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5273 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274
5275 final long identity = Binder.clearCallingIdentity();
5276 try {
5277 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005278 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5280 return value;
5281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
Jake Hambye994d462014-02-03 13:10:13 -08005284 }
5285
5286 /**
5287 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5288 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5289 *
5290 * @param itemID the ID of the item to read
5291 * @param itemValue the value to write, as a String
5292 * @return true on success; false on any failure
5293 */
5294 @Override
5295 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5298 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299
5300 final long identity = Binder.clearCallingIdentity();
5301 try {
5302 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5303 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005304 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5306 return success;
5307 } finally {
5308 Binder.restoreCallingIdentity(identity);
5309 }
Jake Hambye994d462014-02-03 13:10:13 -08005310 }
5311
5312 /**
5313 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5314 * Used for device configuration by some CDMA operators.
5315 *
5316 * @param preferredRoamingList byte array containing the new PRL
5317 * @return true on success; false on any failure
5318 */
5319 @Override
5320 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5322 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323
5324 final long identity = Binder.clearCallingIdentity();
5325 try {
5326 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5327 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5328 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5329 return success;
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
5332 }
Jake Hambye994d462014-02-03 13:10:13 -08005333 }
5334
5335 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005336 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005337 * Used for device configuration by some CDMA operators.
5338 *
chen xu6dac5ab2018-10-26 17:39:23 -07005339 * @param slotIndex - device slot.
5340 *
Jake Hambye994d462014-02-03 13:10:13 -08005341 * @return true on success; false on any failure
5342 */
5343 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005344 public boolean resetModemConfig(int slotIndex) {
5345 Phone phone = PhoneFactory.getPhone(slotIndex);
5346 if (phone != null) {
5347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5348 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349
chen xu6dac5ab2018-10-26 17:39:23 -07005350 final long identity = Binder.clearCallingIdentity();
5351 try {
5352 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5353 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5354 return success;
5355 } finally {
5356 Binder.restoreCallingIdentity(identity);
5357 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 }
chen xu6dac5ab2018-10-26 17:39:23 -07005359 return false;
5360 }
5361
5362 /**
5363 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5364 *
5365 * @param slotIndex - device slot.
5366 *
5367 * @return true on success; false on any failure
5368 */
5369 @Override
5370 public boolean rebootModem(int slotIndex) {
5371 Phone phone = PhoneFactory.getPhone(slotIndex);
5372 if (phone != null) {
5373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5374 mApp, phone.getSubId(), "rebootModem");
5375
5376 final long identity = Binder.clearCallingIdentity();
5377 try {
5378 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5379 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5380 return success;
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
5383 }
5384 }
5385 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005386 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005387
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005388 public String[] getPcscfAddress(String apnType, String callingPackage,
5389 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005390 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005391 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5392 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005393 return new String[0];
5394 }
5395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 final long identity = Binder.clearCallingIdentity();
5397 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005398 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
Wink Saville36469e72014-06-11 15:17:00 -07005402 }
5403
Brad Ebinger51f743a2017-01-23 13:50:20 -08005404 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005405 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5406 * {@link #disableIms(int)}.
5407 * @param slotIndex device slot.
5408 */
5409 public void resetIms(int slotIndex) {
5410 enforceModifyPermission();
5411
5412 final long identity = Binder.clearCallingIdentity();
5413 try {
5414 if (mImsResolver == null) {
5415 // may happen if the does not support IMS.
5416 return;
5417 }
5418 mImsResolver.disableIms(slotIndex);
5419 mImsResolver.enableIms(slotIndex);
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
5423 }
5424
5425 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005426 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5427 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005428 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005429 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431
5432 final long identity = Binder.clearCallingIdentity();
5433 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005434 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005435 // may happen if the device does not support IMS.
5436 return;
5437 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005438 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 } finally {
5440 Binder.restoreCallingIdentity(identity);
5441 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005442 }
5443
5444 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005445 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5446 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005447 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005448 public void disableIms(int slotId) {
5449 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450
5451 final long identity = Binder.clearCallingIdentity();
5452 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005453 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005454 // may happen if the device does not support IMS.
5455 return;
5456 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005457 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 } finally {
5459 Binder.restoreCallingIdentity(identity);
5460 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005461 }
5462
5463 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005464 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5465 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005466 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005467 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005468 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005469 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470
5471 final long identity = Binder.clearCallingIdentity();
5472 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005473 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005474 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5475 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005476 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005477 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 } finally {
5479 Binder.restoreCallingIdentity(identity);
5480 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005481 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005482 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005483 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5484 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005485 @Override
5486 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005487 enforceModifyPermission();
5488
5489 final long identity = Binder.clearCallingIdentity();
5490 try {
5491 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005492 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
5496 }
5497
5498 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005499 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005500 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005501 */
5502 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504
5505 final long identity = Binder.clearCallingIdentity();
5506 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005507 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005508 // may happen if the device does not support IMS.
5509 return null;
5510 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005511 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 } finally {
5513 Binder.restoreCallingIdentity(identity);
5514 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005515 }
5516
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005517 /**
5518 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005519 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005520 */
5521 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5522 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523
5524 final long identity = Binder.clearCallingIdentity();
5525 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005526 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005527 // may happen if the device does not support IMS.
5528 return null;
5529 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005530 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005534 }
5535
Brad Ebinger884c07b2018-02-15 16:17:40 -08005536 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005537 * Sets the ImsService Package Name that Telephony will bind to.
5538 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005539 * @param slotIndex the slot ID that the ImsService should bind for.
5540 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005541 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005542 * @param featureTypes An integer array of feature types associated with a packageName.
5543 * @param packageName The name of the package that the current configuration will be replaced
5544 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005545 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005546 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005547 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5548 int[] featureTypes, String packageName) {
5549 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5550 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005551 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5552 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005553 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005554
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555 final long identity = Binder.clearCallingIdentity();
5556 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005557 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005558 // may happen if the device does not support IMS.
5559 return false;
5560 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005561 Map<Integer, String> featureConfig = new HashMap<>();
5562 for (int featureType : featureTypes) {
5563 featureConfig.put(featureType, packageName);
5564 }
5565 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5566 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005570 }
5571
5572 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005573 * Clears any carrier ImsService overrides for the slot index specified that were previously
5574 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5575 *
5576 * This should only be used for testing.
5577 *
5578 * @param slotIndex the slot ID that the ImsService should bind for.
5579 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5580 */
5581 @Override
5582 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5583 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5584 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5585 "clearCarrierImsServiceOverride");
5586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5587 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5588 "clearCarrierImsServiceOverride");
5589
5590 final long identity = Binder.clearCallingIdentity();
5591 try {
5592 if (mImsResolver == null) {
5593 // may happen if the device does not support IMS.
5594 return false;
5595 }
5596 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
5599 }
5600 }
5601
5602 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005603 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005604 *
5605 * @param slotId The slot that the ImsService is associated with.
5606 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5607 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005608 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005609 * @return the package name of the ImsService configuration.
5610 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005611 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5612 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005613 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005614 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005615 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005616 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5617 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 final long identity = Binder.clearCallingIdentity();
5620 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005621 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005622 // may happen if the device does not support IMS.
5623 return "";
5624 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005625 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005626 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5627 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 } finally {
5629 Binder.restoreCallingIdentity(identity);
5630 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005631 }
5632
Brad Ebinger77b832e2019-10-17 17:03:22 -07005633 /**
5634 * Get the MmTelFeature state associated with the requested subscription id.
5635 * @param subId The subscription that the MmTelFeature is associated with.
5636 * @param callback A callback with an integer containing the
5637 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5638 */
5639 @Override
5640 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5641 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5642 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5643 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5644 "IMS not available on device.");
5645 }
5646 final long token = Binder.clearCallingIdentity();
5647 try {
5648 int slotId = getSlotIndex(subId);
5649 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5650 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5651 + subId + "'");
5652 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5653 }
5654 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5655 try {
5656 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5657 } catch (RemoteException e) {
5658 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5659 + "Ignore");
5660 }
5661 });
5662 } finally {
5663 Binder.restoreCallingIdentity(token);
5664 }
5665 }
5666
Daniel Brightbb5840b2021-01-12 15:48:18 -08005667 /**
5668 * Sets the ims registration state on all valid {@link Phone}s.
5669 */
5670 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005671 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672
5673 final long identity = Binder.clearCallingIdentity();
5674 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005675 // NOTE: Before S, this method only set the default phone.
5676 for (final Phone phone : PhoneFactory.getPhones()) {
5677 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5678 phone.setImsRegistrationState(registered);
5679 }
5680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
Wink Saville36469e72014-06-11 15:17:00 -07005684 }
5685
5686 /**
Stuart Scott54788802015-03-30 13:18:01 -07005687 * Set the network selection mode to automatic.
5688 *
5689 */
5690 @Override
5691 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5693 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
shilufc958392020-01-20 11:36:01 -08005697 if (!isActiveSubscription(subId)) {
5698 return;
5699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005701 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5702 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
Stuart Scott54788802015-03-30 13:18:01 -07005706 }
5707
Jack Yud10cdd42020-09-28 20:28:01 -07005708 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005709 * Ask the radio to connect to the input network and change selection mode to manual.
5710 *
5711 * @param subId the id of the subscription.
5712 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5713 * the operator to attach to.
5714 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5715 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5716 * normal network selection next time.
5717 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005718 */
5719 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005720 public boolean setNetworkSelectionModeManual(
5721 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5723 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005724
5725 if (!isActiveSubscription(subId)) {
5726 return false;
5727 }
5728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 final long identity = Binder.clearCallingIdentity();
5730 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005731 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005733 if (DBG) {
5734 log("setNetworkSelectionModeManual: subId: " + subId
5735 + " operator: " + operatorInfo);
5736 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005737 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005741 }
shilu84f6e8b2019-12-19 13:58:01 -08005742 /**
5743 * Get the manual network selection
5744 *
5745 * @param subId the id of the subscription.
5746 *
5747 * @return the previously saved user selected PLMN
5748 */
5749 @Override
5750 public String getManualNetworkSelectionPlmn(int subId) {
5751 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005752 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005753 mApp, subId, "getManualNetworkSelectionPlmn");
5754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 if (!isActiveSubscription(subId)) {
5758 return "";
5759 }
5760
5761 final Phone phone = getPhone(subId);
5762 if (phone == null) {
5763 return "";
5764 }
5765 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5766 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5767 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5768 } finally {
5769 Binder.restoreCallingIdentity(identity);
5770 }
5771 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005772
5773 /**
5774 * Scans for available networks.
5775 */
5776 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005777 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5778 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5780 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005781 LocationAccessPolicy.LocationPermissionResult locationResult =
5782 LocationAccessPolicy.checkLocationPermission(mApp,
5783 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5784 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005785 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005786 .setCallingPid(Binder.getCallingPid())
5787 .setCallingUid(Binder.getCallingUid())
5788 .setMethod("getCellNetworkScanResults")
5789 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07005790 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5791 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005792 .build());
5793 switch (locationResult) {
5794 case DENIED_HARD:
5795 throw new SecurityException("Not allowed to access scan results -- location");
5796 case DENIED_SOFT:
5797 return null;
5798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799
Pengquan Menga1bb6272018-09-06 09:59:22 -07005800 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801 try {
5802 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005803 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 } finally {
5806 Binder.restoreCallingIdentity(identity);
5807 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005808 }
5809
5810 /**
sqian80370722020-01-29 15:02:51 -08005811 * Get the call forwarding info, given the call forwarding reason.
5812 */
5813 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005814 public void getCallForwarding(int subId, int callForwardingReason,
5815 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005816 enforceReadPrivilegedPermission("getCallForwarding");
5817 long identity = Binder.clearCallingIdentity();
5818 try {
5819 if (DBG) {
5820 log("getCallForwarding: subId " + subId
5821 + " callForwardingReason" + callForwardingReason);
5822 }
Hall Liua1acea22020-09-18 19:04:59 -07005823
5824 Phone phone = getPhone(subId);
5825 if (phone == null) {
5826 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005827 callback.onError(
5828 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005829 } catch (RemoteException e) {
5830 // ignore
5831 }
5832 return;
5833 }
5834
5835 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5836 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5837 @Override
5838 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5839 try {
5840 callback.onCallForwardingInfoAvailable(info);
5841 } catch (RemoteException e) {
5842 // ignore
5843 }
5844 }
5845
5846 @Override
5847 public void onError(int error) {
5848 try {
5849 callback.onError(error);
5850 } catch (RemoteException e) {
5851 // ignore
5852 }
5853 }
5854 });
5855 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005856 } finally {
5857 Binder.restoreCallingIdentity(identity);
5858 }
5859 }
5860
5861 /**
5862 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5863 * reason, the number to forward, and the timeout before the forwarding is attempted.
5864 */
5865 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005866 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5867 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005868 enforceModifyPermission();
5869 long identity = Binder.clearCallingIdentity();
5870 try {
5871 if (DBG) {
5872 log("setCallForwarding: subId " + subId
5873 + " callForwardingInfo" + callForwardingInfo);
5874 }
Hall Liua1acea22020-09-18 19:04:59 -07005875
5876 Phone phone = getPhone(subId);
5877 if (phone == null) {
5878 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005879 callback.accept(
5880 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005881 } catch (RemoteException e) {
5882 // ignore
5883 }
5884 return;
5885 }
5886
5887 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5888 FunctionalUtils.ignoreRemoteException(callback::accept));
5889
5890 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
5894 }
5895
5896 /**
Hall Liua1acea22020-09-18 19:04:59 -07005897 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005898 */
5899 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005900 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWangc63cf522021-03-31 22:08:45 +08005901 enforceReadPrivilegedPermission("getCallWaitingStatus");
sqian80370722020-01-29 15:02:51 -08005902 long identity = Binder.clearCallingIdentity();
5903 try {
Hall Liua1acea22020-09-18 19:04:59 -07005904 Phone phone = getPhone(subId);
5905 if (phone == null) {
5906 try {
5907 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5908 } catch (RemoteException e) {
5909 // ignore
5910 }
5911 return;
5912 }
SongFerngWangc63cf522021-03-31 22:08:45 +08005913 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5914 PersistableBundle c = configManager.getConfigForSubId(subId);
5915 boolean requireUssd = c.getBoolean(
5916 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005917
sqian80370722020-01-29 15:02:51 -08005918 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWangc63cf522021-03-31 22:08:45 +08005919 if (requireUssd) {
5920 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5921 getSubscriptionCarrierId(subId));
5922 String newUssdCommand = "";
5923 try {
5924 newUssdCommand = carrierXmlParser.getFeature(
5925 CarrierXmlParser.FEATURE_CALL_WAITING)
5926 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
5927 } catch (NullPointerException e) {
5928 loge("Failed to generate USSD number" + e);
5929 }
5930 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5931 mMainThreadHandler, callback, carrierXmlParser,
5932 CarrierXmlParser.SsEntry.SSAction.QUERY);
5933 final String ussdCommand = newUssdCommand;
5934 Executors.newSingleThreadExecutor().execute(() -> {
5935 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5936 });
5937 } else {
5938 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
5939 callback::accept);
5940 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
5941 }
sqian80370722020-01-29 15:02:51 -08005942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
5945 }
5946
5947 /**
Hall Liua1acea22020-09-18 19:04:59 -07005948 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005949 */
5950 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005951 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005952 enforceModifyPermission();
5953 long identity = Binder.clearCallingIdentity();
5954 try {
Hall Liua1acea22020-09-18 19:04:59 -07005955 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5956
5957 Phone phone = getPhone(subId);
5958 if (phone == null) {
5959 try {
5960 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5961 } catch (RemoteException e) {
5962 // ignore
5963 }
5964 return;
5965 }
5966
SongFerngWangc63cf522021-03-31 22:08:45 +08005967 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5968 PersistableBundle c = configManager.getConfigForSubId(subId);
5969 boolean requireUssd = c.getBoolean(
5970 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005971
SongFerngWangc63cf522021-03-31 22:08:45 +08005972 if (DBG) log("getCallWaitingStatus: subId " + subId);
5973 if (requireUssd) {
5974 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5975 getSubscriptionCarrierId(subId));
5976 CarrierXmlParser.SsEntry.SSAction ssAction =
5977 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
5978 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
5979 String newUssdCommand = "";
5980 try {
5981 newUssdCommand = carrierXmlParser.getFeature(
5982 CarrierXmlParser.FEATURE_CALL_WAITING)
5983 .makeCommand(ssAction, null);
5984 } catch (NullPointerException e) {
5985 loge("Failed to generate USSD number" + e);
5986 }
5987 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5988 mMainThreadHandler, callback, carrierXmlParser, ssAction);
5989 final String ussdCommand = newUssdCommand;
5990 Executors.newSingleThreadExecutor().execute(() -> {
5991 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5992 });
5993 } else {
5994 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5995 FunctionalUtils.ignoreRemoteException(callback::accept));
5996
5997 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
5998 }
sqian80370722020-01-29 15:02:51 -08005999 } finally {
6000 Binder.restoreCallingIdentity(identity);
6001 }
6002 }
6003
6004 /**
yinxub1bed742017-04-17 11:45:04 -07006005 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006006 *
yinxub1bed742017-04-17 11:45:04 -07006007 * @param subId id of the subscription
6008 * @param request contains the radio access networks with bands/channels to scan
6009 * @param messenger callback messenger for scan results or errors
6010 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006011 * @return the id of the requested scan which can be used to stop the scan.
6012 */
6013 @Override
6014 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006015 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6017 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006018 LocationAccessPolicy.LocationPermissionResult locationResult =
6019 LocationAccessPolicy.checkLocationPermission(mApp,
6020 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6021 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006022 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006023 .setCallingPid(Binder.getCallingPid())
6024 .setCallingUid(Binder.getCallingUid())
6025 .setMethod("requestNetworkScan")
6026 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6027 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006028 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07006029 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6030 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006031 if (e != null) {
6032 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6033 throw e;
6034 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006035 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006036 return TelephonyScanManager.INVALID_SCAN_ID;
6037 }
6038 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 }
Hall Liu912dfd32019-04-25 14:02:26 -07006040 int callingUid = Binder.getCallingUid();
6041 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006042 final long identity = Binder.clearCallingIdentity();
6043 try {
6044 return mNetworkScanRequestTracker.startNetworkScan(
6045 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006046 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006047 } finally {
6048 Binder.restoreCallingIdentity(identity);
6049 }
yinxu504e1392017-04-12 16:03:22 -07006050 }
6051
Hall Liub2ac8ef2019-02-28 15:56:23 -08006052 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07006053 NetworkScanRequest request, int subId, String callingPackage) {
6054 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006055 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6056 boolean hasNetworkScanPermission =
6057 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6058 == PERMISSION_GRANTED;
6059
6060 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6061 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6062 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006063 }
6064
6065 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6066 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006067 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6068 return new SecurityException("Specific channels must not be"
6069 + " scanned without location access.");
6070 }
6071 }
6072 }
6073
Hall Liub2ac8ef2019-02-28 15:56:23 -08006074 return null;
6075 }
6076
yinxu504e1392017-04-12 16:03:22 -07006077 /**
6078 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006079 *
6080 * @param subId id of the subscription
6081 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006082 */
6083 @Override
6084 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6086 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087
Hall Liu912dfd32019-04-25 14:02:26 -07006088 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 final long identity = Binder.clearCallingIdentity();
6090 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006091 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 } finally {
6093 Binder.restoreCallingIdentity(identity);
6094 }
yinxu504e1392017-04-12 16:03:22 -07006095 }
6096
6097 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006098 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006099 *
SongFerngWang9e060372020-12-21 16:41:52 +08006100 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006101 */
6102 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006103 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006104 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006105 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006106 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107
6108 final long identity = Binder.clearCallingIdentity();
6109 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006110 if (DBG) log("getAllowedNetworkTypesBitmask");
6111 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6112 int networkTypesBitmask = (result != null ? result[0] : -1);
6113 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6114 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006118 }
6119
6120 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006121 * Get the allowed network types for certain reason.
6122 *
6123 * @param subId the id of the subscription.
6124 * @param reason the reason the allowed network type change is taking place
6125 * @return the allowed network types.
6126 */
6127 @Override
6128 public long getAllowedNetworkTypesForReason(int subId,
6129 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006130 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006131 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006132 final long identity = Binder.clearCallingIdentity();
6133 try {
6134 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
6138 }
6139
6140 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006141 * Enable/Disable E-UTRA-NR Dual Connectivity
6142 * @param subId subscription id of the sim card
6143 * @param nrDualConnectivityState expected NR dual connectivity state
6144 * This can be passed following states
6145 * <ol>
6146 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6147 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6148 * <li>Disable NR dual connectivity and force secondary cell to be released
6149 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6150 * </ol>
6151 * @return operation result.
6152 */
6153 @Override
6154 public int setNrDualConnectivityState(int subId,
6155 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6157 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006158 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006159 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6160 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6161 }
6162
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006163 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6164 final long identity = Binder.clearCallingIdentity();
6165 try {
6166 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6167 nrDualConnectivityState, subId,
6168 workSource);
6169 if (DBG) log("enableNRDualConnectivity result: " + result);
6170 return result;
6171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
6174 }
6175
6176 /**
6177 * Is E-UTRA-NR Dual Connectivity enabled
6178 * @return true if dual connectivity is enabled else false
6179 */
6180 @Override
6181 public boolean isNrDualConnectivityEnabled(int subId) {
6182 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006183 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006184 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006185 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006186 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6187 return false;
6188 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006189 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6190 final long identity = Binder.clearCallingIdentity();
6191 try {
6192 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6193 null, subId, workSource);
6194 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6195 return isEnabled;
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
6199 }
6200
6201 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006202 * Set the allowed network types of the device and
6203 * provide the reason triggering the allowed network change.
6204 *
6205 * @param subId the id of the subscription.
6206 * @param reason the reason the allowed network type change is taking place
6207 * @param allowedNetworkTypes the allowed network types.
6208 * @return true on success; false on any failure.
6209 */
6210 @Override
6211 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006212 @TelephonyManager.AllowedNetworkTypesReason int reason,
6213 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6215 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006216 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWangc2d3ccc2021-04-15 19:46:33 +08006217 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6218 return false;
6219 }
6220 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6221 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang9e060372020-12-21 16:41:52 +08006222 return false;
6223 }
6224
SongFerngWang522637d2021-03-02 22:09:29 +08006225 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6226 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6227
6228
6229 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6230 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6231 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006232 }
SongFerngWang522637d2021-03-02 22:09:29 +08006233
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006234 final long identity = Binder.clearCallingIdentity();
6235 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006236 Boolean success = (Boolean) sendRequest(
6237 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6238 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6239
6240 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6241 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006242 } finally {
6243 Binder.restoreCallingIdentity(identity);
6244 }
6245 }
6246
6247 /**
Miaoa84611c2019-03-15 09:21:10 +08006248 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006249 *
Miaoa84611c2019-03-15 09:21:10 +08006250 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006251 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006252 * @hide
6253 */
6254 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006255 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006256 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006258 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 try {
Miaoa84611c2019-03-15 09:21:10 +08006260 if (phone != null) {
6261 return phone.hasMatchedTetherApnSetting();
6262 } else {
6263 return false;
6264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006265 } finally {
6266 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006267 }
Junda Liu475951f2014-11-07 16:45:03 -08006268 }
6269
6270 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006271 * Enable or disable always reporting signal strength changes from radio.
6272 *
6273 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6274 */
6275 @Override
6276 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6277 enforceModifyPermission();
6278 enforceSystemCaller();
6279
6280 final long identity = Binder.clearCallingIdentity();
6281 final Phone phone = getPhone(subId);
6282 try {
6283 if (phone != null) {
6284 if (DBG) {
6285 log("setAlwaysReportSignalStrength: subId=" + subId
6286 + " isEnable=" + isEnable);
6287 }
6288 phone.setAlwaysReportSignalStrength(isEnable);
6289 } else {
6290 loge("setAlwaysReportSignalStrength: no phone found for subId="
6291 + subId);
6292 }
6293 } finally {
6294 Binder.restoreCallingIdentity(identity);
6295 }
6296 }
6297
6298 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006299 * Get the user enabled state of Mobile Data.
6300 *
6301 * TODO: remove and use isUserDataEnabled.
6302 * This can't be removed now because some vendor codes
6303 * calls through ITelephony directly while they should
6304 * use TelephonyManager.
6305 *
6306 * @return true on enabled
6307 */
6308 @Override
6309 public boolean getDataEnabled(int subId) {
6310 return isUserDataEnabled(subId);
6311 }
6312
6313 /**
6314 * Get whether mobile data is enabled per user setting.
6315 *
6316 * There are other factors deciding whether mobile data is actually enabled, but they are
6317 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006318 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006319 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006320 *
6321 * @return {@code true} if data is enabled else {@code false}
6322 */
6323 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006324 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006325 try {
6326 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6327 null);
6328 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6330 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006331 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332
6333 final long identity = Binder.clearCallingIdentity();
6334 try {
6335 int phoneId = mSubscriptionController.getPhoneId(subId);
6336 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6337 Phone phone = PhoneFactory.getPhone(phoneId);
6338 if (phone != null) {
6339 boolean retVal = phone.isUserDataEnabled();
6340 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6341 return retVal;
6342 } else {
6343 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6344 return false;
6345 }
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006348 }
6349 }
6350
6351 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006352 * Checks if the device is capable of mobile data by considering whether whether the
6353 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6354 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006355 *
Shuo Qian985d1232020-01-08 14:30:06 -08006356 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006357 */
6358 @Override
6359 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006360 try {
6361 try {
6362 mApp.enforceCallingOrSelfPermission(
6363 android.Manifest.permission.ACCESS_NETWORK_STATE,
6364 null);
6365 } catch (Exception e) {
6366 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6367 "isDataEnabled");
6368 }
6369 } catch (Exception e) {
6370 enforceReadPrivilegedPermission("isDataEnabled");
6371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372
6373 final long identity = Binder.clearCallingIdentity();
6374 try {
6375 int phoneId = mSubscriptionController.getPhoneId(subId);
6376 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6377 Phone phone = PhoneFactory.getPhone(phoneId);
6378 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006379 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6381 return retVal;
6382 } else {
6383 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6384 return false;
6385 }
6386 } finally {
6387 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006388 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006389 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006390
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006391 /**
6392 * Check if data is enabled for a specific reason
6393 * @param subId Subscription index
6394 * @param reason the reason the data enable change is taking place
6395 * @return {@code true} if the overall data is enabled; {@code false} if not.
6396 */
6397 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006398 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006399 @TelephonyManager.DataEnabledReason int reason) {
6400 try {
6401 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6402 null);
6403 } catch (Exception e) {
6404 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006405 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006406 }
6407
6408
6409 final long identity = Binder.clearCallingIdentity();
6410 try {
6411 int phoneId = mSubscriptionController.getPhoneId(subId);
6412 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006413 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006414 + " reason=" + reason);
6415 }
6416 Phone phone = PhoneFactory.getPhone(phoneId);
6417 if (phone != null) {
6418 boolean retVal;
6419 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6420 retVal = phone.isUserDataEnabled();
6421 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006422 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006423 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006424 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006425 return retVal;
6426 } else {
6427 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006428 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006429 + subId + " retVal=false");
6430 }
6431 return false;
6432 }
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
6436 }
6437
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006438 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006439 Phone phone) {
Sarah Chinca45c312021-04-09 10:37:15 -07006440 if (uid == Process.PHONE_UID) {
6441 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6442 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liuce478d22020-07-13 12:13:03 -07006443 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6444 }
6445
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006446 //load access rules from carrier configs, and check those as well: b/139133814
6447 SubscriptionController subController = SubscriptionController.getInstance();
6448 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6449 || subController == null) return privilegeFromSim;
6450
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006451 PackageManager pkgMgr = phone.getContext().getPackageManager();
6452 String[] packages = pkgMgr.getPackagesForUid(uid);
6453
6454 final long identity = Binder.clearCallingIdentity();
6455 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006456 int subId = phone.getSubId();
6457 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6458 // A test override is in place for the privileges for this subId, so don't try to
6459 // read the subscription privileges.
6460 return privilegeFromSim;
6461 }
6462 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006463 SubscriptionManager subManager = (SubscriptionManager)
6464 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6465 for (String pkg : packages) {
6466 if (subManager.canManageSubscription(subInfo, pkg)) {
6467 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6468 }
6469 }
6470 return privilegeFromSim;
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
6474 }
6475
6476 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6477 String pkgName) {
6478 //load access rules from carrier configs, and check those as well: b/139133814
6479 SubscriptionController subController = SubscriptionController.getInstance();
6480 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6481 || subController == null) return privilegeFromSim;
6482
6483 final long identity = Binder.clearCallingIdentity();
6484 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006485 int subId = phone.getSubId();
6486 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6487 // A test override is in place for the privileges for this subId, so don't try to
6488 // read the subscription privileges.
6489 return privilegeFromSim;
6490 }
6491 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006492 SubscriptionManager subManager = (SubscriptionManager)
6493 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6494 return subManager.canManageSubscription(subInfo, pkgName)
6495 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
6499 }
6500
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006501 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006502 public int getCarrierPrivilegeStatus(int subId) {
6503 final Phone phone = getPhone(subId);
6504 if (phone == null) {
6505 loge("getCarrierPrivilegeStatus: Invalid subId");
6506 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6507 }
6508 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006509 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006510 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006511 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6512 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006513
6514 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6515 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006516 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006517 }
Junda Liu29340342014-07-10 15:23:27 -07006518
6519 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006520 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006521 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006522 final Phone phone = getPhone(subId);
6523 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006524 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006525 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6526 }
6527 UiccProfile profile =
6528 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6529 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006530 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006531 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6532 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006533 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006534 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006535 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006536 }
6537
6538 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006539 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6540 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006541 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006542 }
6543
6544 int phoneId = SubscriptionManager.getPhoneId(subId);
6545 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006546 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006547 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006548 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6549 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006550 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6551 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6552 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006553 }
6554
6555 @Override
6556 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006557 if (TextUtils.isEmpty(pkgName))
6558 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006559 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6560 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6561 UiccCard card = UiccController.getInstance().getUiccCard(i);
6562 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006563 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006564 continue;
6565 }
6566
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006567 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6568 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6569 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006570 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6571 break;
6572 }
6573 }
6574
6575 return result;
Junda Liu29340342014-07-10 15:23:27 -07006576 }
Derek Tan89e89d42014-07-08 17:00:10 -07006577
6578 @Override
Junda Liue64de782015-04-16 17:19:16 -07006579 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6580 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6581 loge("phoneId " + phoneId + " is not valid.");
6582 return null;
6583 }
6584 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006585 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006586 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006587 return null ;
6588 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006589 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006590 }
6591
Amith Yamasani6e118872016-02-19 12:53:51 -08006592 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006593 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006594 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006595 List<String> privilegedPackages = new ArrayList<>();
6596 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006597 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6598 // has UICC in that slot.
6599 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006600 if (card.hasCarrierPrivilegeRules()) {
6601 if (packages == null) {
6602 // Only check packages in user 0 for now
6603 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006604 PackageManager.MATCH_DISABLED_COMPONENTS
6605 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006606 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006607 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006608 }
6609 for (int p = packages.size() - 1; p >= 0; p--) {
6610 PackageInfo pkgInfo = packages.get(p);
6611 if (pkgInfo != null && pkgInfo.packageName != null
6612 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006613 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006614 privilegedPackages.add(pkgInfo.packageName);
6615 }
6616 }
6617 }
6618 }
6619 return privilegedPackages;
6620 }
6621
chen xuf7e9fe82019-05-09 19:31:02 -07006622 @Override
6623 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006624 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6625
6626 final long identity = Binder.clearCallingIdentity();
6627
chen xuf7e9fe82019-05-09 19:31:02 -07006628 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006629 try {
6630 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6631 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6632 }
6633 } finally {
6634 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006635 }
6636 return privilegedPackages;
6637 }
6638
Wink Savilleb564aae2014-10-23 10:18:09 -07006639 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006640 final Phone phone = getPhone(subId);
6641 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006642 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006643 return null;
6644 }
6645 String iccId = card.getIccId();
6646 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006647 return null;
6648 }
6649 return iccId;
6650 }
6651
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006652 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006653 public void setCallComposerStatus(int subId, int status) {
6654 enforceModifyPermission();
6655
6656 final long identity = Binder.clearCallingIdentity();
6657 try {
6658 Phone phone = getPhone(subId);
6659 if (phone != null) {
6660 Phone defaultPhone = phone.getImsPhone();
6661 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6662 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6663 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006664 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6665 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006666 }
6667 }
Shuo Qiand8782462020-12-22 19:10:14 -08006668 } catch (ImsException e) {
6669 throw new ServiceSpecificException(e.getCode());
6670 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006671 Binder.restoreCallingIdentity(identity);
6672 }
6673 }
6674
6675 @Override
6676 public int getCallComposerStatus(int subId) {
6677 enforceReadPrivilegedPermission("getCallComposerStatus");
6678
6679 final long identity = Binder.clearCallingIdentity();
6680 try {
6681 Phone phone = getPhone(subId);
6682 if (phone != null) {
6683 Phone defaultPhone = phone.getImsPhone();
6684 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6685 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6686 return imsPhone.getCallComposerStatus();
6687 }
6688 }
6689 } finally {
6690 Binder.restoreCallingIdentity(identity);
6691 }
6692 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6693 }
6694
6695 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006696 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6697 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006698 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006699 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 final long identity = Binder.clearCallingIdentity();
6702 try {
6703 final String iccId = getIccId(subId);
6704 final Phone phone = getPhone(subId);
6705 if (phone == null) {
6706 return false;
6707 }
6708 final String subscriberId = phone.getSubscriberId();
6709
6710 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006711 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 + subscriberId + " to " + number);
6713 }
6714
6715 if (TextUtils.isEmpty(iccId)) {
6716 return false;
6717 }
6718
6719 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6720
6721 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6722 if (alphaTag == null) {
6723 editor.remove(alphaTagPrefKey);
6724 } else {
6725 editor.putString(alphaTagPrefKey, alphaTag);
6726 }
6727
6728 // Record both the line number and IMSI for this ICCID, since we need to
6729 // track all merged IMSIs based on line number
6730 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6731 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6732 if (number == null) {
6733 editor.remove(numberPrefKey);
6734 editor.remove(subscriberPrefKey);
6735 } else {
6736 editor.putString(numberPrefKey, number);
6737 editor.putString(subscriberPrefKey, subscriberId);
6738 }
6739
6740 editor.commit();
6741 return true;
6742 } finally {
6743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006744 }
Derek Tan7226c842014-07-02 17:42:23 -07006745 }
6746
6747 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006748 public String getLine1NumberForDisplay(int subId, String callingPackage,
6749 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006750 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006751 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006752 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006753 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006754 return null;
6755 }
Derek Tan97ebb422014-09-05 16:55:38 -07006756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 final long identity = Binder.clearCallingIdentity();
6758 try {
6759 String iccId = getIccId(subId);
6760 if (iccId != null) {
6761 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6762 if (DBG_MERGE) {
6763 log("getLine1NumberForDisplay returning "
6764 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6765 }
6766 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6769 return null;
6770 } finally {
6771 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006772 }
Derek Tan7226c842014-07-02 17:42:23 -07006773 }
6774
6775 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006776 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6777 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006779 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006780 return null;
6781 }
Derek Tan97ebb422014-09-05 16:55:38 -07006782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 final long identity = Binder.clearCallingIdentity();
6784 try {
6785 String iccId = getIccId(subId);
6786 if (iccId != null) {
6787 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6788 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6789 }
6790 return null;
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006793 }
Derek Tan7226c842014-07-02 17:42:23 -07006794 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006795
6796 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006797 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6798 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006799 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6800 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006802 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006803 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006804 return null;
6805 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006806
Jordan Liub49b04b2019-05-06 14:45:15 -07006807 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6808 // the process, where TelephonyManager was instantiated.
6809 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006810 final long identity = Binder.clearCallingIdentity();
6811 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006812 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 final TelephonyManager tele = TelephonyManager.from(context);
6814 final SubscriptionManager sub = SubscriptionManager.from(context);
6815
6816 // Figure out what subscribers are currently active
6817 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006818
Jordan Liub49b04b2019-05-06 14:45:15 -07006819 // Only consider subs which match the current subId
6820 // This logic can be simplified. See b/131189269 for progress.
6821 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006822 activeSubscriberIds.add(tele.getSubscriberId(subId));
6823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824
6825 // First pass, find a number override for an active subscriber
6826 String mergeNumber = null;
6827 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6828 for (String key : prefs.keySet()) {
6829 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6830 final String subscriberId = (String) prefs.get(key);
6831 if (activeSubscriberIds.contains(subscriberId)) {
6832 final String iccId = key.substring(
6833 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6834 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6835 mergeNumber = (String) prefs.get(numberKey);
6836 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006837 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 + " for active subscriber " + subscriberId);
6839 }
6840 if (!TextUtils.isEmpty(mergeNumber)) {
6841 break;
6842 }
6843 }
6844 }
6845 }
6846
6847 // Shortcut when no active merged subscribers
6848 if (TextUtils.isEmpty(mergeNumber)) {
6849 return null;
6850 }
6851
6852 // Second pass, find all subscribers under that line override
6853 final ArraySet<String> result = new ArraySet<>();
6854 for (String key : prefs.keySet()) {
6855 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6856 final String number = (String) prefs.get(key);
6857 if (mergeNumber.equals(number)) {
6858 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6859 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6860 final String subscriberId = (String) prefs.get(subscriberKey);
6861 if (!TextUtils.isEmpty(subscriberId)) {
6862 result.add(subscriberId);
6863 }
6864 }
6865 }
6866 }
6867
6868 final String[] resultArray = result.toArray(new String[result.size()]);
6869 Arrays.sort(resultArray);
6870 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006871 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006872 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6873 }
6874 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006875 } finally {
6876 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006877 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006878 }
6879
6880 @Override
zoey chen38003472019-12-13 17:16:31 +08006881 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6882 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006883
6884 final long identity = Binder.clearCallingIdentity();
6885 try {
6886 final TelephonyManager telephonyManager = mApp.getSystemService(
6887 TelephonyManager.class);
6888 String subscriberId = telephonyManager.getSubscriberId(subId);
6889 if (subscriberId == null) {
6890 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006891 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006892 + subId);
6893 }
6894 return null;
6895 }
6896
6897 final SubscriptionInfo info = SubscriptionController.getInstance()
6898 .getSubscriptionInfo(subId);
6899 final ParcelUuid groupUuid = info.getGroupUuid();
6900 // If it doesn't belong to any group, return just subscriberId of itself.
6901 if (groupUuid == null) {
6902 return new String[]{subscriberId};
6903 }
6904
6905 // Get all subscriberIds from the group.
6906 final List<String> mergedSubscriberIds = new ArrayList<>();
6907 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006908 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006909 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006910 for (SubscriptionInfo subInfo : groupInfos) {
6911 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6912 if (subscriberId != null) {
6913 mergedSubscriberIds.add(subscriberId);
6914 }
6915 }
6916
6917 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6918 } finally {
6919 Binder.restoreCallingIdentity(identity);
6920
6921 }
6922 }
6923
6924 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006925 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006926 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006927 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928
6929 final long identity = Binder.clearCallingIdentity();
6930 try {
6931 final Phone phone = getPhone(subId);
6932 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6933 } finally {
6934 Binder.restoreCallingIdentity(identity);
6935 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006936 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006937
6938 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006939 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006940 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6941 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006942 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6943 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944
6945 final long identity = Binder.clearCallingIdentity();
6946 try {
6947 final Phone phone = getPhone(subId);
6948 if (phone == null) {
6949 return false;
6950 }
6951 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6952 cdmaNonRoamingList);
6953 } finally {
6954 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006955 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006956 }
6957
6958 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006959 @Deprecated
6960 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6961 enforceModifyPermission();
6962
6963 int returnValue = 0;
6964 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006965 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006966 if(result.exception == null) {
6967 if (result.result != null) {
6968 byte[] responseData = (byte[])(result.result);
6969 if(responseData.length > oemResp.length) {
6970 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6971 responseData.length + "bytes. Buffer Size is " +
6972 oemResp.length + "bytes.");
6973 }
6974 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6975 returnValue = responseData.length;
6976 }
6977 } else {
6978 CommandException ex = (CommandException) result.exception;
6979 returnValue = ex.getCommandError().ordinal();
6980 if(returnValue > 0) returnValue *= -1;
6981 }
6982 } catch (RuntimeException e) {
6983 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6984 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6985 if(returnValue > 0) returnValue *= -1;
6986 }
6987
6988 return returnValue;
6989 }
6990
6991 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006992 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006993 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006994 try {
6995 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006996 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07006997 mApp, phone.getSubId(), "getRadioAccessFamily");
6998 } catch (SecurityException e) {
6999 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7000 throw e;
7001 }
chen xub97461a2018-10-26 14:17:57 -07007002 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007003 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007004 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006 final long identity = Binder.clearCallingIdentity();
7007 try {
chen xub97461a2018-10-26 14:17:57 -07007008 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007009 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007010 mApp, phone.getSubId(), "getRadioAccessFamily");
7011 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 } finally {
7013 Binder.restoreCallingIdentity(identity);
7014 }
chen xub97461a2018-10-26 14:17:57 -07007015 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007016 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007017
7018 @Override
7019 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007020 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022
7023 final long identity = Binder.clearCallingIdentity();
7024 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007025 ImsManager.getInstance(defaultPhone.getContext(),
7026 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 } finally {
7028 Binder.restoreCallingIdentity(identity);
7029 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007030 }
7031
7032 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007033 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007034 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7036 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007037 return false;
7038 }
Svet Ganovb320e182015-04-16 12:30:10 -07007039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 final long identity = Binder.clearCallingIdentity();
7041 try {
7042 // Check the user preference and the system-level IMS setting. Even if the user has
7043 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7044 // In the long run, we may instead need to check if there exists a connection service
7045 // which can support video calling.
7046 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007047 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 return imsManager.isVtEnabledByPlatform()
7049 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7050 && imsManager.isVtEnabledByUser();
7051 } finally {
7052 Binder.restoreCallingIdentity(identity);
7053 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007054 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007055
Andrew Leea1239f22015-03-02 17:44:07 -08007056 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007057 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7058 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007060 mApp, subId, callingPackage, callingFeatureId,
7061 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 return false;
7063 }
7064
7065 final long identity = Binder.clearCallingIdentity();
7066 try {
7067 CarrierConfigManager configManager =
7068 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007069 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7071 } finally {
7072 Binder.restoreCallingIdentity(identity);
7073 }
Andrew Leea1239f22015-03-02 17:44:07 -08007074 }
7075
7076 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007077 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007079 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 return false;
7081 }
7082
7083 final long identity = Binder.clearCallingIdentity();
7084 try {
7085 CarrierConfigManager configManager =
7086 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007087 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7089 } finally {
7090 Binder.restoreCallingIdentity(identity);
7091 }
Andrew Leea1239f22015-03-02 17:44:07 -08007092 }
7093
Andrew Lee9431b832015-03-09 18:46:45 -07007094 @Override
7095 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007096 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007097 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007098 }
7099
7100 @Override
7101 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102 final long identity = Binder.clearCallingIdentity();
7103 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007104 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105 } finally {
7106 Binder.restoreCallingIdentity(identity);
7107 }
Andrew Lee9431b832015-03-09 18:46:45 -07007108 }
7109
Hall Liuf6668912018-10-31 17:05:23 -07007110 /**
7111 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7112 * support for the feature and device firmware support.
7113 *
7114 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7115 */
7116 @Override
7117 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007119 final Phone phone = getPhone(subscriptionId);
7120 if (phone == null) {
7121 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7122 return false;
7123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007125 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7127 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007128 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007129 return isCarrierSupported && isDeviceSupported;
7130 } finally {
7131 Binder.restoreCallingIdentity(identity);
7132 }
Hall Liu98187582018-01-22 19:15:32 -08007133 }
7134
Hall Liuf6668912018-10-31 17:05:23 -07007135 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007136 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7137 * RTT setting, will return true if the device and carrier both support RTT.
7138 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007139 */
7140 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 final long identity = Binder.clearCallingIdentity();
7142 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007143 boolean isRttSupported = isRttSupported(subscriptionId);
7144 boolean isUserRttSettingOn = Settings.Secure.getInt(
7145 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7146 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7147 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7148 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149 } finally {
7150 Binder.restoreCallingIdentity(identity);
7151 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007152 }
7153
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007154 @Deprecated
7155 @Override
7156 public String getDeviceId(String callingPackage) {
7157 return getDeviceIdWithFeature(callingPackage, null);
7158 }
7159
Sanket Padawe7310cc72015-01-14 09:53:20 -08007160 /**
7161 * Returns the unique device ID of phone, for example, the IMEI for
7162 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7163 *
7164 * <p>Requires Permission:
7165 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7166 */
7167 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007168 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007169 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007170 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007171 return null;
7172 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007173 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007174 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007175 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007176 return null;
7177 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178
7179 final long identity = Binder.clearCallingIdentity();
7180 try {
7181 return phone.getDeviceId();
7182 } finally {
7183 Binder.restoreCallingIdentity(identity);
7184 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007185 }
7186
Ping Sunc67b7c22016-03-02 19:16:45 +08007187 /**
7188 * {@hide}
7189 * Returns the IMS Registration Status on a particular subid
7190 *
7191 * @param subId
7192 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007193 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007194 Phone phone = getPhone(subId);
7195 if (phone != null) {
7196 return phone.isImsRegistered();
7197 } else {
7198 return false;
7199 }
7200 }
7201
Santos Cordon7a1885b2015-02-03 11:15:19 -08007202 @Override
7203 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 final long identity = Binder.clearCallingIdentity();
7205 try {
7206 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7207 } finally {
7208 Binder.restoreCallingIdentity(identity);
7209 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007210 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007211
Tyler Gunnf70ed162019-04-03 15:28:53 -07007212 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007213 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007214 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007216 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007217 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7218 }
7219 final long identity = Binder.clearCallingIdentity();
7220 try {
7221 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7222 } finally {
7223 Binder.restoreCallingIdentity(identity);
7224 }
7225 }
7226
7227 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007228 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007229 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7230 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007231 final long identity = Binder.clearCallingIdentity();
7232 try {
7233 Phone phone = getPhone(subscriptionId);
7234 if (phone == null) {
7235 return null;
7236 }
7237 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7238 } finally {
7239 Binder.restoreCallingIdentity(identity);
7240 }
7241 }
7242
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007243 /**
7244 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007245 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007246 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247 final long identity = Binder.clearCallingIdentity();
7248 try {
7249 Phone phone = getPhone(subId);
7250 if (phone != null) {
7251 return phone.isWifiCallingEnabled();
7252 } else {
7253 return false;
7254 }
7255 } finally {
7256 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007257 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007258 }
7259
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007260 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007261 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007262 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007263 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007264 final long identity = Binder.clearCallingIdentity();
7265 try {
7266 Phone phone = getPhone(subId);
7267 if (phone != null) {
7268 return phone.isVideoEnabled();
7269 } else {
7270 return false;
7271 }
7272 } finally {
7273 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007274 }
7275 }
7276
7277 /**
7278 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7279 * defined in {@link ImsRegistrationImplBase}.
7280 */
7281 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 final long identity = Binder.clearCallingIdentity();
7283 try {
7284 Phone phone = getPhone(subId);
7285 if (phone != null) {
7286 return phone.getImsRegistrationTech();
7287 } else {
7288 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7289 }
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007292 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007293 }
7294
Stuart Scott8eef64f2015-04-08 15:13:54 -07007295 @Override
7296 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007297 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007298 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7299 return;
7300 }
7301
Svet Ganovcc087f82015-05-12 20:35:54 -07007302 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007303
Svet Ganovcc087f82015-05-12 20:35:54 -07007304 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007305 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7306 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007307 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007308 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007309 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007310 Phone phone = getPhone(subId);
SongFerngWang51ee2b12021-05-27 22:44:54 +08007311 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007312 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7313 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007314 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007315 // There has been issues when Sms raw table somehow stores orphan
7316 // fragments. They lead to garbled message when new fragments come
7317 // in and combined with those stale ones. In case this happens again,
7318 // user can reset all network settings which will clean up this table.
7319 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007320 // Clean up IMS settings as well here.
7321 int slotId = getSlotIndex(subId);
7322 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7323 ImsManager.getInstance(mApp, slotId).factoryReset();
7324 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007325
7326 // Erase modem config if erase modem on network setting is enabled.
7327 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7328 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7329 if (configValue != null && Boolean.parseBoolean(configValue)) {
7330 sendEraseModemConfig(getDefaultPhone());
7331 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007332 } finally {
7333 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007334 }
7335 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007336
SongFerngWang51ee2b12021-05-27 22:44:54 +08007337 @VisibleForTesting
7338 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7339 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7340 return;
7341 }
7342 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7343 RILConstants.PREFERRED_NETWORK_MODE);
7344 SubscriptionManager.setSubscriptionProperty(subId,
7345 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7346 "user=" + defaultNetworkType);
7347 phone.loadAllowedNetworksFromSubscriptionDatabase();
7348 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7349 defaultNetworkType, null);
7350 }
7351
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007352 private void cleanUpSmsRawTable(Context context) {
7353 ContentResolver resolver = context.getContentResolver();
7354 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7355 resolver.delete(uri, null, null);
7356 }
7357
Narayan Kamath1c496c22015-04-16 14:40:19 +01007358 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007359 public String getSimLocaleForSubscriber(int subId) {
7360 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7361 final Phone phone = getPhone(subId);
7362 if (phone == null) {
7363 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007364 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007365 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 final long identity = Binder.clearCallingIdentity();
7367 try {
chen xu5d3637b2019-01-21 23:31:38 -08007368 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007369 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007370 if (info == null) {
7371 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7372 return null;
7373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007374 // Try and fetch the locale from the carrier properties or from the SIM language
7375 // preferences (EF-PL and EF-LI)...
7376 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007377 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007378 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7379 if (localeFromDefaultSim != null) {
7380 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7381 if (DBG) log("Using locale from subId: " + subId + " locale: "
7382 + localeFromDefaultSim);
7383 return localeFromDefaultSim.toLanguageTag();
7384 } else {
7385 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386 }
7387 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 // The SIM language preferences only store a language (e.g. fr = French), not an
7390 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7391 // the SIM and carrier preferences does not include a country we add the country
7392 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007393 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007394 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007395 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 return mccLocale.toLanguageTag();
7397 }
7398
7399 if (DBG) log("No locale found - returning null");
7400 return null;
7401 } finally {
7402 Binder.restoreCallingIdentity(identity);
7403 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007404 }
7405
7406 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007407 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007408 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007409 }
7410
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 /**
7412 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7413 */
7414 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007415 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007416 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007417 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007418
Chenjie Yu1ba97252018-01-11 18:16:20 -08007419 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007420 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007421
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007422 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007423 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7424 * representing the state of the modem.
7425 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007426 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7427 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007428 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007429 */
7430 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007431 public void requestModemActivityInfo(ResultReceiver result) {
7432 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007433 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434
7435 final long identity = Binder.clearCallingIdentity();
7436 try {
sqian1a1be542020-03-05 11:37:28 -08007437 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 } finally {
7439 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007440 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007441 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007442
Siddharth Rayb8114062018-06-17 15:02:38 -07007443 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7444 // less than total activity duration.
7445 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7446 if (info == null) {
7447 return false;
7448 }
7449 int activityDurationMs =
7450 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7451 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007452 int[] txTimeMs = info.getTransmitTimeMillis();
7453 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7454 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007455 }
7456 return (info.isValid()
7457 && (info.getSleepTimeMillis() <= activityDurationMs)
7458 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007459 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007460 && (totalTxTimeMs <= activityDurationMs));
7461 }
7462
Jack Yu85bd38a2015-11-09 11:34:32 -08007463 /**
7464 * {@hide}
7465 * Returns the service state information on specified subscription.
7466 */
7467 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007468 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7469 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007470 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007471 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007472 return null;
7473 }
7474
Hall Liuf19c44f2018-11-27 14:38:17 -08007475 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7476 LocationAccessPolicy.checkLocationPermission(mApp,
7477 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7478 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007479 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007480 .setCallingPid(Binder.getCallingPid())
7481 .setCallingUid(Binder.getCallingUid())
7482 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007483 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007484 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007485 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7486 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007487 .build());
7488
7489 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7490 LocationAccessPolicy.checkLocationPermission(mApp,
7491 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7492 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007493 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007494 .setCallingPid(Binder.getCallingPid())
7495 .setCallingUid(Binder.getCallingUid())
7496 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007497 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007498 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007499 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7500 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007501 .build());
7502 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7503 boolean hasFinePermission =
7504 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7505 boolean hasCoarsePermission =
7506 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 final long identity = Binder.clearCallingIdentity();
7509 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007510 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7511 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7512 Rlog.d(LOG_TAG,
7513 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7514 return null;
7515 }
7516
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 final Phone phone = getPhone(subId);
7518 if (phone == null) {
7519 return null;
7520 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007521
Hall Liuf19c44f2018-11-27 14:38:17 -08007522 ServiceState ss = phone.getServiceState();
7523
7524 // Scrub out the location info in ServiceState depending on what level of access
7525 // the caller has.
7526 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007527 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7528 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 } finally {
7530 Binder.restoreCallingIdentity(identity);
7531 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007532 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007533
7534 /**
7535 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7536 *
7537 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7538 * voicemail ringtone.
7539 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7540 * PhoneAccount.
7541 */
7542 @Override
7543 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7547 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007548 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007551 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
7554 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007555 }
7556
7557 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007558 * Sets the per-account voicemail ringtone.
7559 *
7560 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7561 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7562 *
7563 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7564 * voicemail ringtone.
7565 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7566 * PhoneAccount.
7567 */
7568 @Override
7569 public void setVoicemailRingtoneUri(String callingPackage,
7570 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007571 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007572 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007573 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7574 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7576 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7577 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579
7580 final long identity = Binder.clearCallingIdentity();
7581 try {
7582 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7583 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007584 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 }
7586 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7587 } finally {
7588 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007589 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007590 }
7591
7592 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007593 * Returns whether vibration is set for voicemail notification in Phone settings.
7594 *
7595 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7596 * voicemail vibration setting.
7597 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7598 */
7599 @Override
7600 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7604 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007605 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007606 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007608 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7609 } finally {
7610 Binder.restoreCallingIdentity(identity);
7611 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007612 }
7613
Youhan Wange64578a2016-05-02 15:32:42 -07007614 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007615 * Sets the per-account voicemail vibration.
7616 *
7617 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7618 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7619 *
7620 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7621 * voicemail vibration setting.
7622 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7623 * specific PhoneAccount.
7624 */
7625 @Override
7626 public void setVoicemailVibrationEnabled(String callingPackage,
7627 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007628 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007629 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007630 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7631 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7633 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7634 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007635 }
7636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007637 final long identity = Binder.clearCallingIdentity();
7638 try {
7639 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7640 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007641 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007642 }
7643 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7644 } finally {
7645 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007646 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007647 }
7648
7649 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007650 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7651 *
7652 * @throws SecurityException if the caller does not have the required permission
7653 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007654 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007655 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007656 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007657 }
7658
7659 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007660 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7661 * permission.
7662 *
7663 * @throws SecurityException if the caller does not have the required permission
7664 */
7665 private void enforceSendSmsPermission() {
7666 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7667 }
7668
7669 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007670 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007671 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007672 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007673 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007674 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 final long identity = Binder.clearCallingIdentity();
7676 try {
7677 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007678 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 if (componentName == null) {
7680 throw new SecurityException(
7681 "Caller not current active visual voicemail package[null]");
7682 }
7683 String vvmPackage = componentName.getPackageName();
7684 if (!callingPackage.equals(vvmPackage)) {
7685 throw new SecurityException("Caller not current active visual voicemail package["
7686 + vvmPackage + "]");
7687 }
7688 } finally {
7689 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007690 }
7691 }
7692
7693 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007694 * Return the application ID for the app type.
7695 *
7696 * @param subId the subscription ID that this request applies to.
7697 * @param appType the uicc app type.
7698 * @return Application ID for specificied app type, or null if no uicc.
7699 */
7700 @Override
7701 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007702 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007703 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007704
7705 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007706 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707 if (phone == null) {
7708 return null;
7709 }
7710 String aid = null;
7711 try {
7712 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7713 .getApplicationByType(appType).getAid();
7714 } catch (Exception e) {
7715 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7716 }
7717 return aid;
7718 } finally {
7719 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007720 }
Youhan Wange64578a2016-05-02 15:32:42 -07007721 }
7722
Youhan Wang4001d252016-05-11 10:29:41 -07007723 /**
7724 * Return the Electronic Serial Number.
7725 *
7726 * @param subId the subscription ID that this request applies to.
7727 * @return ESN or null if error.
7728 */
7729 @Override
7730 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007731 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007732 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007733
7734 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007735 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007736 if (phone == null) {
7737 return null;
7738 }
7739 String esn = null;
7740 try {
7741 esn = phone.getEsn();
7742 } catch (Exception e) {
7743 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7744 }
7745 return esn;
7746 } finally {
7747 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007748 }
Youhan Wang4001d252016-05-11 10:29:41 -07007749 }
7750
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007751 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007752 * Return the Preferred Roaming List Version.
7753 *
7754 * @param subId the subscription ID that this request applies to.
7755 * @return PRLVersion or null if error.
7756 */
7757 @Override
7758 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007759 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007760 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761
7762 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007763 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 if (phone == null) {
7765 return null;
7766 }
7767 String cdmaPrlVersion = null;
7768 try {
7769 cdmaPrlVersion = phone.getCdmaPrlVersion();
7770 } catch (Exception e) {
7771 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7772 }
7773 return cdmaPrlVersion;
7774 } finally {
7775 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007776 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007777 }
7778
7779 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007780 * Get snapshot of Telephony histograms
7781 * @return List of Telephony histograms
7782 * @hide
7783 */
7784 @Override
7785 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7787 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788
7789 final long identity = Binder.clearCallingIdentity();
7790 try {
7791 return RIL.getTelephonyRILTimingHistograms();
7792 } finally {
7793 Binder.restoreCallingIdentity(identity);
7794 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007795 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007796
7797 /**
7798 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007799 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7800 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007801 * Require system privileges. In the future we may add this to carrier APIs.
7802 *
Michele Berionne482f8202018-11-27 18:57:59 -08007803 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007804 */
7805 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007806 @TelephonyManager.SetCarrierRestrictionResult
7807 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007808 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007809 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007810
Michele Berionne482f8202018-11-27 18:57:59 -08007811 if (carrierRestrictionRules == null) {
7812 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007813 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 final long identity = Binder.clearCallingIdentity();
7816 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007817 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007818 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 } finally {
7820 Binder.restoreCallingIdentity(identity);
7821 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007822 }
7823
7824 /**
7825 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007826 * Get the allowed carrier list and the excluded carrier list, including the priority between
7827 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007828 * Require system privileges. In the future we may add this to carrier APIs.
7829 *
Michele Berionne482f8202018-11-27 18:57:59 -08007830 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007831 */
7832 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007833 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007834 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007835 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836
7837 final long identity = Binder.clearCallingIdentity();
7838 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007839 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7840 if (response instanceof CarrierRestrictionRules) {
7841 return (CarrierRestrictionRules) response;
7842 }
7843 // Response is an Exception of some kind,
7844 // which is signalled to the user as a NULL retval
7845 return null;
7846 } catch (Exception e) {
7847 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7848 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007849 } finally {
7850 Binder.restoreCallingIdentity(identity);
7851 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007852 }
7853
fionaxu59545b42016-05-25 15:53:37 -07007854 /**
fionaxu59545b42016-05-25 15:53:37 -07007855 * Action set from carrier signalling broadcast receivers to enable/disable radio
7856 * @param subId the subscription ID that this action applies to.
7857 * @param enabled control enable or disable radio.
7858 * {@hide}
7859 */
7860 @Override
7861 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7862 enforceModifyPermission();
7863 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864
7865 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007866 if (phone == null) {
7867 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7868 return;
7869 }
7870 try {
7871 phone.carrierActionSetRadioEnabled(enabled);
7872 } catch (Exception e) {
7873 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874 } finally {
7875 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007876 }
7877 }
7878
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007879 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007880 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7881 * network status based on which carrier apps could apply actions accordingly,
7882 * enable/disable default url handler for example.
7883 *
7884 * @param subId the subscription ID that this action applies to.
7885 * @param report control start/stop reporting the default network status.
7886 * {@hide}
7887 */
7888 @Override
7889 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7890 enforceModifyPermission();
7891 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007892
7893 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007894 if (phone == null) {
7895 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7896 return;
7897 }
7898 try {
7899 phone.carrierActionReportDefaultNetworkStatus(report);
7900 } catch (Exception e) {
7901 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007902 } finally {
7903 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007904 }
7905 }
7906
7907 /**
fionaxud9622282017-07-17 17:51:30 -07007908 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7909 * @param subId the subscription ID that this action applies to.
7910 * {@hide}
7911 */
7912 @Override
7913 public void carrierActionResetAll(int subId) {
7914 enforceModifyPermission();
7915 final Phone phone = getPhone(subId);
7916 if (phone == null) {
7917 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7918 return;
7919 }
7920 try {
7921 phone.carrierActionResetAll();
7922 } catch (Exception e) {
7923 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7924 }
7925 }
7926
7927 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007928 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7929 * bug report is being generated.
7930 */
7931 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007932 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007933 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7934 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007935 writer.println("Permission Denial: can't dump Phone from pid="
7936 + Binder.getCallingPid()
7937 + ", uid=" + Binder.getCallingUid()
7938 + "without permission "
7939 + android.Manifest.permission.DUMP);
7940 return;
7941 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007942 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007943 }
Jack Yueb89b242016-06-22 13:27:47 -07007944
Brad Ebingerdac2f002018-04-03 15:17:52 -07007945 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007946 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7947 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7948 @NonNull String[] args) {
7949 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7950 this, in.getFileDescriptor(), out.getFileDescriptor(),
7951 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007952 }
7953
Jack Yueb89b242016-06-22 13:27:47 -07007954 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007955 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007956 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007957 * @param reason the reason the data enable change is taking place
7958 * @param enabled True if enabling the data, otherwise disabling.
7959 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007960 */
7961 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007962 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007963 boolean enabled) {
7964 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7965 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7966 try {
7967 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007968 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007969 } catch (SecurityException se) {
7970 enforceModifyPermission();
7971 }
7972 } else {
7973 enforceModifyPermission();
7974 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007975
7976 final long identity = Binder.clearCallingIdentity();
7977 try {
7978 Phone phone = getPhone(subId);
7979 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007980 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7981 phone.carrierActionSetMeteredApnsEnabled(enabled);
7982 } else {
7983 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985 }
7986 } finally {
7987 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007988 }
7989 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007990
7991 /**
7992 * Get Client request stats
7993 * @return List of Client Request Stats
7994 * @hide
7995 */
7996 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007997 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7998 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008000 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008001 return null;
8002 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008003 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008005 final long identity = Binder.clearCallingIdentity();
8006 try {
8007 if (phone != null) {
8008 return phone.getClientRequestStats();
8009 }
8010
8011 return null;
8012 } finally {
8013 Binder.restoreCallingIdentity(identity);
8014 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008015 }
8016
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008017 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008018 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008019 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008020 }
Jack Yueb4124c2017-02-16 15:32:43 -08008021
8022 /**
Grace Chen70990072017-03-24 17:21:30 -07008023 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008024 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008025 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008026 * @param state State of SIM (power down, power up, pass through)
8027 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8028 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8029 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008030 *
8031 **/
8032 @Override
Grace Chen70990072017-03-24 17:21:30 -07008033 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008034 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008035 Phone phone = PhoneFactory.getPhone(slotIndex);
8036
vagdeviaf9a5b92018-08-15 16:01:53 -07008037 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008039 final long identity = Binder.clearCallingIdentity();
8040 try {
8041 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008042 phone.setSimPowerState(state, null, workSource);
8043 }
8044 } finally {
8045 Binder.restoreCallingIdentity(identity);
8046 }
8047 }
8048
8049 /**
8050 * Set SIM card power state.
8051 *
8052 * @param slotIndex SIM slot id.
8053 * @param state State of SIM (power down, power up, pass through)
8054 * @param callback callback to trigger after success or failure
8055 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8056 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8057 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8058 *
8059 **/
8060 @Override
8061 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8062 IIntegerConsumer callback) {
8063 enforceModifyPermission();
8064 Phone phone = PhoneFactory.getPhone(slotIndex);
8065
8066 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8067
8068 final long identity = Binder.clearCallingIdentity();
8069 try {
8070 if (phone != null) {
8071 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8072 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008073 }
8074 } finally {
8075 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008076 }
8077 }
Shuo Qiandd210312017-04-12 22:11:33 +00008078
Tyler Gunn65d45c22017-06-05 11:22:26 -07008079 private boolean isUssdApiAllowed(int subId) {
8080 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008081 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008082 if (configManager == null) {
8083 return false;
8084 }
8085 PersistableBundle pb = configManager.getConfigForSubId(subId);
8086 if (pb == null) {
8087 return false;
8088 }
8089 return pb.getBoolean(
8090 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8091 }
8092
Shuo Qiandd210312017-04-12 22:11:33 +00008093 /**
8094 * Check if phone is in emergency callback mode
8095 * @return true if phone is in emergency callback mode
8096 * @param subId sub id
8097 */
goneil9c5f4872017-12-05 14:07:56 -08008098 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008099 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008100 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008101 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008102
8103 final long identity = Binder.clearCallingIdentity();
8104 try {
8105 if (phone != null) {
8106 return phone.isInEcm();
8107 } else {
8108 return false;
8109 }
8110 } finally {
8111 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008112 }
8113 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008114
8115 /**
8116 * Get the current signal strength information for the given subscription.
8117 * Because this information is not updated when the device is in a low power state
8118 * it should not be relied-upon to be current.
8119 * @param subId Subscription index
8120 * @return the most recent cached signal strength info from the modem
8121 */
8122 @Override
8123 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008124 final long identity = Binder.clearCallingIdentity();
8125 try {
8126 Phone p = getPhone(subId);
8127 if (p == null) {
8128 return null;
8129 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008131 return p.getSignalStrength();
8132 } finally {
8133 Binder.restoreCallingIdentity(identity);
8134 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008135 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008136
Pengquan Meng77b7f132018-08-22 14:49:57 -07008137 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008138 * Get the current modem radio state for the given slot.
8139 * @param slotIndex slot index.
8140 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008141 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008142 * @return the current radio power state from the modem
8143 */
8144 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008145 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008146 Phone phone = PhoneFactory.getPhone(slotIndex);
8147 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8149 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008150 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8151 }
8152
8153 final long identity = Binder.clearCallingIdentity();
8154 try {
8155 return phone.getRadioPowerState();
8156 } finally {
8157 Binder.restoreCallingIdentity(identity);
8158 }
8159 }
8160 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8161 }
8162
8163 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008164 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8165 *
8166 * <p>Requires one of the following permissions:
8167 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8168 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8169 * privileges.
8170 *
8171 * @param subId subscription id
8172 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8173 * {@code false}.
8174 */
8175 @Override
8176 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008177 try {
8178 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8179 null);
8180 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008181 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008182 mApp, subId, "isDataRoamingEnabled");
8183 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008184
Pengquan Menga1bb6272018-09-06 09:59:22 -07008185 boolean isEnabled = false;
8186 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008187 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008188 Phone phone = getPhone(subId);
8189 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008190 } finally {
8191 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008192 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008193 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008194 }
8195
8196
8197 /**
8198 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8199 *
8200 * <p> Requires permission:
8201 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8202 * privileges.
8203 *
8204 * @param subId subscription id
8205 * @param isEnabled {@code true} means enable, {@code false} means disable.
8206 */
8207 @Override
8208 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8210 mApp, subId, "setDataRoamingEnabled");
8211
Pengquan Menga1bb6272018-09-06 09:59:22 -07008212 final long identity = Binder.clearCallingIdentity();
8213 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008214 Phone phone = getPhone(subId);
8215 if (phone != null) {
8216 phone.setDataRoamingEnabled(isEnabled);
8217 }
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008220 }
8221 }
8222
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008223 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008224 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008225 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008226 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008227 mApp, subId, "isManualNetworkSelectionAllowed");
8228
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008229 boolean isAllowed = true;
8230 final long identity = Binder.clearCallingIdentity();
8231 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008232 Phone phone = getPhone(subId);
8233 if (phone != null) {
8234 isAllowed = phone.isCspPlmnEnabled();
8235 }
8236 } finally {
8237 Binder.restoreCallingIdentity(identity);
8238 }
8239 return isAllowed;
8240 }
8241
8242 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008243 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008244 // Verify that tha callingPackage belongs to the calling UID
8245 mApp.getSystemService(AppOpsManager.class)
8246 .checkPackage(Binder.getCallingUid(), callingPackage);
8247
Jordan Liu1e142fc2019-04-22 15:10:43 -07008248 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008249 try {
8250 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008251 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008252 } catch (SecurityException e) {
8253 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8254 // has carrier privileges on an active UICC
8255 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8256 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008257 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008258 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008259 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008260
8261 final long identity = Binder.clearCallingIdentity();
8262 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008263 UiccController uiccController = UiccController.getInstance();
8264 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008265 if (hasReadPermission) {
8266 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008267 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008268
8269 // Remove private info if the caller doesn't have access
8270 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8271 for (UiccCardInfo cardInfo : cardInfos) {
8272 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8273 // is available
8274 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8275 if (card == null || card.getUiccProfile() == null) {
8276 // assume no access if the card or profile is unavailable
8277 filteredInfos.add(cardInfo.getUnprivileged());
8278 continue;
8279 }
8280 UiccProfile profile = card.getUiccProfile();
8281 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8282 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8283 filteredInfos.add(cardInfo);
8284 } else {
8285 filteredInfos.add(cardInfo.getUnprivileged());
8286 }
8287 }
8288 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008289 } finally {
8290 Binder.restoreCallingIdentity(identity);
8291 }
8292 }
8293
8294 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008295 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008296 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8301 if (slots == null) {
8302 Rlog.i(LOG_TAG, "slots is null.");
8303 return null;
8304 }
8305
8306 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8307 for (int i = 0; i < slots.length; i++) {
8308 UiccSlot slot = slots[i];
8309 if (slot == null) {
8310 continue;
8311 }
8312
Jordan Liu7be7e652019-05-06 18:55:02 +00008313 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008314 UiccCard card = slot.getUiccCard();
8315 if (card != null) {
8316 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008317 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008318 cardId = slot.getEid();
8319 if (TextUtils.isEmpty(cardId)) {
8320 cardId = slot.getIccId();
8321 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 }
8323
Jordan Liu857451f2019-05-09 16:35:35 -07008324 if (cardId != null) {
8325 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8326 // if cardId is an EID, it's all digits so this is fine
8327 cardId = IccUtils.stripTrailingFs(cardId);
8328 }
8329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 int cardState = 0;
8331 switch (slot.getCardState()) {
8332 case CARDSTATE_ABSENT:
8333 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8334 break;
8335 case CARDSTATE_PRESENT:
8336 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8337 break;
8338 case CARDSTATE_ERROR:
8339 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8340 break;
8341 case CARDSTATE_RESTRICTED:
8342 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8343 break;
8344 default:
8345 break;
8346
8347 }
8348
8349 infos[i] = new UiccSlotInfo(
8350 slot.isActive(),
8351 slot.isEuicc(),
8352 cardId,
8353 cardState,
8354 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008355 slot.isExtendedApduSupported(),
8356 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008357 }
8358 return infos;
8359 } finally {
8360 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008361 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008362 }
8363
8364 @Override
8365 public boolean switchSlots(int[] physicalSlots) {
8366 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367
8368 final long identity = Binder.clearCallingIdentity();
8369 try {
8370 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8371 } finally {
8372 Binder.restoreCallingIdentity(identity);
8373 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008374 }
Jack Yu4c988042018-02-27 15:30:01 -08008375
8376 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008377 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008378 final long identity = Binder.clearCallingIdentity();
8379 try {
8380 return UiccController.getInstance().getCardIdForDefaultEuicc();
8381 } finally {
8382 Binder.restoreCallingIdentity(identity);
8383 }
8384 }
8385
Pengquan Meng85728fb2018-03-12 16:31:21 -07008386 /**
goneil47ffb6e2018-04-06 15:40:58 -07008387 * A test API to reload the UICC profile.
8388 *
8389 * <p>Requires that the calling app has permission
8390 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8391 * @hide
8392 */
8393 @Override
8394 public void refreshUiccProfile(int subId) {
8395 enforceModifyPermission();
8396
8397 final long identity = Binder.clearCallingIdentity();
8398 try {
8399 Phone phone = getPhone(subId);
8400 if (phone == null) {
8401 return;
8402 }
8403 UiccCard uiccCard = phone.getUiccCard();
8404 if (uiccCard == null) {
8405 return;
8406 }
8407 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8408 if (uiccProfile == null) {
8409 return;
8410 }
8411 uiccProfile.refresh();
8412 } finally {
8413 Binder.restoreCallingIdentity(identity);
8414 }
8415 }
8416
8417 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008418 * Returns false if the mobile data is disabled by default, otherwise return true.
8419 */
8420 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008421 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008422 }
8423
8424 /**
8425 * Returns true if the data roaming is enabled by default, i.e the system property
8426 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8427 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8428 */
8429 private boolean getDefaultDataRoamingEnabled(int subId) {
8430 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008431 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008432 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008433 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8434 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8435 return isDataRoamingEnabled;
8436 }
8437
8438 /**
8439 * Returns the default network type for the given {@code subId}, if the default network type is
8440 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8441 */
8442 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008443 List<Integer> list = TelephonyProperties.default_network();
8444 int phoneId = mSubscriptionController.getPhoneId(subId);
8445 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8446 return list.get(phoneId);
8447 }
8448 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008449 }
fionaxua13278b2018-03-21 00:08:13 -07008450
8451 @Override
8452 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008453 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008454 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008455
8456 final long identity = Binder.clearCallingIdentity();
8457 try {
8458 final Phone phone = getPhone(subId);
8459 if (phone == null) {
8460 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8461 return;
8462 }
chen xueaba88a2019-03-15 13:15:10 -07008463 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8464 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008465 if (carrierPrivilegeRules == null) {
8466 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8467 } else {
8468 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470 } finally {
8471 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008472 }
fionaxua13278b2018-03-21 00:08:13 -07008473 }
8474
8475 @Override
8476 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008477 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008478
8479 final long identity = Binder.clearCallingIdentity();
8480 try {
8481 final Phone phone = getPhone(subId);
8482 if (phone == null) {
8483 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8484 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8485 }
8486 return phone.getCarrierIdListVersion();
8487 } finally {
8488 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008489 }
fionaxua13278b2018-03-21 00:08:13 -07008490 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008491
8492 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008493 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8494 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008496 mApp, subId, callingPackage, callingFeatureId,
8497 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008498 return -1;
8499 }
8500
8501 final long identity = Binder.clearCallingIdentity();
8502 try {
8503 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8504 } finally {
8505 Binder.restoreCallingIdentity(identity);
8506 }
8507 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008508
8509 @Override
8510 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008511 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008512 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008513 mApp, subId, "getCdmaRoamingMode");
8514
8515 final long identity = Binder.clearCallingIdentity();
8516 try {
8517 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8518 } finally {
8519 Binder.restoreCallingIdentity(identity);
8520 }
8521 }
8522
8523 @Override
8524 public boolean setCdmaRoamingMode(int subId, int mode) {
8525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8526 mApp, subId, "setCdmaRoamingMode");
8527
8528 final long identity = Binder.clearCallingIdentity();
8529 try {
8530 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8531 } finally {
8532 Binder.restoreCallingIdentity(identity);
8533 }
8534 }
8535
8536 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008537 public int getCdmaSubscriptionMode(int subId) {
8538 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008539 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008540 mApp, subId, "getCdmaSubscriptionMode");
8541
8542 final long identity = Binder.clearCallingIdentity();
8543 try {
8544 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8545 } finally {
8546 Binder.restoreCallingIdentity(identity);
8547 }
8548 }
8549
8550 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008551 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8553 mApp, subId, "setCdmaSubscriptionMode");
8554
8555 final long identity = Binder.clearCallingIdentity();
8556 try {
8557 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8558 } finally {
8559 Binder.restoreCallingIdentity(identity);
8560 }
8561 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008562
sqianc5eccab2018-10-19 18:46:41 -07008563 @Override
sqian8c685422019-02-22 15:55:18 -08008564 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008565 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008567 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8568 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008569 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8570 }
8571 final long identity = Binder.clearCallingIdentity();
8572 try {
sqian854d44b2018-12-12 16:48:18 -08008573 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8574 for (Phone phone: PhoneFactory.getPhones()) {
8575 if (phone.getEmergencyNumberTracker() != null
8576 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8577 emergencyNumberListInternal.put(
8578 phone.getSubId(),
8579 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8580 }
sqian11b7a0e2018-12-05 18:48:28 -08008581 }
sqian854d44b2018-12-12 16:48:18 -08008582 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008583 } finally {
8584 Binder.restoreCallingIdentity(identity);
8585 }
sqianc5eccab2018-10-19 18:46:41 -07008586 }
8587
8588 @Override
sqian8c685422019-02-22 15:55:18 -08008589 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008590 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008591 if (!exactMatch) {
8592 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008593 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008594 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008595 }
8596 final long identity = Binder.clearCallingIdentity();
8597 try {
sqian854d44b2018-12-12 16:48:18 -08008598 for (Phone phone: PhoneFactory.getPhones()) {
8599 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008600 && phone.getEmergencyNumberTracker()
8601 .isEmergencyNumber(number, exactMatch)) {
8602 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008603 }
sqian11b7a0e2018-12-05 18:48:28 -08008604 }
8605 return false;
8606 } finally {
8607 Binder.restoreCallingIdentity(identity);
8608 }
8609 }
8610
sqianf4ca7ed2019-01-15 18:32:07 -08008611 /**
Shuo Qian479dd9e2021-02-22 18:32:21 -08008612 * Start emergency callback mode for GsmCdmaPhone for testing.
8613 */
8614 @Override
8615 public void startEmergencyCallbackMode() {
8616 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8617 "startEmergencyCallbackMode");
8618 enforceModifyPermission();
8619 final long identity = Binder.clearCallingIdentity();
8620 try {
8621 for (Phone phone : PhoneFactory.getPhones()) {
8622 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8623 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8624 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8625 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8626 gsmCdmaPhone.obtainMessage(
8627 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8628 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8629 }
8630 }
8631 } finally {
8632 Binder.restoreCallingIdentity(identity);
8633 }
8634 }
8635
8636 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008637 * Update emergency number list for test mode.
8638 */
8639 @Override
8640 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8641 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8642 "updateEmergencyNumberListTestMode");
8643
8644 final long identity = Binder.clearCallingIdentity();
8645 try {
8646 for (Phone phone: PhoneFactory.getPhones()) {
8647 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8648 if (tracker != null) {
8649 tracker.executeEmergencyNumberTestModeCommand(action, num);
8650 }
8651 }
8652 } finally {
8653 Binder.restoreCallingIdentity(identity);
8654 }
8655 }
8656
8657 /**
8658 * Get the full emergency number list for test mode.
8659 */
8660 @Override
8661 public List<String> getEmergencyNumberListTestMode() {
8662 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8663 "getEmergencyNumberListTestMode");
8664
8665 final long identity = Binder.clearCallingIdentity();
8666 try {
8667 Set<String> emergencyNumbers = new HashSet<>();
8668 for (Phone phone: PhoneFactory.getPhones()) {
8669 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8670 if (tracker != null) {
8671 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8672 emergencyNumbers.add(num.getNumber());
8673 }
8674 }
8675 }
8676 return new ArrayList<>(emergencyNumbers);
8677 } finally {
8678 Binder.restoreCallingIdentity(identity);
8679 }
8680 }
8681
chen xud6b45bd2018-10-30 22:27:10 -07008682 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008683 public int getEmergencyNumberDbVersion(int subId) {
8684 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8685
8686 final long identity = Binder.clearCallingIdentity();
8687 try {
8688 final Phone phone = getPhone(subId);
8689 if (phone == null) {
8690 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8691 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8692 }
8693 return phone.getEmergencyNumberDbVersion();
8694 } finally {
8695 Binder.restoreCallingIdentity(identity);
8696 }
8697 }
8698
8699 @Override
8700 public void notifyOtaEmergencyNumberDbInstalled() {
8701 enforceModifyPermission();
8702
8703 final long identity = Binder.clearCallingIdentity();
8704 try {
8705 for (Phone phone: PhoneFactory.getPhones()) {
8706 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8707 if (tracker != null) {
8708 tracker.updateOtaEmergencyNumberDatabase();
8709 }
8710 }
8711 } finally {
8712 Binder.restoreCallingIdentity(identity);
8713 }
8714 }
8715
8716 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008717 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008718 enforceActiveEmergencySessionPermission();
8719
8720 final long identity = Binder.clearCallingIdentity();
8721 try {
8722 for (Phone phone: PhoneFactory.getPhones()) {
8723 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8724 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008725 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8726 }
8727 }
8728 } finally {
8729 Binder.restoreCallingIdentity(identity);
8730 }
8731 }
8732
8733 @Override
8734 public void resetOtaEmergencyNumberDbFilePath() {
8735 enforceActiveEmergencySessionPermission();
8736
8737 final long identity = Binder.clearCallingIdentity();
8738 try {
8739 for (Phone phone: PhoneFactory.getPhones()) {
8740 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8741 if (tracker != null) {
8742 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008743 }
8744 }
8745 } finally {
8746 Binder.restoreCallingIdentity(identity);
8747 }
8748 }
8749
8750 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008751 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8752 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8753 Phone phone = getPhone(subId);
8754 if (phone == null) {
8755 return null;
8756 }
8757 final long identity = Binder.clearCallingIdentity();
8758 try {
8759 UiccProfile profile = UiccController.getInstance()
8760 .getUiccProfileForPhone(phone.getPhoneId());
8761 if (profile != null) {
8762 return profile.getCertsFromCarrierPrivilegeAccessRules();
8763 }
8764 } finally {
8765 Binder.restoreCallingIdentity(identity);
8766 }
8767 return null;
8768 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008769
8770 /**
8771 * Enable or disable a modem stack.
8772 */
8773 @Override
8774 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8775 enforceModifyPermission();
8776
8777 final long identity = Binder.clearCallingIdentity();
8778 try {
8779 Phone phone = PhoneFactory.getPhone(slotIndex);
8780 if (phone == null) {
8781 return false;
8782 } else {
8783 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8784 }
8785 } finally {
8786 Binder.restoreCallingIdentity(identity);
8787 }
8788 }
Michelecea4cf22018-12-21 15:00:11 -08008789
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008790 /**
8791 * Whether a modem stack is enabled or not.
8792 */
8793 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008794 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8795 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008796 Phone phone = PhoneFactory.getPhone(slotIndex);
8797 if (phone == null) return false;
8798
8799 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008800 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8801 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008802 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8803 }
8804
8805 final long identity = Binder.clearCallingIdentity();
8806 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008807 try {
8808 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8809 } catch (NoSuchElementException ex) {
8810 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8811 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008812 } finally {
8813 Binder.restoreCallingIdentity(identity);
8814 }
8815 }
8816
Michelecea4cf22018-12-21 15:00:11 -08008817 @Override
Michele0ea7d782019-03-19 14:58:42 -07008818 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008819 enforceModifyPermission();
8820
8821 final long identity = Binder.clearCallingIdentity();
8822 try {
8823 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008824 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008825 .commit();
8826 } finally {
8827 Binder.restoreCallingIdentity(identity);
8828 }
8829 }
8830
8831 @Override
Michele0ea7d782019-03-19 14:58:42 -07008832 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008833 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008835 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8836 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008837 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008838 }
Michelecea4cf22018-12-21 15:00:11 -08008839
8840 final long identity = Binder.clearCallingIdentity();
8841 try {
Michele0ea7d782019-03-19 14:58:42 -07008842 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008843 } finally {
8844 Binder.restoreCallingIdentity(identity);
8845 }
8846 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008847
Michele0ea7d782019-03-19 14:58:42 -07008848 @TelephonyManager.IsMultiSimSupportedResult
8849 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008850 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8851 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8852 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008853 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8854 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008855 }
8856 // Check if the hardware supports multisim functionality. If usage of multisim is not
8857 // supported by the modem, indicate that it is restricted.
8858 PhoneCapability staticCapability =
8859 mPhoneConfigurationManager.getStaticPhoneCapability();
8860 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008861 loge("isMultiSimSupportedInternal: no static configuration available");
8862 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008863 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008864 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008865 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8866 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008867 }
8868 // Check if support of multiple SIMs is restricted by carrier
8869 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008870 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008871 }
8872
Michele0ea7d782019-03-19 14:58:42 -07008873 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008874 }
8875
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008876 /**
8877 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008878 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8879 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8880 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008881 * @param numOfSims number of active sims we want to switch to
8882 */
8883 @Override
8884 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008885 if (numOfSims == 1) {
8886 enforceModifyPermission();
8887 } else {
8888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8889 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8890 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008891 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008892
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008893 try {
Michele30b57b22019-03-01 12:01:14 -08008894 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008895 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008896 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8897 return;
8898 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008899 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8900 } finally {
8901 Binder.restoreCallingIdentity(identity);
8902 }
8903 }
8904
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008905 @Override
8906 public boolean isApplicationOnUicc(int subId, int appType) {
8907 enforceReadPrivilegedPermission("isApplicationOnUicc");
8908 Phone phone = getPhone(subId);
8909 if (phone == null) {
8910 return false;
8911 }
8912 final long identity = Binder.clearCallingIdentity();
8913 try {
8914 UiccCard uiccCard = phone.getUiccCard();
8915 if (uiccCard == null) {
8916 return false;
8917 }
8918 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8919 if (uiccProfile == null) {
8920 return false;
8921 }
8922 if (TelephonyManager.APPTYPE_SIM <= appType
8923 && appType <= TelephonyManager.APPTYPE_ISIM) {
8924 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8925 }
8926 return false;
8927 } finally {
8928 Binder.restoreCallingIdentity(identity);
8929 }
8930 }
8931
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008932 /**
chen xub4baa772019-04-03 10:23:41 -07008933 * Get whether making changes to modem configurations will trigger reboot.
8934 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008935 */
8936 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008937 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8938 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008939 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008940 mApp, subId, callingPackage, callingFeatureId,
8941 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008942 return false;
8943 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008944 final long identity = Binder.clearCallingIdentity();
8945 try {
8946 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8947 } finally {
8948 Binder.restoreCallingIdentity(identity);
8949 }
8950 }
8951
Nathan Harold29f5f052019-02-15 13:41:57 -08008952 private void updateModemStateMetrics() {
8953 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8954 // TODO: check the state for each modem if the api is ready.
8955 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8956 }
8957
Pengquan Meng3889a572019-01-23 11:16:29 -08008958 @Override
8959 public int[] getSlotsMapping() {
8960 enforceReadPrivilegedPermission("getSlotsMapping");
8961
8962 final long identity = Binder.clearCallingIdentity();
8963 try {
8964 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8965 // All logical slots should have a mapping to a physical slot.
8966 int[] logicalSlotsMapping = new int[phoneCount];
8967 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8968 for (int i = 0; i < slotInfos.length; i++) {
8969 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8970 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8971 }
8972 }
8973 return logicalSlotsMapping;
8974 } finally {
8975 Binder.restoreCallingIdentity(identity);
8976 }
8977 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008978
8979 /**
8980 * Get the IRadio HAL Version
8981 */
8982 @Override
8983 public int getRadioHalVersion() {
8984 Phone phone = getDefaultPhone();
8985 if (phone == null) return -1;
8986 HalVersion hv = phone.getHalVersion();
8987 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8988 return hv.major * 100 + hv.minor;
8989 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008990
8991 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008992 * Get the current calling package name.
8993 * @return the current calling package name
8994 */
8995 @Override
8996 public String getCurrentPackageName() {
8997 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8998 }
8999
9000 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009001 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9002 * corresponding network requests on a subId.
9003 *
9004 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009005 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009006 * 2) APN is un-metered for this subscription, or
9007 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07009008 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009009 *
9010 * @return whether data is allowed for a apn type.
9011 *
9012 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009013 */
9014 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009015 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009016 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9017 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009018
9019 // Now that all security checks passes, perform the operation as ourselves.
9020 final long identity = Binder.clearCallingIdentity();
9021 try {
9022 Phone phone = getPhone(subId);
9023 if (phone == null) return false;
9024
Jack Yu41407ee2019-05-13 16:54:09 -07009025 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009026 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9027 } finally {
9028 Binder.restoreCallingIdentity(identity);
9029 }
9030 }
9031
9032 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009033 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009034 enforceReadPrivilegedPermission("isApnMetered");
9035
9036 // Now that all security checks passes, perform the operation as ourselves.
9037 final long identity = Binder.clearCallingIdentity();
9038 try {
9039 Phone phone = getPhone(subId);
9040 if (phone == null) return true; // By default return true.
9041
Jack Yu41407ee2019-05-13 16:54:09 -07009042 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009043 } finally {
9044 Binder.restoreCallingIdentity(identity);
9045 }
9046 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009047
9048 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009049 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9050 int subscriptionId, IBooleanConsumer resultCallback) {
9051 enforceModifyPermission();
9052 long token = Binder.clearCallingIdentity();
9053 try {
9054 Phone phone = getPhone(subscriptionId);
9055 if (phone == null) {
9056 try {
9057 if (resultCallback != null) {
9058 resultCallback.accept(false);
9059 }
9060 } catch (RemoteException e) {
9061 // ignore
9062 }
9063 return;
9064 }
9065 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9066 Pair.create(specifiers, (x) -> {
9067 try {
9068 if (resultCallback != null) {
9069 resultCallback.accept(x);
9070 }
9071 } catch (RemoteException e) {
9072 // ignore
9073 }
9074 });
9075 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9076 } finally {
9077 Binder.restoreCallingIdentity(token);
9078 }
9079 }
9080
9081 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009082 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9083 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07009084 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08009085 mApp, subId, "getSystemSelectionChannels");
9086 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9087 final long identity = Binder.clearCallingIdentity();
9088 try {
Sarah Chin58691872021-03-13 03:17:40 -08009089 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9090 if (result instanceof IllegalStateException) {
9091 throw (IllegalStateException) result;
9092 }
9093 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chincc055732020-11-18 13:39:35 -08009094 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9095 return specifiers;
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 }
9100
9101 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009102 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009103 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009104 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9105 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9106 if (iccRecords == null) {
9107 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9108 return false;
9109 }
9110 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9111 }
9112
9113 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009114 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9115 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009116 if (callingPackage == null) {
9117 callingPackage = getCurrentPackageName();
9118 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009119 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9120 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009121 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9122 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009123 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9124 }
9125 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9126 Intent intent = new Intent();
9127 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9128 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9129 // Bring up choose default SMS subscription dialog right now
9130 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9131 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9132 mApp.startActivity(intent);
9133 }
chen xud5ca2d52019-05-28 15:20:57 -07009134
9135 @Override
9136 public String getMmsUAProfUrl(int subId) {
9137 //TODO investigate if this API should require proper permission check in R b/133791609
9138 final long identity = Binder.clearCallingIdentity();
9139 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009140 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9141 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9142 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9143 return carrierUAProfUrl;
9144 }
chen xud5ca2d52019-05-28 15:20:57 -07009145 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9146 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9147 } finally {
9148 Binder.restoreCallingIdentity(identity);
9149 }
9150 }
9151
9152 @Override
9153 public String getMmsUserAgent(int subId) {
9154 //TODO investigate if this API should require proper permission check in R b/133791609
9155 final long identity = Binder.clearCallingIdentity();
9156 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009157 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9158 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9159 if (!TextUtils.isEmpty(carrierUserAgent)) {
9160 return carrierUserAgent;
9161 }
chen xud5ca2d52019-05-28 15:20:57 -07009162 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9163 .getString(com.android.internal.R.string.config_mms_user_agent);
9164 } finally {
9165 Binder.restoreCallingIdentity(identity);
9166 }
9167 }
Jack Yub07d4972019-05-28 16:12:25 -07009168
9169 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009170 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9171 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9172
9173 final long identity = Binder.clearCallingIdentity();
9174 try {
9175 Phone phone = getPhone(subscriptionId);
9176 if (phone == null) return false;
9177
9178 switch (policy) {
9179 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9180 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9181 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9182 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9183 default:
9184 throw new IllegalArgumentException(policy + " is not a valid policy");
9185 }
9186 } finally {
9187 Binder.restoreCallingIdentity(identity);
9188 }
9189 }
9190
9191 @Override
9192 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9193 boolean enabled) {
9194 enforceModifyPermission();
9195
9196 final long identity = Binder.clearCallingIdentity();
9197 try {
9198 Phone phone = getPhone(subscriptionId);
9199 if (phone == null) return;
9200
9201 switch (policy) {
9202 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9203 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9204 break;
9205 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9206 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9207 break;
9208 default:
9209 throw new IllegalArgumentException(policy + " is not a valid policy");
9210 }
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
9214 }
9215
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009216 /**
Hall Liub48cf452020-09-25 11:13:49 -07009217 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009218 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9219 * otherwise.
9220 */
9221 @Override
9222 public void setCepEnabled(boolean isCepEnabled) {
9223 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9224
9225 final long identity = Binder.clearCallingIdentity();
9226 try {
9227 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9228 for (Phone phone : PhoneFactory.getPhones()) {
9229 Phone defaultPhone = phone.getImsPhone();
9230 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9231 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9232 ImsPhoneCallTracker imsPhoneCallTracker =
9233 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9234 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9235 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9236 + imsPhone.getMsisdn());
9237 }
9238 }
9239 } finally {
9240 Binder.restoreCallingIdentity(identity);
9241 }
9242 }
allenwtsu46dcc572020-01-08 18:24:03 +08009243
9244 /**
9245 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9246 *
9247 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9248 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9249 * before being read.
9250 */
9251 @Override
9252 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9253 isCompressed) {
9254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9255 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009256 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9257 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9258 }
9259 if (!isImsAvailableOnDevice()) {
9260 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9261 "IMS not available on device.");
9262 }
9263
9264 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009265 try {
Hui Wang068ab862020-10-31 05:12:53 +00009266 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9267 } finally {
9268 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009269 }
9270 }
zoey chenf95ca592019-12-30 16:11:23 +08009271
9272 @Override
9273 public boolean isIccLockEnabled(int subId) {
9274 enforceReadPrivilegedPermission("isIccLockEnabled");
9275
9276 // Now that all security checks passes, perform the operation as ourselves.
9277 final long identity = Binder.clearCallingIdentity();
9278 try {
9279 Phone phone = getPhone(subId);
9280 if (phone != null && phone.getIccCard() != null) {
9281 return phone.getIccCard().getIccLockEnabled();
9282 } else {
9283 return false;
9284 }
9285 } finally {
9286 Binder.restoreCallingIdentity(identity);
9287 }
9288 }
9289
9290 /**
zoey chene02881a2019-12-30 16:11:23 +08009291 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009292 *
zoey chene02881a2019-12-30 16:11:23 +08009293 * @return an integer representing the status of IccLock enabled or disabled in the following
9294 * three cases:
9295 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9296 * successfully.
9297 * - Positive number and zero for remaining password attempts.
9298 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009299 *
9300 */
9301 @Override
9302 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9303 enforceModifyPermission();
9304
9305 Phone phone = getPhone(subId);
9306 if (phone == null) {
9307 return 0;
9308 }
9309 // Now that all security checks passes, perform the operation as ourselves.
9310 final long identity = Binder.clearCallingIdentity();
9311 try {
9312 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9313 new Pair<Boolean, String>(enabled, password), phone, null);
9314 return attemptsRemaining;
9315
9316 } catch (Exception e) {
9317 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 return 0;
9322 }
9323
9324 /**
9325 * Change the ICC password used in ICC pin lock.
9326 *
zoey chene02881a2019-12-30 16:11:23 +08009327 * @return an integer representing the status of IccLock changed in the following three cases:
9328 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9329 * - Positive number and zero for remaining password attempts.
9330 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009331 *
9332 */
9333 @Override
9334 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9335 enforceModifyPermission();
9336
9337 Phone phone = getPhone(subId);
9338 if (phone == null) {
9339 return 0;
9340 }
9341 // Now that all security checks passes, perform the operation as ourselves.
9342 final long identity = Binder.clearCallingIdentity();
9343 try {
9344 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9345 new Pair<String, String>(oldPassword, newPassword), phone, null);
9346 return attemptsRemaining;
9347
9348 } catch (Exception e) {
9349 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9350 } finally {
9351 Binder.restoreCallingIdentity(identity);
9352 }
9353 return 0;
9354 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009355
Peter Wangdafb9ac2020-01-15 14:13:38 -08009356 /**
9357 * Request for receiving user activity notification
9358 */
9359 @Override
9360 public void requestUserActivityNotification() {
9361 if (!mNotifyUserActivity.get()
9362 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9363 mNotifyUserActivity.set(true);
9364 }
9365 }
9366
9367 /**
9368 * Called when userActivity is signalled in the power manager.
9369 * This is safe to call from any thread, with any window manager locks held or not.
9370 */
9371 @Override
9372 public void userActivity() {
9373 // ***************************************
9374 // * Inherited from PhoneWindowManager *
9375 // ***************************************
9376 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9377 // WITH ITS LOCKS HELD.
9378 //
9379 // This code must be VERY careful about the locks
9380 // it acquires.
9381 // In fact, the current code acquires way too many,
9382 // and probably has lurking deadlocks.
9383
9384 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9385 throw new SecurityException("Only the OS may call notifyUserActivity()");
9386 }
9387
9388 if (mNotifyUserActivity.getAndSet(false)) {
9389 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9390 USER_ACTIVITY_NOTIFICATION_DELAY);
9391 }
9392 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009393
Malcolm Chen884180b2020-04-13 11:59:40 -07009394 @Override
9395 public boolean canConnectTo5GInDsdsMode() {
9396 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9397 }
Jack Yud10cdd42020-09-28 20:28:01 -07009398
9399 @Override
9400 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9401 String callingFeatureId) {
9402 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9403 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9404 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9405 }
9406
9407 Phone phone = getPhone(subId);
9408 if (phone == null) {
9409 throw new RuntimeException("phone is not available");
9410 }
9411 // Now that all security checks passes, perform the operation as ourselves.
9412 final long identity = Binder.clearCallingIdentity();
9413 try {
9414 return phone.getEquivalentHomePlmns();
9415 } finally {
9416 Binder.restoreCallingIdentity(identity);
9417 }
9418 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009419
Hui Wang0866fcc2020-10-12 12:14:23 -07009420 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009421 public boolean isRadioInterfaceCapabilitySupported(
9422 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009423 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009424 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009425 if (radioInterfaceCapabilities == null) {
9426 throw new RuntimeException("radio interface capabilities are not available");
9427 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009428 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009429 }
9430 }
9431
9432 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009433 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9434 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009435 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9436 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9437 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9438 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9439 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009440 if (DBG) {
9441 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9442 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9443 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9444 }
9445
9446 if (!SubscriptionManager.isValidSubscriptionId(subId)
9447 || appType < TelephonyManager.APPTYPE_UNKNOWN
9448 || appType > TelephonyManager.APPTYPE_ISIM
9449 || nafUrl == null || securityProtocol == null || callback == null) {
9450 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9451 if (callback != null) {
9452 try {
9453 callback.onAuthenticationFailure(
9454 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9455 } catch (RemoteException exception) {
9456 log("Fail to notify onAuthenticationFailure due to " + exception);
9457 }
9458 return;
9459 }
9460 }
9461
9462 final long token = Binder.clearCallingIdentity();
9463 try {
9464 getGbaManager(subId).bootstrapAuthenticationRequest(
9465 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9466 forceBootStrapping, callback));
9467 } finally {
9468 Binder.restoreCallingIdentity(token);
9469 }
9470 }
9471
Jack Nudelman24d51a52020-11-24 12:08:04 -08009472 /**
9473 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9474 * requested radio power state will actually be set. See {@link
9475 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9476 *
9477 * @param subId the subscription ID of the phone requesting to set the radio power state.
9478 * @param enable {@code true} if trying to turn radio on.
9479 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9480 * false}.
9481 */
9482 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9483 Phone phone = getPhone(subId);
9484 if (phone != null) {
9485 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9486 return true;
9487 }
9488 return false;
9489 }
9490
9491 private int handleDataThrottlingRequest(int subId,
9492 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009493 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9494 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9495 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9496 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9497 throw new IllegalArgumentException("modem does not support data throttling");
9498 }
9499
Jack Nudelman24d51a52020-11-24 12:08:04 -08009500 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9501 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9502 if (!setRadioPowerForThermal(subId, true)) {
9503 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9504 }
9505
9506 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9507
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009508 if (isDataThrottlingSupported) {
9509 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009510 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009511 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9512 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9513 } else if (thermalMitigationResult
9514 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman20352592021-05-20 13:57:30 -07009515 log("Modem likely does not support data throttling on secondary carrier. Data " +
9516 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9517 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009518 }
9519 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009520 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009521
9522 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009523 }
9524
Jack Nudelman644b91a2021-03-12 14:09:48 -08009525 private static List<String> getThermalMitigationAllowlist(Context context) {
9526 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9527 for (String pckg : context.getResources()
9528 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9529 sThermalMitigationAllowlistedPackages.add(pckg);
9530 }
9531 }
9532
9533 return sThermalMitigationAllowlistedPackages;
9534 }
9535
Jack Nudelmane634f962021-05-13 10:00:15 -07009536 private boolean isAnyPhoneInEmergencyState() {
9537 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9538 if (tm.isInEmergencyCall()) {
9539 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9540 return true;
9541 }
9542 for (Phone phone : PhoneFactory.getPhones()) {
9543 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9544 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9545 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9546 + phone.isInEcm());
9547 return true;
9548 }
9549 }
9550
9551 return false;
9552 }
9553
Jack Nudelman644b91a2021-03-12 14:09:48 -08009554 /**
9555 * Used by shell commands to add an authorized package name for thermal mitigation.
9556 * @param packageName name of package to be allowlisted
9557 * @param context
9558 */
9559 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9560 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9561 sThermalMitigationAllowlistedPackages.add(packageName);
9562 }
9563
9564 /**
9565 * Used by shell commands to remove an authorized package name for thermal mitigation.
9566 * @param packageName name of package to remove from allowlist
9567 * @param context
9568 */
9569 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9570 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9571 sThermalMitigationAllowlistedPackages.remove(packageName);
9572 }
9573
Jack Nudelman24d51a52020-11-24 12:08:04 -08009574 /**
9575 * Thermal mitigation request to control functionalities at modem.
9576 *
9577 * @param subId the id of the subscription.
9578 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009579 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009580 *
9581 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9582 */
9583 @Override
9584 @ThermalMitigationResult
9585 public int sendThermalMitigationRequest(
9586 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009587 ThermalMitigationRequest thermalMitigationRequest,
9588 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009589 enforceModifyPermission();
9590
Jack Nudelman644b91a2021-03-12 14:09:48 -08009591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9592 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9593 .contains(callingPackage)) {
9594 throw new SecurityException("Calling package must be configured in the device config. "
9595 + "calling package: " + callingPackage);
9596 }
9597
Jack Nudelman24d51a52020-11-24 12:08:04 -08009598 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9599 final long identity = Binder.clearCallingIdentity();
9600
9601 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9602 try {
9603 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9604 switch (thermalMitigationAction) {
9605 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9606 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009607 handleDataThrottlingRequest(subId,
9608 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009609 break;
9610 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9611 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9612 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9613 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9614 }
9615
9616 // Ensure that radio is on. If not able to power on due to phone being
9617 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9618 if (!setRadioPowerForThermal(subId, true)) {
9619 thermalMitigationResult =
9620 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9621 break;
9622 }
9623
9624 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9625 false);
9626 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9627 break;
9628 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9629 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9630 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9631 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9632 }
9633
9634 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9635 if (registry != null) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009636 Phone phone = getPhone(subId);
9637 if (phone == null) {
9638 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009639 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009640 break;
9641 }
9642
Jack Nudelmane634f962021-05-13 10:00:15 -07009643 TelephonyConnectionService service =
9644 registry.getTelephonyConnectionService();
9645 if (service == null) {
9646 Log.e(LOG_TAG, "TelephonyConnectionService is null");
9647 thermalMitigationResult =
9648 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9649 break;
9650
9651 } else if (service.isEmergencyCallPending()) {
9652 Log.e(LOG_TAG, "An emergency call is pending");
9653 thermalMitigationResult =
9654 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9655 break;
9656 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009657 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009658 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009659 break;
9660 }
9661 } else {
9662 thermalMitigationResult =
9663 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9664 break;
9665 }
9666
9667 // Turn radio off. If not able to power off due to phone being unavailable,
9668 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9669 if (!setRadioPowerForThermal(subId, false)) {
9670 thermalMitigationResult =
9671 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9672 break;
9673 }
9674 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009675 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009676 break;
9677 default:
9678 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9679 + "not exist. Requested action: " + thermalMitigationAction);
9680 }
9681 } catch (IllegalArgumentException e) {
9682 throw e;
9683 } catch (Exception e) {
9684 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9685 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9686 } finally {
9687 Binder.restoreCallingIdentity(identity);
9688 }
9689
9690 if (DBG) {
9691 log("thermalMitigationRequest returning with thermalMitigationResult: "
9692 + thermalMitigationResult);
9693 }
9694
9695 return thermalMitigationResult;
9696 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009697
9698 /**
9699 * Set the GbaService Package Name that Telephony will bind to.
9700 *
9701 * @param subId The sim that the GbaService is associated with.
9702 * @param packageName The name of the package to be replaced with.
9703 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9704 */
9705 @Override
9706 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9707 enforceModifyPermission();
9708
9709 final long identity = Binder.clearCallingIdentity();
9710 try {
9711 return getGbaManager(subId).overrideServicePackage(packageName);
9712 } finally {
9713 Binder.restoreCallingIdentity(identity);
9714 }
9715 }
9716
9717 /**
9718 * Return the package name of the currently bound GbaService.
9719 *
9720 * @param subId The sim that the GbaService is associated with.
9721 * @return the package name of the GbaService configuration, null if GBA is not supported.
9722 */
9723 @Override
9724 public String getBoundGbaService(int subId) {
9725 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9726
9727 final long identity = Binder.clearCallingIdentity();
9728 try {
9729 return getGbaManager(subId).getServicePackage();
9730 } finally {
9731 Binder.restoreCallingIdentity(identity);
9732 }
9733 }
9734
9735 /**
9736 * Set the release time for telephony to unbind GbaService.
9737 *
9738 * @param subId The sim that the GbaService is associated with.
9739 * @param interval The release time to unbind GbaService by millisecond.
9740 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9741 */
9742 @Override
9743 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9744 enforceModifyPermission();
9745
9746 final long identity = Binder.clearCallingIdentity();
9747 try {
9748 return getGbaManager(subId).overrideReleaseTime(interval);
9749 } finally {
9750 Binder.restoreCallingIdentity(identity);
9751 }
9752 }
9753
9754 /**
9755 * Return the release time for telephony to unbind GbaService.
9756 *
9757 * @param subId The sim that the GbaService is associated with.
9758 * @return The release time to unbind GbaService by millisecond.
9759 */
9760 @Override
9761 public int getGbaReleaseTime(int subId) {
9762 enforceReadPrivilegedPermission("getGbaReleaseTime");
9763
9764 final long identity = Binder.clearCallingIdentity();
9765 try {
9766 return getGbaManager(subId).getReleaseTime();
9767 } finally {
9768 Binder.restoreCallingIdentity(identity);
9769 }
9770 }
9771
9772 private GbaManager getGbaManager(int subId) {
9773 GbaManager instance = GbaManager.getInstance(subId);
9774 if (instance == null) {
9775 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9776 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9777 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9778 }
9779 return instance;
9780 }
Hui Wang068ab862020-10-31 05:12:53 +00009781
9782 /**
9783 * indicate whether the device and the carrier can support
9784 * RCS VoLTE single registration.
9785 */
9786 @Override
9787 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009788 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9789 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9790 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9791 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009792
9793 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9794 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9795 }
9796
9797 final long identity = Binder.clearCallingIdentity();
9798 try {
9799 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9800 if (rpm != null) {
Hui Wang048c10a2021-06-21 18:05:57 +00009801 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
9802 if (isCapable != null) {
9803 return isCapable;
9804 }
Hui Wang068ab862020-10-31 05:12:53 +00009805 }
Hui Wang048c10a2021-06-21 18:05:57 +00009806 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
9807 "service is temporarily unavailable.");
Hui Wang068ab862020-10-31 05:12:53 +00009808 } finally {
9809 Binder.restoreCallingIdentity(identity);
9810 }
9811 }
9812
9813 /**
9814 * Register RCS provisioning callback.
9815 */
9816 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009817 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009818 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009819 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009820 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009821 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9822 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009823
9824 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9825 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9826 }
9827 if (!isImsAvailableOnDevice()) {
9828 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9829 "IMS not available on device.");
9830 }
9831
9832 final long identity = Binder.clearCallingIdentity();
9833 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009834 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009835 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009836 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9837 "Service not available for the subscription.");
9838 }
Hui Wang068ab862020-10-31 05:12:53 +00009839 } finally {
9840 Binder.restoreCallingIdentity(identity);
9841 }
9842 }
9843
9844 /**
9845 * Unregister RCS provisioning callback.
9846 */
9847 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009848 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009849 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009850 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009851 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009852 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9853 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009854
9855 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9856 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9857 }
9858 if (!isImsAvailableOnDevice()) {
9859 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9860 "IMS not available on device.");
9861 }
9862
9863 final long identity = Binder.clearCallingIdentity();
9864 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009865 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009866 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009867 } finally {
9868 Binder.restoreCallingIdentity(identity);
9869 }
9870 }
9871
9872 /**
9873 * trigger RCS reconfiguration.
9874 */
9875 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009876 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9877 "triggerRcsReconfiguration",
9878 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009879
9880 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9881 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9882 }
9883 if (!isImsAvailableOnDevice()) {
9884 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9885 "IMS not available on device.");
9886 }
9887
9888 final long identity = Binder.clearCallingIdentity();
9889 try {
9890 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9891 } finally {
9892 Binder.restoreCallingIdentity(identity);
9893 }
9894 }
9895
9896 /**
9897 * Provide the client configuration parameters of the RCS application.
9898 */
9899 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009900 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9901 "setRcsClientConfiguration",
9902 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009903
9904 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9905 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9906 }
9907 if (!isImsAvailableOnDevice()) {
9908 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9909 "IMS not available on device.");
9910 }
9911
9912 final long identity = Binder.clearCallingIdentity();
9913
9914 try {
9915 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9916 if (configBinder == null) {
9917 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9918 } else {
9919 configBinder.setRcsClientConfiguration(rcc);
9920 }
9921 } catch (RemoteException e) {
9922 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9923 } finally {
9924 Binder.restoreCallingIdentity(identity);
9925 }
9926 }
9927
9928 /**
Hui Wang19a21872021-02-19 20:45:36 -08009929 * Enables or disables the test mode for RCS VoLTE single registration.
9930 */
9931 @Override
9932 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9933 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9934 "setRcsSingleRegistrationTestModeEnabled");
9935
9936 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9937 }
9938
9939 /**
9940 * Gets the test mode for RCS VoLTE single registration.
9941 */
9942 @Override
9943 public boolean getRcsSingleRegistrationTestModeEnabled() {
9944 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9945 "getRcsSingleRegistrationTestModeEnabled");
9946
9947 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9948 }
9949
9950 /**
Hui Wang068ab862020-10-31 05:12:53 +00009951 * Overrides the config of RCS VoLTE single registration enabled for the device.
9952 */
9953 @Override
9954 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9955 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9956 "setDeviceSingleRegistrationEnabledOverride");
9957 enforceModifyPermission();
9958
9959 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9960 : Boolean.parseBoolean(enabledStr);
9961 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009962 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009963 }
9964
9965 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009966 * Sends a device to device communication message. Only usable via shell.
9967 * @param message message to send.
9968 * @param value message value.
9969 */
9970 @Override
9971 public void sendDeviceToDeviceMessage(int message, int value) {
9972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9973 "setCarrierSingleRegistrationEnabledOverride");
9974 enforceModifyPermission();
9975
9976 final long identity = Binder.clearCallingIdentity();
9977 try {
9978 TelephonyConnectionService service =
9979 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9980 if (service == null) {
9981 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9982 return;
9983 }
9984 service.sendTestDeviceToDeviceMessage(message, value);
9985 } finally {
9986 Binder.restoreCallingIdentity(identity);
9987 }
9988 }
9989
9990
9991 /**
Hui Wang068ab862020-10-31 05:12:53 +00009992 * Gets the config of RCS VoLTE single registration enabled for the device.
9993 */
9994 @Override
9995 public boolean getDeviceSingleRegistrationEnabled() {
9996 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9997 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9998 }
9999
10000 /**
10001 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10002 */
10003 @Override
10004 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10005 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10006 "setCarrierSingleRegistrationEnabledOverride");
10007 enforceModifyPermission();
10008
10009 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10010 : Boolean.parseBoolean(enabledStr);
10011 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10012 subId, enabled);
10013 }
10014
10015 /**
10016 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10017 */
10018 @Override
10019 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10020 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10021 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10022 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010023
10024 /**
Hui Wangeadb2562021-02-26 09:33:38 -080010025 * Overrides the ims feature validation result
10026 */
10027 @Override
10028 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10029 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10030 "setImsFeatureValidationOverride");
10031
10032 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10033 : Boolean.parseBoolean(enabledStr);
10034 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10035 subId, enabled);
10036 }
10037
10038 /**
10039 * Gets the ims feature validation override value
10040 */
10041 @Override
10042 public boolean getImsFeatureValidationOverride(int subId) {
10043 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10044 "getImsFeatureValidationOverride");
10045 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10046 }
10047
10048 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010049 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10050 * their mobile plan.
10051 */
10052 @Override
10053 public String getMobileProvisioningUrl() {
10054 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10055 final long identity = Binder.clearCallingIdentity();
10056 try {
10057 return getDefaultPhone().getMobileProvisioningUrl();
10058 } finally {
10059 Binder.restoreCallingIdentity(identity);
10060 }
10061 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010062
James.cf Linbcdf8b32021-01-14 16:44:13 +080010063 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010064 * Get the EAB contact from the EAB database.
10065 */
10066 @Override
10067 public String getContactFromEab(String contact) {
10068 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10069 enforceModifyPermission();
10070 final long identity = Binder.clearCallingIdentity();
10071 try {
10072 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10073 } finally {
10074 Binder.restoreCallingIdentity(identity);
10075 }
10076 }
10077
10078 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010079 * Remove the EAB contacts from the EAB database.
10080 */
10081 @Override
10082 public int removeContactFromEab(int subId, String contacts) {
10083 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10084 enforceModifyPermission();
10085 final long identity = Binder.clearCallingIdentity();
10086 try {
10087 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10088 } finally {
10089 Binder.restoreCallingIdentity(identity);
10090 }
10091 }
10092
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010093 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010094 public boolean getDeviceUceEnabled() {
10095 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10096 final long identity = Binder.clearCallingIdentity();
10097 try {
10098 return mApp.getDeviceUceEnabled();
10099 } finally {
10100 Binder.restoreCallingIdentity(identity);
10101 }
10102 }
10103
10104 @Override
10105 public void setDeviceUceEnabled(boolean isEnabled) {
10106 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10107 final long identity = Binder.clearCallingIdentity();
10108 try {
10109 mApp.setDeviceUceEnabled(isEnabled);
10110 } finally {
10111 Binder.restoreCallingIdentity(identity);
10112 }
10113 }
10114
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010115 /**
10116 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10117 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10118 */
10119 // Used for SHELL command only right now.
10120 @Override
10121 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10122 List<String> featureTags) {
10123 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10124 "addUceRegistrationOverrideShell");
10125 final long identity = Binder.clearCallingIdentity();
10126 try {
10127 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10128 new ArraySet<>(featureTags));
10129 } catch (ImsException e) {
10130 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10131 } finally {
10132 Binder.restoreCallingIdentity(identity);
10133 }
10134 }
10135
10136 /**
10137 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10138 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10139 */
10140 // Used for SHELL command only right now.
10141 @Override
10142 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10143 List<String> featureTags) {
10144 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10145 "removeUceRegistrationOverrideShell");
10146 final long identity = Binder.clearCallingIdentity();
10147 try {
10148 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10149 new ArraySet<>(featureTags));
10150 } catch (ImsException e) {
10151 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10152 } finally {
10153 Binder.restoreCallingIdentity(identity);
10154 }
10155 }
10156
10157 /**
10158 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10159 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10160 */
10161 // Used for SHELL command only right now.
10162 @Override
10163 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10164 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10165 "clearUceRegistrationOverrideShell");
10166 final long identity = Binder.clearCallingIdentity();
10167 try {
10168 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10169 } catch (ImsException e) {
10170 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10171 } finally {
10172 Binder.restoreCallingIdentity(identity);
10173 }
10174 }
10175
10176 /**
10177 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10178 */
10179 // Used for SHELL command only right now.
10180 @Override
10181 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10182 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10183 "getLatestRcsContactUceCapabilityShell");
10184 final long identity = Binder.clearCallingIdentity();
10185 try {
10186 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10187 } catch (ImsException e) {
10188 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10189 } finally {
10190 Binder.restoreCallingIdentity(identity);
10191 }
10192 }
10193
10194 /**
10195 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10196 * device does not have an active PUBLISH.
10197 */
10198 // Used for SHELL command only right now.
10199 @Override
10200 public String getLastUcePidfXmlShell(int subId) {
10201 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10202 final long identity = Binder.clearCallingIdentity();
10203 try {
10204 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10205 } catch (ImsException e) {
10206 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10207 } finally {
10208 Binder.restoreCallingIdentity(identity);
10209 }
10210 }
10211
James.cf Line8713a42021-04-29 16:04:26 +080010212 /**
10213 * Remove UCE requests cannot be sent to the network status.
10214 */
10215 // Used for SHELL command only right now.
10216 @Override
10217 public boolean removeUceRequestDisallowedStatus(int subId) {
10218 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10219 final long identity = Binder.clearCallingIdentity();
10220 try {
10221 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10222 } catch (ImsException e) {
10223 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10224 } finally {
10225 Binder.restoreCallingIdentity(identity);
10226 }
10227 }
10228
James.cf Lin18bb9002021-05-25 01:37:38 +080010229 /**
10230 * Remove UCE requests cannot be sent to the network status.
10231 */
10232 // Used for SHELL command only.
10233 @Override
10234 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10235 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10236 final long identity = Binder.clearCallingIdentity();
10237 try {
10238 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10239 } catch (ImsException e) {
10240 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10241 } finally {
10242 Binder.restoreCallingIdentity(identity);
10243 }
10244 }
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010245
James.cf Lin4b784aa2021-01-31 03:25:15 +080010246 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010247 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10248 String callingPackage) {
10249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10250 mApp, subId, "setSignalStrengthUpdateRequest");
10251
10252 final int callingUid = Binder.getCallingUid();
10253 // Verify that tha callingPackage belongs to the calling UID
10254 mApp.getSystemService(AppOpsManager.class)
10255 .checkPackage(callingUid, callingPackage);
10256
10257 validateSignalStrengthUpdateRequest(request, callingUid);
10258
10259 final long identity = Binder.clearCallingIdentity();
10260 try {
10261 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10262 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10263
10264 if (result instanceof IllegalStateException) {
10265 throw (IllegalStateException) result;
10266 }
10267 } finally {
10268 Binder.restoreCallingIdentity(identity);
10269 }
10270 }
10271
10272 @Override
10273 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10274 String callingPackage) {
10275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10276 mApp, subId, "clearSignalStrengthUpdateRequest");
10277
10278 final int callingUid = Binder.getCallingUid();
10279 // Verify that tha callingPackage belongs to the calling UID
10280 mApp.getSystemService(AppOpsManager.class)
10281 .checkPackage(callingUid, callingPackage);
10282
10283 final long identity = Binder.clearCallingIdentity();
10284 try {
10285 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10286 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10287
10288 if (result instanceof IllegalStateException) {
10289 throw (IllegalStateException) result;
10290 }
10291 } finally {
10292 Binder.restoreCallingIdentity(identity);
10293 }
10294 }
10295
10296 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10297 int callingUid) {
10298 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10299 // phone/system process do not have further restriction on request
10300 return;
10301 }
10302
10303 // Applications has restrictions on how to use the request:
10304 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10305 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10306 // This is not system caller which has been checked above
10307 throw new IllegalArgumentException(
10308 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10309 }
10310
10311 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10312 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10313 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10314 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10315 || info.isEnabled()) {
10316 throw new IllegalArgumentException(
10317 "Only system can set hide fields in SignalThresholdInfo");
10318 }
10319
10320 // Thresholds length for each RAN need in range. This has been validated in
10321 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10322 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10323 final int[] thresholds = info.getThresholds();
10324 Objects.requireNonNull(thresholds);
10325 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10326 || thresholds.length
10327 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10328 throw new IllegalArgumentException(
10329 "thresholds length is out of range: " + thresholds.length);
10330 }
10331 }
10332 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010333
10334 /**
10335 * Prepare TelephonyManager for an unattended reboot. The reboot is
10336 * required to be done shortly after the API is invoked.
10337 */
10338 @Override
10339 @TelephonyManager.PrepareUnattendedRebootResult
10340 public int prepareForUnattendedReboot() {
10341 enforceRebootPermission();
10342
10343 final long identity = Binder.clearCallingIdentity();
10344 try {
10345 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10346 } finally {
10347 Binder.restoreCallingIdentity(identity);
10348 }
10349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010350}