blob: 6e003b43e7048fb4c3dc0d4d6b2c559423c935be [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;
sqian80370722020-01-29 15:02:51 -0800137import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700138import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700139import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700140import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800141import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700142import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700143import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800144import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700146import com.android.internal.telephony.GbaManager;
Shuo Qian479dd9e2021-02-22 18:32:21 -0800147import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800148import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800149import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700150import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700151import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800152import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700153import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800154import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700155import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700156import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700157import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700159import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800160import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700161import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700162import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700163import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700164import com.android.internal.telephony.RIL;
SongFerngWang522637d2021-03-02 22:09:29 +0800165import com.android.internal.telephony.RILConstants;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800166import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700167import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700168import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800170import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800171import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800172import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700173import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800174import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700175import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800176import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700177import com.android.internal.telephony.imsphone.ImsPhone;
178import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800179import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900180import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700181import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800182import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800184import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700185import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800186import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800188import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000189import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800190import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700191import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700192import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800193import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700194import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700195import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800196import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700197import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700198import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800199import com.android.services.telephony.TelecomAccountRegistry;
200import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800201import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800202
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700203import java.io.FileDescriptor;
204import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800206import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800207import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800208import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800209import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100210import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800211import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700212import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800213import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800214import java.util.Set;
SongFerngWangc63cf522021-03-31 22:08:45 +0800215import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800216import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800217import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218
219/**
220 * Implementation of the ITelephony interface.
221 */
Santos Cordon117fee72014-05-16 17:56:12 -0700222public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700223 private static final String LOG_TAG = "PhoneInterfaceManager";
224 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
225 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800226 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227
228 // Message codes used with mMainThreadHandler
229 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700230 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
231 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700232 private static final int CMD_OPEN_CHANNEL = 9;
233 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
234 private static final int CMD_CLOSE_CHANNEL = 11;
235 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800236 private static final int CMD_NV_READ_ITEM = 13;
237 private static final int EVENT_NV_READ_ITEM_DONE = 14;
238 private static final int CMD_NV_WRITE_ITEM = 15;
239 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
240 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
241 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700242 private static final int CMD_RESET_MODEM_CONFIG = 19;
243 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800244 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
245 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800246 private static final int CMD_SEND_ENVELOPE = 25;
247 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000248 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
249 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700250 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
251 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
252 private static final int CMD_EXCHANGE_SIM_IO = 31;
253 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800254 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
255 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700256 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
257 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700258 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
259 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700260 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
261 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
262 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
263 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700264 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
265 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
266 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
267 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700268 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800269 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
270 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000271 private static final int CMD_SWITCH_SLOTS = 50;
272 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700273 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
274 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
275 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
276 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
277 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
278 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
279 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
280 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700281 private static final int CMD_GET_ALL_CELL_INFO = 60;
282 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
283 private static final int CMD_GET_CELL_LOCATION = 62;
284 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700285 private static final int CMD_MODEM_REBOOT = 64;
286 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700287 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
288 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800289 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
290 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700291 private static final int CMD_GET_MODEM_STATUS = 70;
292 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700293 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
294 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700295 private static final int CMD_ERASE_MODEM_CONFIG = 74;
296 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800297 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
298 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
299 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
300 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800301 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
302 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800303 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800304 private static final int CMD_GET_CALL_FORWARDING = 83;
305 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
306 private static final int CMD_SET_CALL_FORWARDING = 85;
307 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
308 private static final int CMD_GET_CALL_WAITING = 87;
309 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
310 private static final int CMD_SET_CALL_WAITING = 89;
311 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700312 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
313 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
314 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
315 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700316 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
317 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800318 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
319 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800320 private static final int CMD_SET_DATA_THROTTLING = 99;
321 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800322 private static final int CMD_SET_SIM_POWER = 101;
323 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800324 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
325 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
326 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
327 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800328 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
329 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000330 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800332 // Parameters of select command.
333 private static final int SELECT_COMMAND = 0xA4;
334 private static final int SELECT_P1 = 0x04;
335 private static final int SELECT_P2 = 0;
336 private static final int SELECT_P3 = 0x10;
337
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 /** The singleton instance. */
339 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800340 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
Wink Saville3ab207e2014-11-20 13:07:20 -0800342 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800343 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800344 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700345 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800346 private AppOpsManager mAppOps;
347 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800348 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800349 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700350 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800351 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352
Peter Wangdafb9ac2020-01-15 14:13:38 -0800353 /** User Activity */
354 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800355 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
356
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700357 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
358
Derek Tan97ebb422014-09-05 16:55:38 -0700359 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
360 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800361 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800362 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700363
Michelecea4cf22018-12-21 15:00:11 -0800364 // String to store multi SIM allowed
365 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
366
Derek Tan740e1672017-06-27 14:56:27 -0700367 // The AID of ISD-R.
368 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
369
yinxub1bed742017-04-17 11:45:04 -0700370 private NetworkScanRequestTracker mNetworkScanRequestTracker;
371
David Kelly5e06a7f2018-03-12 14:10:59 +0000372 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
373 private static final int MANUFACTURER_CODE_LENGTH = 8;
374
Jack Nudelman24d51a52020-11-24 12:08:04 -0800375 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800376 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800377
Derek Tan89e89d42014-07-08 17:00:10 -0700378 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700379 * Experiment flag to enable erase modem config on reset network, default value is false
380 */
381 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
382 "reset_network_erase_modem_config_enabled";
383
Rambo Wang0f050d82021-02-12 11:43:36 -0800384 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
385
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700386 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700387 * A request object to use for transmitting data to an ICC.
388 */
389 private static final class IccAPDUArgument {
390 public int channel, cla, command, p1, p2, p3;
391 public String data;
392
393 public IccAPDUArgument(int channel, int cla, int command,
394 int p1, int p2, int p3, String data) {
395 this.channel = channel;
396 this.cla = cla;
397 this.command = command;
398 this.p1 = p1;
399 this.p2 = p2;
400 this.p3 = p3;
401 this.data = data;
402 }
403 }
404
405 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700406 * A request object to use for transmitting data to an ICC.
407 */
408 private static final class ManualNetworkSelectionArgument {
409 public OperatorInfo operatorInfo;
410 public boolean persistSelection;
411
412 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
413 this.operatorInfo = operatorInfo;
414 this.persistSelection = persistSelection;
415 }
416 }
417
418 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700419 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
420 * request after sending. The main thread will notify the request when it is complete.
421 */
422 private static final class MainThreadRequest {
423 /** The argument to use for the request */
424 public Object argument;
425 /** The result of the request that is run on the main thread */
426 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800427 // The subscriber id that this request applies to. Defaults to
428 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
429 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430
Nathan Harold92bed182018-10-12 18:16:49 -0700431 // In cases where subId is unavailable, the caller needs to specify the phone.
432 public Phone phone;
433
vagdeviaf9a5b92018-08-15 16:01:53 -0700434 public WorkSource workSource;
435
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 public MainThreadRequest(Object argument) {
437 this.argument = argument;
438 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800439
Nathan Harold92bed182018-10-12 18:16:49 -0700440 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
441 this.argument = argument;
442 if (phone != null) {
443 this.phone = phone;
444 }
445 this.workSource = workSource;
446 }
447
vagdeviaf9a5b92018-08-15 16:01:53 -0700448 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800449 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800450 if (subId != null) {
451 this.subId = subId;
452 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700453 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 }
456
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800457 private static final class IncomingThirdPartyCallArgs {
458 public final ComponentName component;
459 public final String callId;
460 public final String callerDisplayName;
461
462 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
463 String callerDisplayName) {
464 this.component = component;
465 this.callId = callId;
466 this.callerDisplayName = callerDisplayName;
467 }
468 }
469
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 /**
471 * A handler that processes messages on the main thread in the phone process. Since many
472 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
473 * inbound binder threads to the main thread in the phone process. The Binder thread
474 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
475 * on, which will be notified when the operation completes and will contain the result of the
476 * request.
477 *
478 * <p>If a MainThreadRequest object is provided in the msg.obj field,
479 * note that request.result must be set to something non-null for the calling thread to
480 * unblock.
481 */
482 private final class MainThreadHandler extends Handler {
483 @Override
484 public void handleMessage(Message msg) {
485 MainThreadRequest request;
486 Message onCompleted;
487 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800488 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800490 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700491
492 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 case CMD_HANDLE_USSD_REQUEST: {
494 request = (MainThreadRequest) msg.obj;
495 final Phone phone = getPhoneFromRequest(request);
496 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
497 String ussdRequest = ussdObject.first;
498 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700499
Pengquan Menga1bb6272018-09-06 09:59:22 -0700500 if (!isUssdApiAllowed(request.subId)) {
501 // Carrier does not support use of this API, return failure.
502 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
503 UssdResponse response = new UssdResponse(ussdRequest, null);
504 Bundle returnData = new Bundle();
505 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
506 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700507
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 request.result = true;
509 notifyRequester(request);
510 return;
511 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700512
Pengquan Menga1bb6272018-09-06 09:59:22 -0700513 try {
514 request.result = phone != null
515 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
516 } catch (CallStateException cse) {
517 request.result = false;
518 }
519 // Wake up the requesting thread
520 notifyRequester(request);
521 break;
pkanwar32d516d2016-10-14 19:37:38 -0700522 }
523
Yorke Lee716f67e2015-06-17 15:39:16 -0700524 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700526 final Phone phone = getPhoneFromRequest(request);
527 request.result = phone != null ?
528 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
529 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700532 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700536 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 if (uiccCard == null) {
540 loge("iccTransmitApduLogicalChannel: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
545 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700546 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 iccArgument.channel, iccArgument.cla, iccArgument.command,
548 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 break;
552
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 ar = (AsyncResult) msg.obj;
555 request = (MainThreadRequest) ar.userObj;
556 if (ar.exception == null && ar.result != null) {
557 request.result = ar.result;
558 } else {
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
560 if (ar.result == null) {
561 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800562 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800564 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 } else {
566 loge("iccTransmitApduLogicalChannel: Unknown exception");
567 }
568 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 break;
571
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
573 request = (MainThreadRequest) msg.obj;
574 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800575 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 if (uiccCard == null) {
577 loge("iccTransmitApduBasicChannel: No UICC");
578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 } else {
581 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
582 request);
583 uiccCard.iccTransmitApduBasicChannel(
584 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
585 iccArgument.p3, iccArgument.data, onCompleted);
586 }
587 break;
588
589 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
590 ar = (AsyncResult) msg.obj;
591 request = (MainThreadRequest) ar.userObj;
592 if (ar.exception == null && ar.result != null) {
593 request.result = ar.result;
594 } else {
595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
596 if (ar.result == null) {
597 loge("iccTransmitApduBasicChannel: Empty response");
598 } else if (ar.exception instanceof CommandException) {
599 loge("iccTransmitApduBasicChannel: CommandException: " +
600 ar.exception);
601 } else {
602 loge("iccTransmitApduBasicChannel: Unknown exception");
603 }
604 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 break;
607
608 case CMD_EXCHANGE_SIM_IO:
609 request = (MainThreadRequest) msg.obj;
610 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800611 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 if (uiccCard == null) {
613 loge("iccExchangeSimIO: No UICC");
614 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 } else {
617 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
618 request);
619 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
620 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
621 iccArgument.data, onCompleted);
622 }
623 break;
624
625 case EVENT_EXCHANGE_SIM_IO_DONE:
626 ar = (AsyncResult) msg.obj;
627 request = (MainThreadRequest) ar.userObj;
628 if (ar.exception == null && ar.result != null) {
629 request.result = ar.result;
630 } else {
631 request.result = new IccIoResult(0x6f, 0, (byte[])null);
632 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 break;
635
Derek Tan4d5e5c12014-02-04 11:54:58 -0800636 case CMD_SEND_ENVELOPE:
637 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800638 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 if (uiccCard == null) {
640 loge("sendEnvelopeWithStatus: No UICC");
641 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 } else {
644 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
645 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
646 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800647 break;
648
649 case EVENT_SEND_ENVELOPE_DONE:
650 ar = (AsyncResult) msg.obj;
651 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700652 if (ar.exception == null && ar.result != null) {
653 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800654 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700655 request.result = new IccIoResult(0x6F, 0, (byte[])null);
656 if (ar.result == null) {
657 loge("sendEnvelopeWithStatus: Empty response");
658 } else if (ar.exception instanceof CommandException) {
659 loge("sendEnvelopeWithStatus: CommandException: " +
660 ar.exception);
661 } else {
662 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
663 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800664 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700665 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800666 break;
667
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 case CMD_OPEN_CHANNEL:
669 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800670 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800671 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 if (uiccCard == null) {
673 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800674 request.result = new IccOpenLogicalChannelResponse(-1,
675 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 } else {
678 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800679 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
680 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 break;
683
684 case EVENT_OPEN_CHANNEL_DONE:
685 ar = (AsyncResult) msg.obj;
686 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700687 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700689 int[] result = (int[]) ar.result;
690 int channelId = result[0];
691 byte[] selectResponse = null;
692 if (result.length > 1) {
693 selectResponse = new byte[result.length - 1];
694 for (int i = 1; i < result.length; ++i) {
695 selectResponse[i - 1] = (byte) result[i];
696 }
697 }
698 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700699 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 if (ar.result == null) {
702 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700704 if (ar.exception != null) {
705 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
706 }
707
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700708 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700709 if (ar.exception instanceof CommandException) {
710 CommandException.Error error =
711 ((CommandException) (ar.exception)).getCommandError();
712 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700713 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700714 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700715 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700716 }
717 }
718 openChannelResp = new IccOpenLogicalChannelResponse(
719 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700721 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700722 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700723 break;
724
725 case CMD_CLOSE_CHANNEL:
726 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800727 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700728 if (uiccCard == null) {
729 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900730 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700731 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700732 } else {
733 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
734 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
735 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700736 break;
737
738 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800739 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
740 break;
741
742 case CMD_NV_READ_ITEM:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800745 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
746 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800747 break;
748
749 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 ar = (AsyncResult) msg.obj;
751 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800752 if (ar.exception == null && ar.result != null) {
753 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800755 request.result = "";
756 if (ar.result == null) {
757 loge("nvReadItem: Empty response");
758 } else if (ar.exception instanceof CommandException) {
759 loge("nvReadItem: CommandException: " +
760 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800762 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 }
764 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700765 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700766 break;
767
Jake Hambye994d462014-02-03 13:10:13 -0800768 case CMD_NV_WRITE_ITEM:
769 request = (MainThreadRequest) msg.obj;
770 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
771 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800772 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700773 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800774 break;
775
776 case EVENT_NV_WRITE_ITEM_DONE:
777 handleNullReturnEvent(msg, "nvWriteItem");
778 break;
779
780 case CMD_NV_WRITE_CDMA_PRL:
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800783 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800784 break;
785
786 case EVENT_NV_WRITE_CDMA_PRL_DONE:
787 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
788 break;
789
chen xu6dac5ab2018-10-26 17:39:23 -0700790 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800791 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700792 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800793 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800794 break;
795
chen xu6dac5ab2018-10-26 17:39:23 -0700796 case EVENT_RESET_MODEM_CONFIG_DONE:
797 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800798 break;
799
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700800 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
803 request);
804 Phone phone = getPhoneFromRequest(request);
805 if (phone != null) {
806 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
807 } else {
808 loge("isNRDualConnectivityEnabled: No phone object");
809 request.result = false;
810 notifyRequester(request);
811 }
812 break;
813 }
814
815 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
816 ar = (AsyncResult) msg.obj;
817 request = (MainThreadRequest) ar.userObj;
818 if (ar.exception == null && ar.result != null) {
819 request.result = ar.result;
820 } else {
821 // request.result must be set to something non-null
822 // for the calling thread to unblock
823 if (request.result != null) {
824 request.result = ar.result;
825 } else {
826 request.result = false;
827 }
828 if (ar.result == null) {
829 loge("isNRDualConnectivityEnabled: Empty response");
830 } else if (ar.exception instanceof CommandException) {
831 loge("isNRDualConnectivityEnabled: CommandException: "
832 + ar.exception);
833 } else {
834 loge("isNRDualConnectivityEnabled: Unknown exception");
835 }
836 }
837 notifyRequester(request);
838 break;
839
840 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
841 request = (MainThreadRequest) msg.obj;
842 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
843 Phone phone = getPhoneFromRequest(request);
844 if (phone != null) {
845 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
846 request.workSource);
847 } else {
848 loge("enableNrDualConnectivity: No phone object");
849 request.result =
850 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
851 notifyRequester(request);
852 }
853 break;
854 }
855
856 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
857 ar = (AsyncResult) msg.obj;
858 request = (MainThreadRequest) ar.userObj;
859 if (ar.exception == null) {
860 request.result =
861 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
862 } else {
863 request.result =
864 TelephonyManager
865 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
866 if (ar.exception instanceof CommandException) {
867 CommandException.Error error =
868 ((CommandException) (ar.exception)).getCommandError();
869 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
870 request.result =
871 TelephonyManager
872 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000873 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
874 request.result =
875 TelephonyManager
876 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700877 }
878 loge("enableNrDualConnectivity" + ": CommandException: "
879 + ar.exception);
880 } else {
881 loge("enableNrDualConnectivity" + ": Unknown exception");
882 }
883 }
884 notifyRequester(request);
885 break;
886 }
887
SongFerngWang9e060372020-12-21 16:41:52 +0800888 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800889 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800890 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
891 request);
892 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800893 break;
894
SongFerngWang9e060372020-12-21 16:41:52 +0800895 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800896 ar = (AsyncResult) msg.obj;
897 request = (MainThreadRequest) ar.userObj;
898 if (ar.exception == null && ar.result != null) {
899 request.result = ar.result; // Integer
900 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530901 // request.result must be set to something non-null
902 // for the calling thread to unblock
903 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800905 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800906 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800907 loge("getAllowedNetworkTypesBitmask: CommandException: "
908 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800909 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800910 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800911 }
912 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700913 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800914 break;
915
SongFerngWang9e060372020-12-21 16:41:52 +0800916 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800918 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
919 request);
920 Pair<Integer, Long> reasonWithNetworkTypes =
921 (Pair<Integer, Long>) request.argument;
922 getPhoneFromRequest(request).setAllowedNetworkTypes(
923 reasonWithNetworkTypes.first,
924 reasonWithNetworkTypes.second,
925 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800926 break;
927
SongFerngWang9e060372020-12-21 16:41:52 +0800928 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
929 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800930 break;
931
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000932 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
933 request = (MainThreadRequest)msg.obj;
934 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800935 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000936 break;
937
938 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
939 ar = (AsyncResult)msg.obj;
940 request = (MainThreadRequest)ar.userObj;
941 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700942 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000943 break;
944
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800945 case CMD_SET_VOICEMAIL_NUMBER:
946 request = (MainThreadRequest) msg.obj;
947 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
948 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800949 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
950 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800951 break;
952
953 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
954 handleNullReturnEvent(msg, "setVoicemailNumber");
955 break;
956
Stuart Scott54788802015-03-30 13:18:01 -0700957 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
958 request = (MainThreadRequest) msg.obj;
959 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
960 request);
961 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
962 break;
963
964 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
965 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
966 break;
967
Shishir Agrawal302c8692015-06-19 13:49:39 -0700968 case CMD_PERFORM_NETWORK_SCAN:
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
971 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
972 break;
973
Hall Liua1acea22020-09-18 19:04:59 -0700974 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800975 request = (MainThreadRequest) msg.obj;
976 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700977 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
978 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
979 request.argument;
980 int callForwardingReason = args.first;
981 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800982 break;
Hall Liua1acea22020-09-18 19:04:59 -0700983 }
984 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800985 ar = (AsyncResult) msg.obj;
986 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700987 TelephonyManager.CallForwardingInfoCallback callback =
988 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
989 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800990 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700991 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800992 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
993 for (CallForwardInfo callForwardInfo : callForwardInfos) {
994 // Service Class is a bit mask per 3gpp 27.007. Search for
995 // any service for voice call.
996 if ((callForwardInfo.serviceClass
997 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700998 callForwardingInfo = new CallForwardingInfo(true,
999 callForwardInfo.reason,
1000 callForwardInfo.number,
1001 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -08001002 break;
1003 }
1004 }
1005 // Didn't find a call forward info for voice call.
1006 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -07001007 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1008 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001009 }
Hall Liua1acea22020-09-18 19:04:59 -07001010 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001011 } else {
1012 if (ar.result == null) {
1013 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1014 }
1015 if (ar.exception != null) {
1016 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1017 }
Hall Liuae527aa2020-09-29 17:10:18 -07001018 int errorCode = TelephonyManager
1019 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001020 if (ar.exception instanceof CommandException) {
1021 CommandException.Error error =
1022 ((CommandException) (ar.exception)).getCommandError();
1023 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001024 errorCode = TelephonyManager
1025 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001026 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001027 errorCode = TelephonyManager
1028 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001029 }
1030 }
Hall Liua1acea22020-09-18 19:04:59 -07001031 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001032 }
sqian80370722020-01-29 15:02:51 -08001033 break;
Hall Liua1acea22020-09-18 19:04:59 -07001034 }
sqian80370722020-01-29 15:02:51 -08001035
Hall Liua1acea22020-09-18 19:04:59 -07001036 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001037 request = (MainThreadRequest) msg.obj;
1038 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001039 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001040 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001041 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1042 request.argument).first;
1043 request.phone.setCallForwardingOption(
1044 callForwardingInfoToSet.isEnabled()
1045 ? CommandsInterface.CF_ACTION_ENABLE
1046 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001047 callForwardingInfoToSet.getReason(),
1048 callForwardingInfoToSet.getNumber(),
1049 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1050 break;
Hall Liua1acea22020-09-18 19:04:59 -07001051 }
sqian80370722020-01-29 15:02:51 -08001052
Hall Liua1acea22020-09-18 19:04:59 -07001053 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001056 Consumer<Integer> callback =
1057 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1058 request.argument).second;
1059 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001060 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001061 int errorCode = TelephonyManager.CallForwardingInfoCallback
1062 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001063 if (ar.exception instanceof CommandException) {
1064 CommandException.Error error =
1065 ((CommandException) (ar.exception)).getCommandError();
1066 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001067 errorCode = TelephonyManager.CallForwardingInfoCallback
1068 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001069 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001070 errorCode = TelephonyManager.CallForwardingInfoCallback
1071 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001072 }
1073 }
1074 callback.accept(errorCode);
1075 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001076 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001077 }
sqian80370722020-01-29 15:02:51 -08001078 break;
Hall Liua1acea22020-09-18 19:04:59 -07001079 }
sqian80370722020-01-29 15:02:51 -08001080
Hall Liua1acea22020-09-18 19:04:59 -07001081 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001082 request = (MainThreadRequest) msg.obj;
1083 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1084 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1085 break;
Hall Liua1acea22020-09-18 19:04:59 -07001086 }
sqian80370722020-01-29 15:02:51 -08001087
Hall Liua1acea22020-09-18 19:04:59 -07001088 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001089 ar = (AsyncResult) msg.obj;
1090 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001091 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001092 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1093 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001094 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001095 // Service Class is a bit mask per 3gpp 27.007.
1096 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001097 if (callForwardResults.length > 1
1098 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001099 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001100 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001101 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1102 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001103 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001104 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001105 }
1106 } else {
1107 if (ar.result == null) {
1108 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1109 }
1110 if (ar.exception != null) {
1111 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1112 }
1113 if (ar.exception instanceof CommandException) {
1114 CommandException.Error error =
1115 ((CommandException) (ar.exception)).getCommandError();
1116 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1117 callForwardingStatus =
1118 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1119 }
1120 }
1121 }
Hall Liua1acea22020-09-18 19:04:59 -07001122 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001123 break;
Hall Liua1acea22020-09-18 19:04:59 -07001124 }
sqian80370722020-01-29 15:02:51 -08001125
Hall Liua1acea22020-09-18 19:04:59 -07001126 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001127 request = (MainThreadRequest) msg.obj;
1128 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001129 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1130 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001131 break;
Hall Liua1acea22020-09-18 19:04:59 -07001132 }
sqian80370722020-01-29 15:02:51 -08001133
Hall Liua1acea22020-09-18 19:04:59 -07001134 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001135 ar = (AsyncResult) msg.obj;
1136 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001137 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1138 Consumer<Integer> callback =
1139 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1140 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001141 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001142 if (ar.exception instanceof CommandException) {
1143 CommandException.Error error =
1144 ((CommandException) (ar.exception)).getCommandError();
1145 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1146 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1147 } else {
1148 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1149 }
1150 } else {
1151 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1152 }
1153 } else {
1154 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1155 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001156 }
sqian80370722020-01-29 15:02:51 -08001157 break;
Hall Liua1acea22020-09-18 19:04:59 -07001158 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001159 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1160 ar = (AsyncResult) msg.obj;
1161 request = (MainThreadRequest) ar.userObj;
1162 CellNetworkScanResult cellScanResult;
1163 if (ar.exception == null && ar.result != null) {
1164 cellScanResult = new CellNetworkScanResult(
1165 CellNetworkScanResult.STATUS_SUCCESS,
1166 (List<OperatorInfo>) ar.result);
1167 } else {
1168 if (ar.result == null) {
1169 loge("getCellNetworkScanResults: Empty response");
1170 }
1171 if (ar.exception != null) {
1172 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1173 }
1174 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1175 if (ar.exception instanceof CommandException) {
1176 CommandException.Error error =
1177 ((CommandException) (ar.exception)).getCommandError();
1178 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1179 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1180 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1181 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1182 }
1183 }
1184 cellScanResult = new CellNetworkScanResult(errorCode, null);
1185 }
1186 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001187 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001188 break;
1189
1190 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1191 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001192 ManualNetworkSelectionArgument selArg =
1193 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001194 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1195 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001196 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1197 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001198 break;
1199
1200 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001201 ar = (AsyncResult) msg.obj;
1202 request = (MainThreadRequest) ar.userObj;
1203 if (ar.exception == null) {
1204 request.result = true;
1205 } else {
1206 request.result = false;
1207 loge("setNetworkSelectionModeManual " + ar.exception);
1208 }
1209 notifyRequester(request);
1210 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001211 break;
1212
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001213 case CMD_GET_MODEM_ACTIVITY_INFO:
1214 request = (MainThreadRequest) msg.obj;
1215 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001216 if (defaultPhone != null) {
1217 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001218 } else {
1219 ResultReceiver result = (ResultReceiver) request.argument;
1220 Bundle bundle = new Bundle();
1221 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1222 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1223 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001224 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001225 break;
1226
1227 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1228 ar = (AsyncResult) msg.obj;
1229 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001230 ResultReceiver result = (ResultReceiver) request.argument;
1231
1232 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001233 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001234 // Update the last modem activity info and the result of the request.
1235 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1236 if (isModemActivityInfoValid(info)) {
1237 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1238 int[] txTimeMs = info.getTransmitTimeMillis();
1239 int[] lastModemTxTimeMs = mLastModemActivityInfo
1240 .getTransmitTimeMillis();
1241 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1242 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1243 }
1244 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1245 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1246 + mLastModemActivityInfo.getSleepTimeMillis());
1247 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1248 + mLastModemActivityInfo.getIdleTimeMillis());
1249 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1250 mLastModemActivityInfo.setReceiveTimeMillis(
1251 info.getReceiveTimeMillis()
1252 + mLastModemActivityInfo.getReceiveTimeMillis());
1253 }
1254 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1255 mLastModemActivityInfo.getSleepTimeMillis(),
1256 mLastModemActivityInfo.getIdleTimeMillis(),
1257 mLastModemActivityInfo.getTransmitTimeMillis(),
1258 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001259 } else {
1260 if (ar.result == null) {
1261 loge("queryModemActivityInfo: Empty response");
1262 } else if (ar.exception instanceof CommandException) {
1263 loge("queryModemActivityInfo: CommandException: " +
1264 ar.exception);
1265 } else {
1266 loge("queryModemActivityInfo: Unknown exception");
1267 }
1268 }
sqian1a1be542020-03-05 11:37:28 -08001269 Bundle bundle = new Bundle();
1270 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1271 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001272 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001273 break;
1274
Meng Wang1a7c35a2016-05-05 20:56:15 -07001275 case CMD_SET_ALLOWED_CARRIERS:
1276 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001277 CarrierRestrictionRules argument =
1278 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001279 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001280 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001281 break;
1282
1283 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1284 ar = (AsyncResult) msg.obj;
1285 request = (MainThreadRequest) ar.userObj;
1286 if (ar.exception == null && ar.result != null) {
1287 request.result = ar.result;
1288 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001289 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1290 if (ar.exception instanceof CommandException) {
1291 loge("setAllowedCarriers: CommandException: " + ar.exception);
1292 CommandException.Error error =
1293 ((CommandException) (ar.exception)).getCommandError();
1294 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1295 request.result =
1296 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1297 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001298 } else {
1299 loge("setAllowedCarriers: Unknown exception");
1300 }
1301 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001302 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 break;
1304
1305 case CMD_GET_ALLOWED_CARRIERS:
1306 request = (MainThreadRequest) msg.obj;
1307 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001308 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001309 break;
1310
1311 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1312 ar = (AsyncResult) msg.obj;
1313 request = (MainThreadRequest) ar.userObj;
1314 if (ar.exception == null && ar.result != null) {
1315 request.result = ar.result;
1316 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001317 request.result = new IllegalStateException(
1318 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001319 if (ar.result == null) {
1320 loge("getAllowedCarriers: Empty response");
1321 } else if (ar.exception instanceof CommandException) {
1322 loge("getAllowedCarriers: CommandException: " +
1323 ar.exception);
1324 } else {
1325 loge("getAllowedCarriers: Unknown exception");
1326 }
1327 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001328 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001329 break;
1330
Nathan Haroldb3014052017-01-25 15:57:32 -08001331 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1332 ar = (AsyncResult) msg.obj;
1333 request = (MainThreadRequest) ar.userObj;
1334 if (ar.exception == null && ar.result != null) {
1335 request.result = ar.result;
1336 } else {
1337 request.result = new IllegalArgumentException(
1338 "Failed to retrieve Forbidden Plmns");
1339 if (ar.result == null) {
1340 loge("getForbiddenPlmns: Empty response");
1341 } else {
1342 loge("getForbiddenPlmns: Unknown exception");
1343 }
1344 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001345 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001346 break;
1347
1348 case CMD_GET_FORBIDDEN_PLMNS:
1349 request = (MainThreadRequest) msg.obj;
1350 uiccCard = getUiccCardFromRequest(request);
1351 if (uiccCard == null) {
1352 loge("getForbiddenPlmns() UiccCard is null");
1353 request.result = new IllegalArgumentException(
1354 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001355 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001356 break;
1357 }
1358 Integer appType = (Integer) request.argument;
1359 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1360 if (uiccApp == null) {
1361 loge("getForbiddenPlmns() no app with specified type -- "
1362 + appType);
1363 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001364 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001365 break;
1366 } else {
1367 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1368 + " specified type -- " + appType);
1369 }
1370 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1371 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1372 onCompleted);
1373 break;
1374
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001375 case CMD_SWITCH_SLOTS:
1376 request = (MainThreadRequest) msg.obj;
1377 int[] physicalSlots = (int[]) request.argument;
1378 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1379 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1380 break;
1381
1382 case EVENT_SWITCH_SLOTS_DONE:
1383 ar = (AsyncResult) msg.obj;
1384 request = (MainThreadRequest) ar.userObj;
1385 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001386 notifyRequester(request);
1387 break;
1388 case CMD_GET_NETWORK_SELECTION_MODE:
1389 request = (MainThreadRequest) msg.obj;
1390 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1391 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1392 break;
1393
1394 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1395 ar = (AsyncResult) msg.obj;
1396 request = (MainThreadRequest) ar.userObj;
1397 if (ar.exception != null) {
1398 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1399 } else {
1400 int mode = ((int[]) ar.result)[0];
1401 if (mode == 0) {
1402 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1403 } else {
1404 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1405 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001406 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001407 notifyRequester(request);
1408 break;
1409 case CMD_GET_CDMA_ROAMING_MODE:
1410 request = (MainThreadRequest) msg.obj;
1411 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1412 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1413 break;
1414 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1415 ar = (AsyncResult) msg.obj;
1416 request = (MainThreadRequest) ar.userObj;
1417 if (ar.exception != null) {
1418 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1419 } else {
1420 request.result = ((int[]) ar.result)[0];
1421 }
1422 notifyRequester(request);
1423 break;
1424 case CMD_SET_CDMA_ROAMING_MODE:
1425 request = (MainThreadRequest) msg.obj;
1426 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1427 int mode = (int) request.argument;
1428 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1429 break;
1430 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1431 ar = (AsyncResult) msg.obj;
1432 request = (MainThreadRequest) ar.userObj;
1433 request.result = ar.exception == null;
1434 notifyRequester(request);
1435 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001436 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1437 request = (MainThreadRequest) msg.obj;
1438 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1439 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1440 break;
1441 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1442 ar = (AsyncResult) msg.obj;
1443 request = (MainThreadRequest) ar.userObj;
1444 if (ar.exception != null) {
1445 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1446 } else {
1447 request.result = ((int[]) ar.result)[0];
1448 }
1449 notifyRequester(request);
1450 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001451 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1452 request = (MainThreadRequest) msg.obj;
1453 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1454 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001455 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1456 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001457 break;
1458 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1459 ar = (AsyncResult) msg.obj;
1460 request = (MainThreadRequest) ar.userObj;
1461 request.result = ar.exception == null;
1462 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001463 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001464 case CMD_GET_ALL_CELL_INFO:
1465 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001466 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001467 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001468 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001469 case EVENT_GET_ALL_CELL_INFO_DONE:
1470 ar = (AsyncResult) msg.obj;
1471 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001472 // If a timeout occurs, the response will be null
1473 request.result = (ar.exception == null && ar.result != null)
1474 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001475 synchronized (request) {
1476 request.notifyAll();
1477 }
1478 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001479 case CMD_REQUEST_CELL_INFO_UPDATE:
1480 request = (MainThreadRequest) msg.obj;
1481 request.phone.requestCellInfoUpdate(request.workSource,
1482 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1483 break;
1484 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1485 ar = (AsyncResult) msg.obj;
1486 request = (MainThreadRequest) ar.userObj;
1487 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1488 try {
1489 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001490 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001491 cb.onError(
1492 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1493 ar.exception.getClass().getName(),
1494 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001495 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001496 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001497 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001498 } else {
1499 // use the result as returned
1500 cb.onCellInfo((List<CellInfo>) ar.result);
1501 }
1502 } catch (RemoteException re) {
1503 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1504 }
1505 break;
Sarah Chincc055732020-11-18 13:39:35 -08001506 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001507 request = (MainThreadRequest) msg.obj;
1508 WorkSource ws = (WorkSource) request.argument;
1509 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001510 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001511 break;
Sarah Chincc055732020-11-18 13:39:35 -08001512 }
1513 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001514 ar = (AsyncResult) msg.obj;
1515 request = (MainThreadRequest) ar.userObj;
1516 if (ar.exception == null) {
1517 request.result = ar.result;
1518 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001519 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001520 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001521 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001522 }
1523
1524 synchronized (request) {
1525 request.notifyAll();
1526 }
1527 break;
Sarah Chincc055732020-11-18 13:39:35 -08001528 }
chen xu6dac5ab2018-10-26 17:39:23 -07001529 case CMD_MODEM_REBOOT:
1530 request = (MainThreadRequest) msg.obj;
1531 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001532 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001533 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001534 case EVENT_CMD_MODEM_REBOOT_DONE:
1535 handleNullReturnEvent(msg, "rebootModem");
1536 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001537 case CMD_REQUEST_ENABLE_MODEM:
1538 request = (MainThreadRequest) msg.obj;
1539 boolean enable = (boolean) request.argument;
1540 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001541 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001542 PhoneConfigurationManager.getInstance()
1543 .enablePhone(request.phone, enable, onCompleted);
1544 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001545 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001546 ar = (AsyncResult) msg.obj;
1547 request = (MainThreadRequest) ar.userObj;
1548 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001549 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001550 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001551 if ((boolean) request.result) {
1552 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1553 updateModemStateMetrics();
1554 } else {
1555 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1556 + ar.exception);
1557 }
1558 notifyRequester(request);
1559 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001560 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001561 case CMD_GET_MODEM_STATUS:
1562 request = (MainThreadRequest) msg.obj;
1563 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1564 PhoneConfigurationManager.getInstance()
1565 .getPhoneStatusFromModem(request.phone, onCompleted);
1566 break;
1567 case EVENT_GET_MODEM_STATUS_DONE:
1568 ar = (AsyncResult) msg.obj;
1569 request = (MainThreadRequest) ar.userObj;
1570 int id = request.phone.getPhoneId();
1571 if (ar.exception == null && ar.result != null) {
1572 request.result = ar.result;
1573 //update the cache as modem status has changed
1574 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1575 (boolean) request.result);
1576 } else {
1577 // Return true if modem status cannot be retrieved. For most cases,
1578 // modem status is on. And for older version modems, GET_MODEM_STATUS
1579 // and disable modem are not supported. Modem is always on.
1580 // TODO: this should be fixed in R to support a third
1581 // status UNKNOWN b/131631629
1582 request.result = true;
1583 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1584 + ar.exception);
1585 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001586 notifyRequester(request);
1587 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001588 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1591 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1592 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1593 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1594 break;
1595 }
1596 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1597 ar = (AsyncResult) msg.obj;
1598 request = (MainThreadRequest) ar.userObj;
1599 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1600 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1601 args.second.accept(ar.exception == null);
1602 notifyRequester(request);
1603 break;
1604 }
Sarah Chincc055732020-11-18 13:39:35 -08001605 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1606 request = (MainThreadRequest) msg.obj;
1607 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1608 Phone phone = getPhoneFromRequest(request);
1609 if (phone != null) {
1610 phone.getSystemSelectionChannels(onCompleted);
1611 } else {
1612 loge("getSystemSelectionChannels: No phone object");
1613 request.result = new ArrayList<RadioAccessSpecifier>();
1614 notifyRequester(request);
1615 }
1616 break;
1617 }
1618 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1619 ar = (AsyncResult) msg.obj;
1620 request = (MainThreadRequest) ar.userObj;
1621 if (ar.exception == null && ar.result != null) {
1622 request.result = ar.result;
1623 } else {
Sarah Chin58691872021-03-13 03:17:40 -08001624 request.result = new IllegalStateException(
1625 "Failed to retrieve system selecton channels");
Sarah Chincc055732020-11-18 13:39:35 -08001626 if (ar.result == null) {
1627 loge("getSystemSelectionChannels: Empty response");
1628 } else {
1629 loge("getSystemSelectionChannels: Unknown exception");
1630 }
1631 }
1632 notifyRequester(request);
1633 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001634 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1635 ar = (AsyncResult) msg.obj;
1636 request = (MainThreadRequest) ar.userObj;
1637 if (ar.exception == null && ar.result != null) {
1638 request.result = ar.result;
1639 } else {
1640 request.result = -1;
1641 loge("Failed to set Forbidden Plmns");
1642 if (ar.result == null) {
1643 loge("setForbidenPlmns: Empty response");
1644 } else if (ar.exception != null) {
1645 loge("setForbiddenPlmns: Exception: " + ar.exception);
1646 request.result = -1;
1647 } else {
1648 loge("setForbiddenPlmns: Unknown exception");
1649 }
1650 }
1651 notifyRequester(request);
1652 break;
1653 case CMD_SET_FORBIDDEN_PLMNS:
1654 request = (MainThreadRequest) msg.obj;
1655 uiccCard = getUiccCardFromRequest(request);
1656 if (uiccCard == null) {
1657 loge("setForbiddenPlmns: UiccCard is null");
1658 request.result = -1;
1659 notifyRequester(request);
1660 break;
1661 }
1662 Pair<Integer, List<String>> setFplmnsArgs =
1663 (Pair<Integer, List<String>>) request.argument;
1664 appType = setFplmnsArgs.first;
1665 List<String> fplmns = setFplmnsArgs.second;
1666 uiccApp = uiccCard.getApplicationByType(appType);
1667 if (uiccApp == null) {
1668 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1669 request.result = -1;
1670 loge("Failed to get UICC App");
1671 notifyRequester(request);
1672 } else {
1673 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1674 ((SIMRecords) uiccApp.getIccRecords())
1675 .setForbiddenPlmns(onCompleted, fplmns);
1676 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001677 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001678 case CMD_ERASE_MODEM_CONFIG:
1679 request = (MainThreadRequest) msg.obj;
1680 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1681 defaultPhone.eraseModemConfig(onCompleted);
1682 break;
1683 case EVENT_ERASE_MODEM_CONFIG_DONE:
1684 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001685 break;
zoey chenf95ca592019-12-30 16:11:23 +08001686
1687 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1688 request = (MainThreadRequest) msg.obj;
1689 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1690 Pair<String, String> changed = (Pair<String, String>) request.argument;
1691 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1692 changed.first, changed.second, onCompleted);
1693 break;
1694 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1695 ar = (AsyncResult) msg.obj;
1696 request = (MainThreadRequest) ar.userObj;
1697 if (ar.exception == null) {
1698 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001699 // If the operation is successful, update the PIN storage
1700 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1701 int phoneId = getPhoneFromRequest(request).getPhoneId();
1702 UiccController.getInstance().getPinStorage()
1703 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001704 } else {
1705 request.result = msg.arg1;
1706 }
1707 notifyRequester(request);
1708 break;
1709
Michele Berionned9fbae52020-11-13 02:36:59 +00001710 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001711 request = (MainThreadRequest) msg.obj;
1712 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1713 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1714 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1715 enabled.first, enabled.second, onCompleted);
1716 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001717 }
zoey chenf95ca592019-12-30 16:11:23 +08001718 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1719 ar = (AsyncResult) msg.obj;
1720 request = (MainThreadRequest) ar.userObj;
1721 if (ar.exception == null) {
1722 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001723 // If the operation is successful, update the PIN storage
1724 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1725 int phoneId = getPhoneFromRequest(request).getPhoneId();
1726 if (enabled.first) {
1727 UiccController.getInstance().getPinStorage()
1728 .storePin(enabled.second, phoneId);
1729 } else {
1730 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1731 }
zoey chenf95ca592019-12-30 16:11:23 +08001732 } else {
1733 request.result = msg.arg1;
1734 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001735
1736
zoey chenf95ca592019-12-30 16:11:23 +08001737 notifyRequester(request);
1738 break;
1739
Peter Wangdafb9ac2020-01-15 14:13:38 -08001740 case MSG_NOTIFY_USER_ACTIVITY:
1741 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001742 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001743 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1744 getDefaultPhone().getContext().sendBroadcastAsUser(
1745 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1746 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001747
1748 case CMD_SET_DATA_THROTTLING: {
1749 request = (MainThreadRequest) msg.obj;
1750 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1751 DataThrottlingRequest dataThrottlingRequest =
1752 (DataThrottlingRequest) request.argument;
1753 Phone phone = getPhoneFromRequest(request);
1754 if (phone != null) {
1755 phone.setDataThrottling(onCompleted,
1756 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1757 dataThrottlingRequest.getCompletionDurationMillis());
1758 } else {
1759 loge("setDataThrottling: No phone object");
1760 request.result =
1761 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1762 notifyRequester(request);
1763 }
1764
1765 break;
1766 }
1767 case EVENT_SET_DATA_THROTTLING_DONE:
1768 ar = (AsyncResult) msg.obj;
1769 request = (MainThreadRequest) ar.userObj;
1770
1771 if (ar.exception == null) {
1772 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1773 } else if (ar.exception instanceof CommandException) {
1774 loge("setDataThrottling: CommandException: " + ar.exception);
1775 CommandException.Error error =
1776 ((CommandException) (ar.exception)).getCommandError();
1777
1778 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1779 request.result = TelephonyManager
1780 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1781 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1782 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001783 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1784 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001785 } else {
1786 request.result =
1787 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1788 }
1789 } else {
1790 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1791 }
1792 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1793 notifyRequester(request);
1794 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001795
1796 case CMD_SET_SIM_POWER: {
1797 request = (MainThreadRequest) msg.obj;
1798 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1799 request = (MainThreadRequest) msg.obj;
1800 int stateToSet =
1801 ((Pair<Integer, IIntegerConsumer>)
1802 request.argument).first;
1803 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1804 break;
1805 }
1806 case EVENT_SET_SIM_POWER_DONE: {
1807 ar = (AsyncResult) msg.obj;
1808 request = (MainThreadRequest) ar.userObj;
1809 IIntegerConsumer callback =
1810 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1811 if (ar.exception != null) {
1812 loge("setSimPower exception: " + ar.exception);
1813 int errorCode = TelephonyManager.CallForwardingInfoCallback
1814 .RESULT_ERROR_UNKNOWN;
1815 if (ar.exception instanceof CommandException) {
1816 CommandException.Error error =
1817 ((CommandException) (ar.exception)).getCommandError();
1818 if (error == CommandException.Error.SIM_ERR) {
1819 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1820 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1821 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1822 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1823 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1824 } else {
1825 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1826 }
1827 }
1828 try {
1829 callback.accept(errorCode);
1830 } catch (RemoteException e) {
1831 // Ignore if the remote process is no longer available to call back.
1832 Log.w(LOG_TAG, "setSimPower: callback not available.");
1833 }
1834 } else {
1835 try {
1836 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1837 } catch (RemoteException e) {
1838 // Ignore if the remote process is no longer available to call back.
1839 Log.w(LOG_TAG, "setSimPower: callback not available.");
1840 }
1841 }
1842 break;
1843 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001844 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1845 request = (MainThreadRequest) msg.obj;
1846
1847 final Phone phone = getPhoneFromRequest(request);
1848 if (phone == null || phone.getServiceStateTracker() == null) {
1849 request.result = new IllegalStateException("Phone or SST is null");
1850 notifyRequester(request);
1851 break;
1852 }
1853
1854 Pair<Integer, SignalStrengthUpdateRequest> pair =
1855 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1856 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1857 request);
1858 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1859 request.subId, pair.first /*callingUid*/,
1860 pair.second /*request*/, onCompleted);
1861 break;
1862 }
1863 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1864 ar = (AsyncResult) msg.obj;
1865 request = (MainThreadRequest) ar.userObj;
1866 // request.result will be the exception of ar if present, true otherwise.
1867 // Be cautious not to leave result null which will wait() forever
1868 request.result = ar.exception != null ? ar.exception : true;
1869 notifyRequester(request);
1870 break;
1871 }
1872 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1873 request = (MainThreadRequest) msg.obj;
1874
1875 Phone phone = getPhoneFromRequest(request);
1876 if (phone == null || phone.getServiceStateTracker() == null) {
1877 request.result = new IllegalStateException("Phone or SST is null");
1878 notifyRequester(request);
1879 break;
1880 }
1881
1882 Pair<Integer, SignalStrengthUpdateRequest> pair =
1883 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1884 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1885 request);
1886 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1887 request.subId, pair.first /*callingUid*/,
1888 pair.second /*request*/, onCompleted);
1889 break;
1890 }
1891 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1892 ar = (AsyncResult) msg.obj;
1893 request = (MainThreadRequest) ar.userObj;
1894 request.result = ar.exception != null ? ar.exception : true;
1895 notifyRequester(request);
1896 break;
1897 }
Jordan Liud5366d92020-11-24 14:50:34 -08001898
Michele Berionned9fbae52020-11-13 02:36:59 +00001899 case CMD_PREPARE_UNATTENDED_REBOOT:
1900 request = (MainThreadRequest) msg.obj;
1901 request.result =
1902 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1903 notifyRequester(request);
1904 break;
1905
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 default:
1907 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1908 break;
1909 }
1910 }
Jake Hambye994d462014-02-03 13:10:13 -08001911
Pengquan Menga1bb6272018-09-06 09:59:22 -07001912 private void notifyRequester(MainThreadRequest request) {
1913 synchronized (request) {
1914 request.notifyAll();
1915 }
1916 }
1917
Jake Hambye994d462014-02-03 13:10:13 -08001918 private void handleNullReturnEvent(Message msg, String command) {
1919 AsyncResult ar = (AsyncResult) msg.obj;
1920 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1921 if (ar.exception == null) {
1922 request.result = true;
1923 } else {
1924 request.result = false;
1925 if (ar.exception instanceof CommandException) {
1926 loge(command + ": CommandException: " + ar.exception);
1927 } else {
1928 loge(command + ": Unknown exception");
1929 }
1930 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001931 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001932 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001933 }
1934
1935 /**
1936 * Posts the specified command to be executed on the main thread,
1937 * waits for the request to complete, and returns the result.
1938 * @see #sendRequestAsync
1939 */
1940 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001941 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1942 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001943 }
1944
1945 /**
1946 * Posts the specified command to be executed on the main thread,
1947 * waits for the request to complete, and returns the result.
1948 * @see #sendRequestAsync
1949 */
1950 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1951 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001952 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001953 }
1954
1955 /**
1956 * Posts the specified command to be executed on the main thread,
1957 * waits for the request to complete, and returns the result.
1958 * @see #sendRequestAsync
1959 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001960 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001961 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1962 }
1963
1964 /**
1965 * Posts the specified command to be executed on the main thread,
1966 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1967 * if not timeout or null otherwise.
1968 * @see #sendRequestAsync
1969 */
1970 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1971 long timeoutInMs) {
1972 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001973 }
1974
1975 /**
1976 * Posts the specified command to be executed on the main thread,
1977 * waits for the request to complete, and returns the result.
1978 * @see #sendRequestAsync
1979 */
Nathan Harold92bed182018-10-12 18:16:49 -07001980 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001981 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001982 }
1983
1984 /**
1985 * Posts the specified command to be executed on the main thread,
1986 * waits for the request to complete, and returns the result.
1987 * @see #sendRequestAsync
1988 */
1989 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001990 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1991 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001992 }
1993
1994 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001995 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1996 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1997 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001998 * @see #sendRequestAsync
1999 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002000 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2001 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2003 throw new RuntimeException("This method will deadlock if called from the main thread.");
2004 }
2005
Nathan Harold92bed182018-10-12 18:16:49 -07002006 MainThreadRequest request = null;
2007 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2008 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2009 } else if (phone != null) {
2010 request = new MainThreadRequest(argument, phone, workSource);
2011 } else {
2012 request = new MainThreadRequest(argument, subId, workSource);
2013 }
2014
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 Message msg = mMainThreadHandler.obtainMessage(command, request);
2016 msg.sendToTarget();
2017
Rambo Wang0f050d82021-02-12 11:43:36 -08002018
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002020 if (timeoutInMs >= 0) {
2021 // Wait for at least timeoutInMs before returning null request result
2022 long now = SystemClock.elapsedRealtime();
2023 long deadline = now + timeoutInMs;
2024 while (request == null && now < deadline) {
2025 try {
2026 request.wait(deadline - now);
2027 } catch (InterruptedException e) {
2028 // Do nothing, go back and check if request is completed or timeout
2029 } finally {
2030 now = SystemClock.elapsedRealtime();
2031 }
2032 }
2033 } else {
2034 // Wait for the request to complete
2035 while (request.result == null) {
2036 try {
2037 request.wait();
2038 } catch (InterruptedException e) {
2039 // Do nothing, go back and wait until the request is complete
2040 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002041 }
2042 }
2043 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002044 if (request.result == null) {
2045 Log.wtf(LOG_TAG,
2046 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2047 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 return request.result;
2049 }
2050
2051 /**
2052 * Asynchronous ("fire and forget") version of sendRequest():
2053 * Posts the specified command to be executed on the main thread, and
2054 * returns immediately.
2055 * @see #sendRequest
2056 */
2057 private void sendRequestAsync(int command) {
2058 mMainThreadHandler.sendEmptyMessage(command);
2059 }
2060
2061 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002062 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002063 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002064 */
2065 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002066 sendRequestAsync(command, argument, null, null);
2067 }
2068
2069 /**
2070 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2071 * @see {@link #sendRequest(int,Object)}
2072 */
2073 private void sendRequestAsync(
2074 int command, Object argument, Phone phone, WorkSource workSource) {
2075 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002076 Message msg = mMainThreadHandler.obtainMessage(command, request);
2077 msg.sendToTarget();
2078 }
2079
2080 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 * Initialize the singleton PhoneInterfaceManager instance.
2082 * This is only done once, at startup, from PhoneApp.onCreate().
2083 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002084 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 synchronized (PhoneInterfaceManager.class) {
2086 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002087 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 } else {
2089 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2090 }
2091 return sInstance;
2092 }
2093 }
2094
2095 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002096 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerc9c432e2021-05-17 20:54:49 +00002099 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002100 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2102 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002103 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002104 mTelephonySharedPreferences =
2105 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002106 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002107 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002108 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002109 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002110
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 publish();
2112 }
2113
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002114 private Phone getDefaultPhone() {
2115 Phone thePhone = getPhone(getDefaultSubscription());
2116 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2117 }
2118
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 private void publish() {
2120 if (DBG) log("publish: " + this);
2121
Peter Wangc035ce42020-01-08 21:00:22 -08002122 TelephonyFrameworkInitializer
2123 .getTelephonyServiceManager()
2124 .getTelephonyServiceRegisterer()
2125 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126 }
2127
Stuart Scott584921c2015-01-15 17:10:34 -08002128 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002129 if (request.phone != null) {
2130 return request.phone;
2131 } else {
2132 return getPhoneFromSubId(request.subId);
2133 }
2134 }
2135
2136 private Phone getPhoneFromSubId(int subId) {
2137 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2138 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002139 }
2140
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002141 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2142 Phone phone = getPhoneFromRequest(request);
2143 return phone == null ? null :
2144 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2145 }
2146
Wink Saville36469e72014-06-11 15:17:00 -07002147 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002148 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002149 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002152 private void sendEraseModemConfig(Phone phone) {
2153 if (phone != null) {
2154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2155 mApp, phone.getSubId(), "eraseModemConfig");
2156 final long identity = Binder.clearCallingIdentity();
2157 try {
2158 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2159 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2160 } finally {
2161 Binder.restoreCallingIdentity(identity);
2162 }
2163 }
2164 }
2165
Peter Wang050bb052020-01-13 23:33:09 -08002166 private boolean isImsAvailableOnDevice() {
2167 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2168 if (pm == null) {
2169 // For some reason package manger is not available.. This will fail internally anyway,
2170 // so do not throw error and allow.
2171 return true;
2172 }
2173 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2174 }
2175
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002177 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002178 }
2179
Wink Savilleb564aae2014-10-23 10:18:09 -07002180 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 if (DBG) log("dial: " + number);
2182 // No permission check needed here: This is just a wrapper around the
2183 // ACTION_DIAL intent, which is available to any app since it puts up
2184 // the UI before it does anything.
2185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002186 final long identity = Binder.clearCallingIdentity();
2187 try {
2188 String url = createTelUrl(number);
2189 if (url == null) {
2190 return;
2191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002193 // PENDING: should we just silently fail if phone is offhook or ringing?
2194 PhoneConstants.State state = mCM.getState(subId);
2195 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2196 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2197 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2198 mApp.startActivity(intent);
2199 }
2200 } finally {
2201 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 }
2203 }
2204
2205 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002206 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002207 }
2208
Wink Savilleb564aae2014-10-23 10:18:09 -07002209 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 if (DBG) log("call: " + number);
2211
2212 // This is just a wrapper around the ACTION_CALL intent, but we still
2213 // need to do a permission check since we're calling startActivity()
2214 // from the context of the phone app.
2215 enforceCallPermission();
2216
Jordan Liu1617b712019-07-10 15:06:26 -07002217 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 != AppOpsManager.MODE_ALLOWED) {
2219 return;
2220 }
2221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222 final long identity = Binder.clearCallingIdentity();
2223 try {
2224 String url = createTelUrl(number);
2225 if (url == null) {
2226 return;
2227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229 boolean isValid = false;
2230 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2231 if (slist != null) {
2232 for (SubscriptionInfo subInfoRecord : slist) {
2233 if (subInfoRecord.getSubscriptionId() == subId) {
2234 isValid = true;
2235 break;
2236 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002237 }
Wink Saville08874612014-08-31 19:19:58 -07002238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002239 if (!isValid) {
2240 return;
2241 }
Wink Saville08874612014-08-31 19:19:58 -07002242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2244 intent.putExtra(SUBSCRIPTION_KEY, subId);
2245 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2246 mApp.startActivity(intent);
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
2249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 }
2251
Wink Savilleb564aae2014-10-23 10:18:09 -07002252 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002253 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002254 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2255 }
2256
Wink Savilleb564aae2014-10-23 10:18:09 -07002257 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002258 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002259 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2260 }
2261
Wink Savilleb564aae2014-10-23 10:18:09 -07002262 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264
2265 final long identity = Binder.clearCallingIdentity();
2266 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002267 Phone phone = getPhone(subId);
2268 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002269 checkSimPin.start();
2270 return checkSimPin.unlockSim(null, pin);
2271 } finally {
2272 Binder.restoreCallingIdentity(identity);
2273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 }
2275
Wink Savilleb564aae2014-10-23 10:18:09 -07002276 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002278
2279 final long identity = Binder.clearCallingIdentity();
2280 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002281 Phone phone = getPhone(subId);
2282 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002283 checkSimPuk.start();
2284 return checkSimPuk.unlockSim(puk, pin);
2285 } finally {
2286 Binder.restoreCallingIdentity(identity);
2287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 }
2289
2290 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002291 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 * a synchronous one.
2293 */
2294 private static class UnlockSim extends Thread {
2295
2296 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002297 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298
2299 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002300 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2301 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302
2303 // For replies from SimCard interface
2304 private Handler mHandler;
2305
2306 // For async handler to identify request type
2307 private static final int SUPPLY_PIN_COMPLETE = 100;
2308
Michele Berionned9fbae52020-11-13 02:36:59 +00002309 UnlockSim(int phoneId, IccCard simCard) {
2310 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 mSimCard = simCard;
2312 }
2313
2314 @Override
2315 public void run() {
2316 Looper.prepare();
2317 synchronized (UnlockSim.this) {
2318 mHandler = new Handler() {
2319 @Override
2320 public void handleMessage(Message msg) {
2321 AsyncResult ar = (AsyncResult) msg.obj;
2322 switch (msg.what) {
2323 case SUPPLY_PIN_COMPLETE:
2324 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2325 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002326 mRetryCount = msg.arg1;
2327 if (ar.exception != null) {
2328 if (ar.exception instanceof CommandException &&
2329 ((CommandException)(ar.exception)).getCommandError()
2330 == CommandException.Error.PASSWORD_INCORRECT) {
2331 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002332 } //When UiccCardApp dispose,handle message and return exception
2333 else if (ar.exception instanceof CommandException &&
2334 ((CommandException) (ar.exception)).getCommandError()
2335 == CommandException.Error.ABORTED) {
2336 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002337 } else {
2338 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2339 }
2340 } else {
2341 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 mDone = true;
2344 UnlockSim.this.notifyAll();
2345 }
2346 break;
2347 }
2348 }
2349 };
2350 UnlockSim.this.notifyAll();
2351 }
2352 Looper.loop();
2353 }
2354
2355 /*
2356 * Use PIN or PUK to unlock SIM card
2357 *
2358 * If PUK is null, unlock SIM card with PIN
2359 *
2360 * If PUK is not null, unlock SIM card with PUK and set PIN code
2361 */
Wink Saville9de0f752013-10-22 19:04:03 -07002362 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363
2364 while (mHandler == null) {
2365 try {
2366 wait();
2367 } catch (InterruptedException e) {
2368 Thread.currentThread().interrupt();
2369 }
2370 }
2371 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2372
2373 if (puk == null) {
2374 mSimCard.supplyPin(pin, callback);
2375 } else {
2376 mSimCard.supplyPuk(puk, pin, callback);
2377 }
2378
2379 while (!mDone) {
2380 try {
2381 Log.d(LOG_TAG, "wait for done");
2382 wait();
2383 } catch (InterruptedException e) {
2384 // Restore the interrupted status
2385 Thread.currentThread().interrupt();
2386 }
2387 }
2388 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002389 int[] resultArray = new int[2];
2390 resultArray[0] = mResult;
2391 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002392
2393 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2394 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2395 }
2396
Wink Saville9de0f752013-10-22 19:04:03 -07002397 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002398 }
2399 }
2400
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002401 /**
2402 * This method has been removed due to privacy and stability concerns.
2403 */
2404 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002406 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2407 return;
Wink Saville36469e72014-06-11 15:17:00 -07002408 }
2409
Nathan Harold1f889d82020-06-04 17:05:26 -07002410 @Override
2411 public void updateServiceLocationWithPackageName(String callingPackage) {
2412 mApp.getSystemService(AppOpsManager.class)
2413 .checkPackage(Binder.getCallingUid(), callingPackage);
2414
Nathan Haroldf096d982020-11-18 17:18:06 -08002415 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002416 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2417 // Callers targeting S have no business invoking this method.
2418 return;
2419 }
2420
2421 LocationAccessPolicy.LocationPermissionResult locationResult =
2422 LocationAccessPolicy.checkLocationPermission(mApp,
2423 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2424 .setCallingPackage(callingPackage)
2425 .setCallingFeatureId(null)
2426 .setCallingPid(Binder.getCallingPid())
2427 .setCallingUid(Binder.getCallingUid())
2428 .setMethod("updateServiceLocation")
2429 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2430 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2431 .build());
2432 // Apps that lack location permission have no business calling this method;
2433 // however, because no permission was declared in the public API, denials must
2434 // all be "soft".
2435 switch (locationResult) {
2436 case DENIED_HARD: /* fall through */
2437 case DENIED_SOFT:
2438 return;
2439 }
2440
2441 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442 final long identity = Binder.clearCallingIdentity();
2443 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002444 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002445 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002446 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447 }
2448 } finally {
2449 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 }
2452
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002453 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002454 @Override
2455 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002456 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002457 }
2458
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002459
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002460 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002461 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2462 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2463 callingFeatureId);
2464 }
2465
2466 @Deprecated
2467 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002468 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002469 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2470 }
2471
2472 @Override
2473 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2474 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002476 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002477 return false;
2478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002479
2480 final long identity = Binder.clearCallingIdentity();
2481 try {
2482 return isRadioOnForSubscriber(subId);
2483 } finally {
2484 Binder.restoreCallingIdentity(identity);
2485 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002486 }
2487
2488 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 final Phone phone = getPhone(subId);
2492 if (phone != null) {
2493 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2494 } else {
2495 return false;
2496 }
2497 } finally {
2498 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 }
2501
2502 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002503 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
Wink Saville36469e72014-06-11 15:17:00 -07002505
Wink Savilleb564aae2014-10-23 10:18:09 -07002506 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 final Phone phone = getPhone(subId);
2512 if (phone != null) {
2513 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002517 }
Wink Saville36469e72014-06-11 15:17:00 -07002518 }
2519
2520 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002521 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002522 }
2523
Wink Savilleb564aae2014-10-23 10:18:09 -07002524 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002525 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002526
2527 final long identity = Binder.clearCallingIdentity();
2528 try {
2529 final Phone phone = getPhone(subId);
2530 if (phone == null) {
2531 return false;
2532 }
2533 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2534 toggleRadioOnOffForSubscriber(subId);
2535 }
2536 return true;
2537 } finally {
2538 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002540 }
Wink Saville36469e72014-06-11 15:17:00 -07002541
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002542 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002543 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002544 /*
2545 * If any of the Radios are available, it will need to be
2546 * shutdown. So return true if any Radio is available.
2547 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2551 Phone phone = PhoneFactory.getPhone(i);
2552 if (phone != null && phone.isRadioAvailable()) return true;
2553 }
2554 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2555 return false;
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002558 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002559 }
2560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002562 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 enforceModifyPermission();
2564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2568 logv("Shutting down Phone " + i);
2569 shutdownRadioUsingPhoneId(i);
2570 }
2571 } finally {
2572 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002573 }
2574 }
2575
2576 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002577 Phone phone = PhoneFactory.getPhone(phoneId);
2578 if (phone != null && phone.isRadioAvailable()) {
2579 phone.shutdownRadio();
2580 }
2581 }
2582
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002583 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002584 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585
2586 final long identity = Binder.clearCallingIdentity();
2587 try {
2588 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2589 if (defaultPhone != null) {
2590 defaultPhone.setRadioPower(turnOn);
2591 return true;
2592 } else {
2593 loge("There's no default phone.");
2594 return false;
2595 }
2596 } finally {
2597 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002598 }
Wink Saville36469e72014-06-11 15:17:00 -07002599 }
2600
Wink Savilleb564aae2014-10-23 10:18:09 -07002601 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603
2604 final long identity = Binder.clearCallingIdentity();
2605 try {
2606 final Phone phone = getPhone(subId);
2607 if (phone != null) {
2608 phone.setRadioPower(turnOn);
2609 return true;
2610 } else {
2611 return false;
2612 }
2613 } finally {
2614 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002615 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002616 }
2617
Wink Saville36469e72014-06-11 15:17:00 -07002618 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002619 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620 public boolean enableDataConnectivity() {
2621 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 int subId = mSubscriptionController.getDefaultDataSubId();
2626 final Phone phone = getPhone(subId);
2627 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002628 phone.getDataEnabledSettings().setDataEnabled(
2629 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 return true;
2631 } else {
2632 return false;
2633 }
2634 } finally {
2635 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637 }
2638
Wink Saville36469e72014-06-11 15:17:00 -07002639 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002640 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 public boolean disableDataConnectivity() {
2642 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643
2644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 int subId = mSubscriptionController.getDefaultDataSubId();
2647 final Phone phone = getPhone(subId);
2648 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002649 phone.getDataEnabledSettings().setDataEnabled(
2650 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 return true;
2652 } else {
2653 return false;
2654 }
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
2659
Sanket Padawe356d7632015-06-22 14:03:32 -07002660 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002661 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002666 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 } else {
2668 return false;
2669 }
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673 }
2674
2675 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002676 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002677 }
2678
pkanwarae03a6b2016-11-06 20:37:09 -08002679 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680 enforceCallPermission();
2681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2685 return;
2686 }
2687 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2688 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2689 } finally {
2690 Binder.restoreCallingIdentity(identity);
2691 }
pkanwar32d516d2016-10-14 19:37:38 -07002692 };
2693
Wink Savilleb564aae2014-10-23 10:18:09 -07002694 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2700 return false;
2701 }
2702 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 }
2707
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002709 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002710 }
2711
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002712 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 Phone phone = PhoneFactory.getPhone(slotIndex);
2716 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2717 PhoneConstantConversions.convertCallState(phone.getState());
2718 } finally {
2719 Binder.restoreCallingIdentity(identity);
2720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 }
2722
Sanket Padawe356d7632015-06-22 14:03:32 -07002723 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002724 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002725 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2726 }
2727
2728 @Override
2729 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 final long identity = Binder.clearCallingIdentity();
2731 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002732 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733 if (phone != null) {
2734 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2735 } else {
2736 return PhoneConstantConversions.convertDataState(
2737 PhoneConstants.DataState.DISCONNECTED);
2738 }
2739 } finally {
2740 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002741 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 }
2743
Sanket Padawe356d7632015-06-22 14:03:32 -07002744 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002745 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002746 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2747 }
2748
2749 @Override
2750 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751 final long identity = Binder.clearCallingIdentity();
2752 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002753 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754 if (phone != null) {
2755 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2756 } else {
2757 return TelephonyManager.DATA_ACTIVITY_NONE;
2758 }
2759 } finally {
2760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002761 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 }
2763
2764 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002765 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002766 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002767 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002768
2769 LocationAccessPolicy.LocationPermissionResult locationResult =
2770 LocationAccessPolicy.checkLocationPermission(mApp,
2771 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2772 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002773 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002774 .setCallingPid(Binder.getCallingPid())
2775 .setCallingUid(Binder.getCallingUid())
2776 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002777 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002778 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2779 .build());
2780 switch (locationResult) {
2781 case DENIED_HARD:
2782 throw new SecurityException("Not allowed to access cell location");
2783 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002784 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2785 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002786 }
2787
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002788 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002792 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002793 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794 } finally {
2795 Binder.restoreCallingIdentity(identity);
2796 }
Svetoslav64fad262015-04-14 14:35:21 -07002797 }
2798
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 @Override
Jack Yu01425032020-02-22 19:38:58 -08002800 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002801 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2802 // registered cell info, so return a NULL country instead.
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002805 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2806 // Get default phone in this case.
2807 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2808 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002809 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002811 if (phone == null) return "";
2812 ServiceStateTracker sst = phone.getServiceStateTracker();
2813 if (sst == null) return "";
2814 LocaleTracker lt = sst.getLocaleTracker();
2815 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002816 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002817 } finally {
2818 Binder.restoreCallingIdentity(identity);
2819 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002820 }
2821
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002822 /**
2823 * This method was removed due to potential issues caused by performing partial
2824 * updates of service state, and lack of a credible use case.
2825 *
2826 * This has the ability to break the telephony implementation by disabling notification of
2827 * changes in device connectivity. DO NOT USE THIS!
2828 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002829 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 public void enableLocationUpdates() {
2831 mApp.enforceCallingOrSelfPermission(
2832 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002833 }
2834
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002835 /**
2836 * This method was removed due to potential issues caused by performing partial
2837 * updates of service state, and lack of a credible use case.
2838 *
2839 * This has the ability to break the telephony implementation by disabling notification of
2840 * changes in device connectivity. DO NOT USE THIS!
2841 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 @Override
2843 public void disableLocationUpdates() {
2844 mApp.enforceCallingOrSelfPermission(
2845 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 }
2847
2848 @Override
2849 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002850 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2851 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002852 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002853 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2854 throw new SecurityException(
2855 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2856 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002857
Jordan Liu1617b712019-07-10 15:06:26 -07002858 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2860 return null;
2861 }
Svetoslav64fad262015-04-14 14:35:21 -07002862
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002863 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002865 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002866 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867
Nathan Haroldf180aac2018-06-01 18:43:55 -07002868 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2869 for (CellInfo ci : info) {
2870 if (ci instanceof CellInfoGsm) {
2871 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2872 } else if (ci instanceof CellInfoWcdma) {
2873 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2874 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002875 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002876 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002877 }
2878
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002879 private List<CellInfo> getCachedCellInfo() {
2880 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2881 for (Phone phone : PhoneFactory.getPhones()) {
2882 List<CellInfo> info = phone.getAllCellInfo();
2883 if (info != null) cellInfos.addAll(info);
2884 }
2885 return cellInfos;
2886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002887
2888 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002889 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002890 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002891 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002892
2893 LocationAccessPolicy.LocationPermissionResult locationResult =
2894 LocationAccessPolicy.checkLocationPermission(mApp,
2895 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2896 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002897 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002898 .setCallingPid(Binder.getCallingPid())
2899 .setCallingUid(Binder.getCallingUid())
2900 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002901 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002902 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2903 .build());
2904 switch (locationResult) {
2905 case DENIED_HARD:
2906 throw new SecurityException("Not allowed to access cell info");
2907 case DENIED_SOFT:
2908 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002909 }
2910
Nathan Haroldf096d982020-11-18 17:18:06 -08002911 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002912 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2913 return getCachedCellInfo();
2914 }
2915
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002916 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002917 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 final long identity = Binder.clearCallingIdentity();
2919 try {
2920 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2921 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002922 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002923 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 if (info != null) cellInfos.addAll(info);
2925 }
2926 return cellInfos;
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930 }
2931
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002932 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002933 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2934 String callingFeatureId) {
2935 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2936 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002937 }
2938
2939 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002940 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2941 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002942 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002943 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002944 }
2945
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002946 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2947 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002948 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002949 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002950
2951 LocationAccessPolicy.LocationPermissionResult locationResult =
2952 LocationAccessPolicy.checkLocationPermission(mApp,
2953 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2954 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002955 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002956 .setCallingPid(Binder.getCallingPid())
2957 .setCallingUid(Binder.getCallingUid())
2958 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002959 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2960 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002961 .build());
2962 switch (locationResult) {
2963 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002964 if (TelephonyPermissions
2965 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002966 // Safetynet logging for b/154934934
2967 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2968 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002969 throw new SecurityException("Not allowed to access cell info");
2970 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002971 if (TelephonyPermissions
2972 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002973 // Safetynet logging for b/154934934
2974 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2975 }
Nathan Harold5320c422019-05-09 10:26:08 -07002976 try {
2977 cb.onCellInfo(new ArrayList<CellInfo>());
2978 } catch (RemoteException re) {
2979 // Drop without consequences
2980 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002981 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002982 }
2983
Nathan Harolda939a962019-05-09 10:13:47 -07002984
2985 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002986 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2987
2988 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2989 }
2990
2991 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002992 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002993 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002994 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995
2996 final long identity = Binder.clearCallingIdentity();
2997 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002998 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 } finally {
3000 Binder.restoreCallingIdentity(identity);
3001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003002 }
3003
Shishir Agrawala9f32182016-04-12 12:00:16 -07003004 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003005 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003006 Phone phone = PhoneFactory.getPhone(slotIndex);
3007 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003008 return null;
3009 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003010 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003011 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003012 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003013 return null;
3014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015
3016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 return phone.getImei();
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003022 }
3023
3024 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003025 public String getTypeAllocationCodeForSlot(int slotIndex) {
3026 Phone phone = PhoneFactory.getPhone(slotIndex);
3027 String tac = null;
3028 if (phone != null) {
3029 String imei = phone.getImei();
3030 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3031 }
3032 return tac;
3033 }
3034
3035 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003036 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003037 Phone phone = PhoneFactory.getPhone(slotIndex);
3038 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003039 return null;
3040 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003041
Jeff Davidson913390f2018-02-23 17:11:49 -08003042 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003043 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003044 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003045 return null;
3046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047
3048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 return phone.getMeid();
3051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
Jack Yu2af8d712017-03-15 17:14:14 -07003054 }
3055
3056 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003057 public String getManufacturerCodeForSlot(int slotIndex) {
3058 Phone phone = PhoneFactory.getPhone(slotIndex);
3059 String manufacturerCode = null;
3060 if (phone != null) {
3061 String meid = phone.getMeid();
3062 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3063 }
3064 return manufacturerCode;
3065 }
3066
3067 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003068 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3069 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003070 Phone phone = PhoneFactory.getPhone(slotIndex);
3071 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003072 return null;
3073 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003074 int subId = phone.getSubId();
3075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003076 mApp, subId, callingPackage, callingFeatureId,
3077 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003078 return null;
3079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080
3081 final long identity = Binder.clearCallingIdentity();
3082 try {
3083 return phone.getDeviceSvn();
3084 } finally {
3085 Binder.restoreCallingIdentity(identity);
3086 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003087 }
3088
fionaxu43304da2017-11-27 22:51:16 -08003089 @Override
3090 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003091 final long identity = Binder.clearCallingIdentity();
3092 try {
3093 final Phone phone = getPhone(subId);
3094 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3095 } finally {
3096 Binder.restoreCallingIdentity(identity);
3097 }
fionaxu43304da2017-11-27 22:51:16 -08003098 }
3099
3100 @Override
3101 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 final Phone phone = getPhone(subId);
3105 return phone == null ? null : phone.getCarrierName();
3106 } finally {
3107 Binder.restoreCallingIdentity(identity);
3108 }
fionaxu43304da2017-11-27 22:51:16 -08003109 }
3110
calvinpanffe225e2018-11-01 19:43:06 +08003111 @Override
chen xu0026ca62019-03-06 15:28:50 -08003112 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 final Phone phone = getPhone(subId);
3116 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003117 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003118 } finally {
3119 Binder.restoreCallingIdentity(identity);
3120 }
3121 }
3122
3123 @Override
chen xu0026ca62019-03-06 15:28:50 -08003124 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003128 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
3132 }
3133
chen xu651eec72018-11-11 19:03:44 -08003134 @Override
chen xu864e11c2018-12-06 22:10:03 -08003135 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3136 if (!isSubscriptionMccMnc) {
3137 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3138 }
chen xu651eec72018-11-11 19:03:44 -08003139 final Phone phone = PhoneFactory.getPhone(slotIndex);
3140 if (phone == null) {
3141 return TelephonyManager.UNKNOWN_CARRIER_ID;
3142 }
3143 final long identity = Binder.clearCallingIdentity();
3144 try {
3145 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
3148 }
3149 }
3150
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003151 //
3152 // Internal helper methods.
3153 //
3154
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003155 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003156 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3157 *
3158 * @throws SecurityException if the caller does not have the required permission
3159 */
3160 private void enforceModifyPermission() {
3161 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3162 }
3163
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003164 /**
3165 * Make sure the caller is system.
3166 *
3167 * @throws SecurityException if the caller is not system.
3168 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003169 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003170 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3171 throw new SecurityException("Caller must be system");
3172 }
3173 }
3174
Shuo Qianf2b2df42019-11-13 17:43:31 -08003175 private void enforceActiveEmergencySessionPermission() {
3176 mApp.enforceCallingOrSelfPermission(
3177 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3178 }
3179
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003180 /**
3181 * Make sure the caller has the CALL_PHONE permission.
3182 *
3183 * @throws SecurityException if the caller does not have the required permission
3184 */
3185 private void enforceCallPermission() {
3186 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3187 }
3188
paulhu423b5f22019-08-23 19:17:33 +08003189 private void enforceSettingsPermission() {
3190 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003191 }
3192
Michele Berionned9fbae52020-11-13 02:36:59 +00003193 private void enforceRebootPermission() {
3194 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3195 }
3196
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 private String createTelUrl(String number) {
3198 if (TextUtils.isEmpty(number)) {
3199 return null;
3200 }
3201
Jake Hambye994d462014-02-03 13:10:13 -08003202 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 }
3204
Ihab Awadf9e92732013-12-05 18:02:52 -08003205 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003206 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3207 }
3208
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003209 private static void logv(String msg) {
3210 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3211 }
3212
Ihab Awadf9e92732013-12-05 18:02:52 -08003213 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3215 }
3216
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003217 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003218 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003219 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003220 }
3221
Sanket Padawe356d7632015-06-22 14:03:32 -07003222 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003223 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 final Phone phone = PhoneFactory.getPhone(slotIndex);
3227 if (phone == null) {
3228 return PhoneConstants.PHONE_TYPE_NONE;
3229 } else {
3230 return phone.getPhoneType();
3231 }
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003235 }
3236
3237 /**
3238 * Returns the CDMA ERI icon index to display
3239 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003240 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003241 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3242 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3243 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003244 }
3245
Sanket Padawe356d7632015-06-22 14:03:32 -07003246 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003247 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3248 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003250 mApp, subId, callingPackage, callingFeatureId,
3251 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003252 return -1;
3253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254
3255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 final Phone phone = getPhone(subId);
3258 if (phone != null) {
3259 return phone.getCdmaEriIconIndex();
3260 } else {
3261 return -1;
3262 }
3263 } finally {
3264 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003266 }
3267
3268 /**
3269 * Returns the CDMA ERI icon mode,
3270 * 0 - ON
3271 * 1 - FLASHING
3272 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003273 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003274 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3275 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3276 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003277 }
3278
Sanket Padawe356d7632015-06-22 14:03:32 -07003279 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003280 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3281 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003283 mApp, subId, callingPackage, callingFeatureId,
3284 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003285 return -1;
3286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003287
3288 final long identity = Binder.clearCallingIdentity();
3289 try {
3290 final Phone phone = getPhone(subId);
3291 if (phone != null) {
3292 return phone.getCdmaEriIconMode();
3293 } else {
3294 return -1;
3295 }
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003299 }
3300
3301 /**
3302 * Returns the CDMA ERI text,
3303 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003304 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003305 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3306 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3307 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003308 }
3309
Sanket Padawe356d7632015-06-22 14:03:32 -07003310 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003311 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3312 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003314 mApp, subId, callingPackage, callingFeatureId,
3315 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003316 return null;
3317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318
3319 final long identity = Binder.clearCallingIdentity();
3320 try {
3321 final Phone phone = getPhone(subId);
3322 if (phone != null) {
3323 return phone.getCdmaEriText();
3324 } else {
3325 return null;
3326 }
3327 } finally {
3328 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003330 }
3331
3332 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003333 * Returns the CDMA MDN.
3334 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003335 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003336 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3338 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339
3340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003343 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344 return phone.getLine1Number();
3345 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003346 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347 return null;
3348 }
3349 } finally {
3350 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003351 }
3352 }
3353
3354 /**
3355 * Returns the CDMA MIN.
3356 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003357 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003358 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3360 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003361
3362 final long identity = Binder.clearCallingIdentity();
3363 try {
3364 final Phone phone = getPhone(subId);
3365 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3366 return phone.getCdmaMin();
3367 } else {
3368 return null;
3369 }
3370 } finally {
3371 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003372 }
3373 }
3374
Hall Liud892bec2018-11-30 14:51:45 -08003375 @Override
3376 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3377 INumberVerificationCallback callback, String callingPackage) {
3378 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3379 != PERMISSION_GRANTED) {
3380 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3381 }
3382 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3383
3384 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3385 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003386 throw new SecurityException("Calling package must be configured in the device config: "
3387 + "calling package: " + callingPackage
3388 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003389 }
3390
3391 if (range == null) {
3392 throw new NullPointerException("Range must be non-null");
3393 }
3394
3395 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003396 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003397
3398 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3399 }
3400
Junda Liuca05d5d2014-08-14 22:36:34 -07003401 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003402 * Returns true if CDMA provisioning needs to run.
3403 */
3404 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405 final long identity = Binder.clearCallingIdentity();
3406 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003407 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003411 }
3412
3413 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003414 * Sets the voice mail number of a given subId.
3415 */
3416 @Override
3417 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003418 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3419 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3424 new Pair<String, String>(alphaTag, number), new Integer(subId));
3425 return success;
3426 } finally {
3427 Binder.restoreCallingIdentity(identity);
3428 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003429 }
3430
Ta-wei Yen87c49842016-05-13 21:19:52 -07003431 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003432 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3433 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003434 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3435 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003436 if (!TextUtils.equals(callingPackage, systemDialer)) {
3437 throw new SecurityException("caller must be system dialer");
3438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003439
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
3442 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3443 if (phoneAccountHandle == null) {
3444 return null;
3445 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003446 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447 } finally {
3448 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003449 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003450 }
3451
3452 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003453 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3454 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003457 mApp, subId, callingPackage, callingFeatureId,
3458 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003459 return null;
3460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003462 final long identity = Binder.clearCallingIdentity();
3463 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003468 }
3469
3470 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003471 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3472 VisualVoicemailSmsFilterSettings settings) {
3473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003474
3475 final long identity = Binder.clearCallingIdentity();
3476 try {
3477 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003482 }
3483
3484 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003485 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3486 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003487
3488 final long identity = Binder.clearCallingIdentity();
3489 try {
3490 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003491 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492 } finally {
3493 Binder.restoreCallingIdentity(identity);
3494 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003495 }
3496
3497 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003498 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3499 String callingPackage, int subId) {
3500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003501
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003505 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003509 }
3510
3511 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003512 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514
3515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003518 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003519 } finally {
3520 Binder.restoreCallingIdentity(identity);
3521 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003522 }
3523
3524 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003525 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3526 String callingAttributionTag, int subId, String number, int port, String text,
3527 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003529 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003530 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003531 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003532 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3533 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003534 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003535
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003536 /**
fionaxu0152e512016-11-14 13:36:14 -08003537 * Sets the voice activation state of a given subId.
3538 */
3539 @Override
3540 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3542 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 final Phone phone = getPhone(subId);
3547 if (phone != null) {
3548 phone.setVoiceActivationState(activationState);
3549 } else {
3550 loge("setVoiceActivationState fails with invalid subId: " + subId);
3551 }
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003554 }
3555 }
3556
3557 /**
3558 * Sets the data activation state of a given subId.
3559 */
3560 @Override
3561 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3563 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003564
3565 final long identity = Binder.clearCallingIdentity();
3566 try {
3567 final Phone phone = getPhone(subId);
3568 if (phone != null) {
3569 phone.setDataActivationState(activationState);
3570 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003571 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572 }
3573 } finally {
3574 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003575 }
3576 }
3577
3578 /**
3579 * Returns the voice activation state of a given subId.
3580 */
3581 @Override
3582 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584
fionaxu0152e512016-11-14 13:36:14 -08003585 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 if (phone != null) {
3589 return phone.getVoiceActivationState();
3590 } else {
3591 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3592 }
3593 } finally {
3594 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003595 }
3596 }
3597
3598 /**
3599 * Returns the data activation state of a given subId.
3600 */
3601 @Override
3602 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003603 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604
fionaxu0152e512016-11-14 13:36:14 -08003605 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 if (phone != null) {
3609 return phone.getDataActivationState();
3610 } else {
3611 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3612 }
3613 } finally {
3614 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003615 }
3616 }
3617
3618 /**
Wink Saville36469e72014-06-11 15:17:00 -07003619 * Returns the unread count of voicemails for a subId
3620 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003621 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003622 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3623 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003625 mApp, subId, callingPackage, callingFeatureId,
3626 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003627 return 0;
3628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629 final long identity = Binder.clearCallingIdentity();
3630 try {
3631 final Phone phone = getPhone(subId);
3632 if (phone != null) {
3633 return phone.getVoiceMessageCount();
3634 } else {
3635 return 0;
3636 }
3637 } finally {
3638 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003640 }
3641
3642 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003643 * returns true, if the device is in a state where both voice and data
3644 * are supported simultaneously. This can change based on location or network condition.
3645 */
3646 @Override
3647 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 final Phone phone = getPhone(subId);
3651 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3652 } finally {
3653 Binder.restoreCallingIdentity(identity);
3654 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003655 }
3656
3657 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003658 * Send the dialer code if called from the current default dialer or the caller has
3659 * carrier privilege.
3660 * @param inputCode The dialer code to send
3661 */
3662 @Override
3663 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003664 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003666 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3667 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003668 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003669 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003670 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003675 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
fionaxu235cc5e2017-03-06 22:25:57 -08003679 }
3680
Pengquan Menga1bb6272018-09-06 09:59:22 -07003681 @Override
3682 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003683 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07003684 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003685 mApp, subId, "getNetworkSelectionMode");
3686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 if (!isActiveSubscription(subId)) {
3689 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3690 }
3691 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3692 } finally {
3693 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003694 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003695 }
3696
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003698 public boolean isInEmergencySmsMode() {
3699 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 for (Phone phone : PhoneFactory.getPhones()) {
3703 if (phone.isInEmergencySmsMode()) {
3704 return true;
3705 }
3706 }
3707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
3710 return false;
3711 }
3712
shilu366312e2019-12-17 09:28:10 -08003713 /**
3714 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3715 * @param subId The subscription to use to check the configuration.
3716 * @param c The callback that will be used to send the result.
3717 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003718 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003719 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3720 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003721 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003722 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003723
Brad Ebinger77b832e2019-10-17 17:03:22 -07003724 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3725 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3726 "IMS not available on device.");
3727 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003728 final long token = Binder.clearCallingIdentity();
3729 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003730 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003731 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003732 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003733 } catch (ImsException e) {
3734 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003735 } finally {
3736 Binder.restoreCallingIdentity(token);
3737 }
3738 }
3739
shilu366312e2019-12-17 09:28:10 -08003740 /**
3741 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3742 * @param subId The subscription to use to check the configuration.
3743 * @param c The callback that will be used to send the result.
3744 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003745 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003746 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003747 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003748 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003749 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3750 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3751 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003752 final long token = Binder.clearCallingIdentity();
3753 try {
3754 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3755 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3756 .removeRegistrationCallbackForSubscription(c, subId);
3757 } catch (ImsException e) {
3758 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3759 + "is inactive, ignoring unregister.");
3760 // If the subscription is no longer active, just return, since the callback
3761 // will already have been removed internally.
3762 } finally {
3763 Binder.restoreCallingIdentity(token);
3764 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003765 }
3766
Brad Ebinger774ba362019-10-22 17:36:18 -07003767 /**
3768 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3769 */
3770 @Override
3771 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3772 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3773 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3774 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3775 "IMS not available on device.");
3776 }
3777 final long token = Binder.clearCallingIdentity();
3778 try {
3779 Phone phone = getPhone(subId);
3780 if (phone == null) {
3781 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3782 + subId + "'");
3783 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3784 }
3785 phone.getImsRegistrationState(regState -> {
3786 try {
3787 consumer.accept((regState == null)
3788 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3789 } catch (RemoteException e) {
3790 // Ignore if the remote process is no longer available to call back.
3791 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3792 }
3793 });
3794 } finally {
3795 Binder.restoreCallingIdentity(token);
3796 }
3797 }
3798
3799 /**
3800 * Get the transport type for the IMS service registration state.
3801 */
3802 @Override
3803 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003804 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003805 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003806 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3807 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3808 "IMS not available on device.");
3809 }
3810 final long token = Binder.clearCallingIdentity();
3811 try {
3812 Phone phone = getPhone(subId);
3813 if (phone == null) {
3814 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3815 + subId + "'");
3816 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3817 }
3818 phone.getImsRegistrationTech(regTech -> {
3819 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3820 int regTechConverted = (regTech == null)
3821 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3822 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3823 regTechConverted);
3824 try {
3825 consumer.accept(regTechConverted);
3826 } catch (RemoteException e) {
3827 // Ignore if the remote process is no longer available to call back.
3828 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3829 }
3830 });
3831 } finally {
3832 Binder.restoreCallingIdentity(token);
3833 }
3834 }
3835
shilu366312e2019-12-17 09:28:10 -08003836 /**
3837 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3838 * @param subId The subscription to use to check the configuration.
3839 * @param c The callback that will be used to send the result.
3840 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003841 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003842 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3843 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003844 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003845 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003846 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3847 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3848 "IMS not available on device.");
3849 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003850 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3851 final long token = Binder.clearCallingIdentity();
3852 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003853 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003854 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003855 } catch (ImsException e) {
3856 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003857 } finally {
3858 Binder.restoreCallingIdentity(token);
3859 }
3860 }
3861
shilu366312e2019-12-17 09:28:10 -08003862 /**
3863 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3864 * @param subId The subscription to use to check the configuration.
3865 * @param c The callback that will be used to send the result.
3866 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003867 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003868 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003869 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003870 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003871 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3872 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3873 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003874
3875 final long token = Binder.clearCallingIdentity();
3876 try {
3877 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3878 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003879 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003880 } catch (ImsException e) {
3881 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3882 + "is inactive, ignoring unregister.");
3883 // If the subscription is no longer active, just return, since the callback
3884 // will already have been removed internally.
3885 } finally {
3886 Binder.restoreCallingIdentity(token);
3887 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003888 }
3889
3890 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003891 public boolean isCapable(int subId, int capability, int regTech) {
3892 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3894 final long token = Binder.clearCallingIdentity();
3895 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003896 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003897 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003898 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3900 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003901 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003902 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3903 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003904 } finally {
3905 Binder.restoreCallingIdentity(token);
3906 }
3907 }
3908
3909 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003910 public boolean isAvailable(int subId, int capability, int regTech) {
3911 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 final long token = Binder.clearCallingIdentity();
3913 try {
3914 Phone phone = getPhone(subId);
3915 if (phone == null) return false;
3916 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003917 } catch (com.android.ims.ImsException e) {
3918 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3919 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003920 } finally {
3921 Binder.restoreCallingIdentity(token);
3922 }
3923 }
3924
Brad Ebinger77b832e2019-10-17 17:03:22 -07003925 /**
3926 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3927 * subscription.
3928 * @param subId The subscription to use to check the configuration.
3929 * @param callback The callback that will be used to send the result.
3930 * @param capability The MmTelFeature capability that will be used to send the result.
3931 * @param transportType The transport type of the MmTelFeature capability.
3932 */
3933 @Override
3934 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3935 int transportType) {
3936 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3937 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3938 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3939 "IMS not available on device.");
3940 }
3941 final long token = Binder.clearCallingIdentity();
3942 try {
3943 int slotId = getSlotIndex(subId);
3944 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3945 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3946 + subId + "'");
3947 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3948 }
3949 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3950 transportType, aBoolean -> {
3951 try {
3952 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3953 } catch (RemoteException e) {
3954 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3955 + "running. Ignore");
3956 }
3957 });
3958 } finally {
3959 Binder.restoreCallingIdentity(token);
3960 }
3961 }
3962
shilu366312e2019-12-17 09:28:10 -08003963 /**
3964 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3965 * @param subId The subscription to use to check the configuration.
3966 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003967 @Override
3968 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003969 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003970 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003971
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3973 final long token = Binder.clearCallingIdentity();
3974 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003975 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003977 } catch (ImsException e) {
3978 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 } finally {
3980 Binder.restoreCallingIdentity(token);
3981 }
3982 }
3983
3984 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003985 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003987 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003991 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003993 } catch (ImsException e) {
3994 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 } finally {
3996 Binder.restoreCallingIdentity(identity);
3997 }
3998 }
3999
shilu366312e2019-12-17 09:28:10 -08004000 /**
4001 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4002 * @param subId The subscription to use to check the configuration.
4003 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004005 public boolean isVtSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004006 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004007 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004011 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4012 } catch (ImsException e) {
4013 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 } finally {
4015 Binder.restoreCallingIdentity(identity);
4016 }
4017 }
4018
4019 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004020 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004022 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004026 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004027 } catch (ImsException e) {
4028 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 } finally {
4030 Binder.restoreCallingIdentity(identity);
4031 }
4032 }
4033
shilu366312e2019-12-17 09:28:10 -08004034 /**
4035 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4036 * @param subId The subscription to use to check the configuration.
4037 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 @Override
4039 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004040 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004041 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 final long identity = Binder.clearCallingIdentity();
4043 try {
4044 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004045 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004047 } catch (ImsException e) {
4048 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 } finally {
4050 Binder.restoreCallingIdentity(identity);
4051 }
4052 }
4053
4054 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004055 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004057 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 final long identity = Binder.clearCallingIdentity();
4059 try {
4060 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004061 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004062 } catch (ImsException e) {
4063 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004064 } finally {
4065 Binder.restoreCallingIdentity(identity);
4066 }
4067 }
4068
shilu366312e2019-12-17 09:28:10 -08004069 /**
4070 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4071 * @param subId The subscription to use to check the configuration.
4072 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 @Override
4074 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004075 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004076 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004080 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004082 } catch (ImsException e) {
4083 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 } finally {
4085 Binder.restoreCallingIdentity(identity);
4086 }
4087 }
4088
4089 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004090 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004092 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004096 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004097 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004098 } catch (ImsException e) {
4099 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 } finally {
4101 Binder.restoreCallingIdentity(identity);
4102 }
4103 }
4104
4105 @Override
4106 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4108 "setVoWiFiNonPersistent");
4109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004112 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004113 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004114 } catch (ImsException e) {
4115 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 } finally {
4117 Binder.restoreCallingIdentity(identity);
4118 }
4119 }
4120
shilu366312e2019-12-17 09:28:10 -08004121 /**
4122 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4123 * @param subId The subscription to use to check the configuration.
4124 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004125 @Override
4126 public int getVoWiFiModeSetting(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004127 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004128 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004129 final long identity = Binder.clearCallingIdentity();
4130 try {
4131 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004132 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004134 } catch (ImsException e) {
4135 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 } finally {
4137 Binder.restoreCallingIdentity(identity);
4138 }
4139 }
4140
4141 @Override
4142 public void setVoWiFiModeSetting(int subId, int mode) {
4143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4144 "setVoWiFiModeSetting");
4145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004148 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004150 } catch (ImsException e) {
4151 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
4155 }
4156
4157 @Override
4158 public int getVoWiFiRoamingModeSetting(int subId) {
4159 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004163 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004165 } catch (ImsException e) {
4166 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 } finally {
4168 Binder.restoreCallingIdentity(identity);
4169 }
4170 }
4171
4172 @Override
4173 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4175 "setVoWiFiRoamingModeSetting");
4176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004179 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004181 } catch (ImsException e) {
4182 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
4186 }
4187
4188 @Override
4189 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4190 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4191 "setRttCapabilityEnabled");
4192 final long identity = Binder.clearCallingIdentity();
4193 try {
4194 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004195 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4196 } catch (ImsException e) {
4197 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 } finally {
4199 Binder.restoreCallingIdentity(identity);
4200 }
4201 }
4202
shilu366312e2019-12-17 09:28:10 -08004203 /**
4204 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4205 * @param subId The subscription to use to check the configuration.
4206 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 @Override
4208 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004209 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004210 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 final long identity = Binder.clearCallingIdentity();
4212 try {
4213 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004214 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004216 } catch (ImsException e) {
4217 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004218 } finally {
4219 Binder.restoreCallingIdentity(identity);
4220 }
4221 }
4222
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004223 @Override
4224 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4225 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4226 final long identity = Binder.clearCallingIdentity();
4227 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004228 if (!isImsAvailableOnDevice()) {
4229 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4230 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004231 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004232 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004233 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004234 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004235 } catch (ImsException e) {
4236 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004237 } finally {
4238 Binder.restoreCallingIdentity(identity);
4239 }
4240 }
4241
4242 @Override
4243 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4244 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4245 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004246 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4247 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4248 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004249 try {
4250 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004251 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004252 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004253 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004254 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4255 + "is inactive, ignoring unregister.");
4256 // If the subscription is no longer active, just return, since the callback will already
4257 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004258 } finally {
4259 Binder.restoreCallingIdentity(identity);
4260 }
4261 }
4262
allenwtsu99c623b2020-01-03 18:24:23 +08004263
4264 private void checkModifyPhoneStatePermission(int subId, String message) {
4265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4266 message);
4267 }
4268
4269 private boolean isImsProvisioningRequired(int subId, int capability,
4270 boolean isMmtelCapability) {
4271 Phone phone = getPhone(subId);
4272 if (phone == null) {
4273 loge("phone instance null for subid " + subId);
4274 return false;
4275 }
4276 if (isMmtelCapability) {
4277 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4278 return false;
4279 }
4280 } else {
4281 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4282 return false;
4283 }
4284 }
4285 return true;
4286 }
4287
4288 @Override
4289 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4290 boolean isProvisioned) {
4291 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4292
4293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4296 if (!isImsProvisioningRequired(subId, capability, false)) {
4297 return;
4298 }
4299
4300 // this capability requires provisioning, route to the correct API.
4301 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4302 switch (capability) {
4303 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4304 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4305 ims.setEabProvisioned(isProvisioned);
4306 break;
4307 default: {
4308 throw new IllegalArgumentException("Tried to set provisioning for "
4309 + "rcs capability '" + capability + "', which does not require "
4310 + "provisioning.");
4311 }
4312 }
4313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
4316
4317 }
4318
4319
4320 @Override
4321 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4322 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4326 if (!isImsProvisioningRequired(subId, capability, false)) {
4327 return true;
4328 }
4329
4330 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4331 switch (capability) {
4332 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4333 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4334 return ims.isEabProvisionedOnDevice();
4335
4336 default: {
4337 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4338 + "capability '" + capability + "', which does not require "
4339 + "provisioning.");
4340 }
4341 }
4342
4343 } finally {
4344 Binder.restoreCallingIdentity(identity);
4345 }
4346 }
4347
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004348 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004349 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4350 boolean isProvisioned) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004351 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4352 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004353 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4354 }
allenwtsu99c623b2020-01-03 18:24:23 +08004355 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004356 final long identity = Binder.clearCallingIdentity();
4357 try {
4358 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004359 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004360 return;
4361 }
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004362 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4363 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4364 loge("setImsProvisioningStatusForCapability: called for technology that does "
4365 + "not support provisioning - " + tech);
4366 return;
4367 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004368
4369 // this capability requires provisioning, route to the correct API.
4370 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4371 switch (capability) {
4372 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4373 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4374 ims.setVolteProvisioned(isProvisioned);
4375 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4376 ims.setWfcProvisioned(isProvisioned);
4377 }
4378 break;
4379 }
4380 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4381 // There is currently no difference in VT provisioning type.
4382 ims.setVtProvisioned(isProvisioned);
4383 break;
4384 }
4385 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4386 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4387 // change the capability of the feature instead if needed.
4388 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4389 == isProvisioned) {
4390 // No change in provisioning.
4391 return;
4392 }
4393 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4394 try {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004395 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004396 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004397 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4398 + ", Exception" + e.getMessage());
4399 }
4400 break;
4401 }
4402 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004403 throw new IllegalArgumentException("Tried to set provisioning for "
4404 + "MmTel capability '" + capability + "', which does not require "
4405 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004406 }
4407 }
4408
4409 } finally {
4410 Binder.restoreCallingIdentity(identity);
4411 }
4412 }
4413
4414 @Override
4415 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004416 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4417 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004418 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4419 }
4420 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4421 final long identity = Binder.clearCallingIdentity();
4422 try {
4423 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004424 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004425 return true;
4426 }
4427
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004428 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4429 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4430 loge("getImsProvisioningStatusForCapability: called for technology that does "
4431 + "not support provisioning - " + tech);
4432 return true;
4433 }
4434
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004435 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4436 switch (capability) {
4437 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4438 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4439 return ims.isVolteProvisionedOnDevice();
4440 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4441 return ims.isWfcProvisionedOnDevice();
4442 }
4443 // This should never happen, since we are checking tech above to make sure it
4444 // is either LTE or IWLAN.
4445 throw new IllegalArgumentException("Invalid radio technology for voice "
4446 + "capability.");
4447 }
4448 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4449 // There is currently no difference in VT provisioning type.
4450 return ims.isVtProvisionedOnDevice();
4451 }
4452 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4453 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4454 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4455 }
4456 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004457 throw new IllegalArgumentException(
4458 "Tried to get provisioning for MmTel capability '" + capability
4459 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004460 }
4461 }
4462
4463 } finally {
4464 Binder.restoreCallingIdentity(identity);
4465 }
4466 }
4467
4468 @Override
4469 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4470 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4471 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4472 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4473 }
4474 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4475 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4476 return (provisionedBits & capability) > 0;
4477 }
4478
4479 @Override
4480 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4481 boolean isProvisioned) {
4482 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4483 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4484 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4485 }
4486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4487 "setProvisioningStatusForCapability");
4488 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4489 // If the current provisioning status for capability already matches isProvisioned,
4490 // do nothing.
4491 if (((provisionedBits & capability) > 0) == isProvisioned) {
4492 return;
4493 }
4494 if (isProvisioned) {
4495 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4496 } else {
4497 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4498 }
4499 }
4500
4501 /**
4502 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4503 * technology. The bitfield should mirror the bitfield defined by
4504 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4505 */
4506 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4507 String key = getMmTelProvisioningKey(subId, tech);
4508 // Default is no capabilities are provisioned.
4509 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4510 }
4511
4512 /**
4513 * Sets the MmTel capability provisioning bitfield (defined by
4514 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4515 * technology specified.
4516 *
4517 * Note: This is a synchronous command and should not be called on UI thread.
4518 */
4519 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4520 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4521 String key = getMmTelProvisioningKey(subId, tech);
4522 editor.putInt(key, newField);
4523 editor.commit();
4524 }
4525
4526 private static String getMmTelProvisioningKey(int subId, int tech) {
4527 // resulting key is provision_ims_mmtel_{subId}_{tech}
4528 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4529 }
4530
4531 /**
4532 * Query CarrierConfig to see if the specified capability requires provisioning for the
4533 * carrier associated with the subscription id.
4534 */
4535 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4536 int capability) {
4537 CarrierConfigManager configManager = new CarrierConfigManager(context);
4538 PersistableBundle c = configManager.getConfigForSubId(subId);
4539 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004540 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004541 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4542 false);
4543 boolean requireVoiceVtProvisioning = c.getBoolean(
4544 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4545
4546 // First check to make sure that the capability requires provisioning.
4547 switch (capability) {
4548 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4549 // intentional fallthrough
4550 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4551 if (requireVoiceVtProvisioning) {
4552 // Voice and Video requires provisioning
4553 return true;
4554 }
4555 break;
4556 }
4557 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4558 if (requireUtProvisioning) {
4559 // UT requires provisioning
4560 return true;
4561 }
4562 break;
4563 }
4564 }
4565 return false;
4566 }
4567
allenwtsu99c623b2020-01-03 18:24:23 +08004568 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4569 int capability) {
4570 CarrierConfigManager configManager = new CarrierConfigManager(context);
4571 PersistableBundle c = configManager.getConfigForSubId(subId);
4572
4573 boolean requireRcsProvisioning = c.getBoolean(
4574 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4575
4576 // First check to make sure that the capability requires provisioning.
4577 switch (capability) {
4578 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4579 // intentional fallthrough
4580 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4581 if (requireRcsProvisioning) {
4582 // OPTION or PRESENCE requires provisioning
4583 return true;
4584 }
4585 break;
4586 }
4587 }
4588 return false;
4589 }
4590
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004591 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004592 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004593 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4594 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4595 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004596 enforceReadPrivilegedPermission("getImsProvisioningInt");
4597 final long identity = Binder.clearCallingIdentity();
4598 try {
4599 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004600 int slotId = getSlotIndex(subId);
4601 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4602 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4603 + subId + "' for key:" + key);
4604 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4605 }
calvinpan9cfff472021-02-08 19:59:36 +08004606 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004607 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004608 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4609 + subId + "' for key:" + key);
4610 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004611 } finally {
4612 Binder.restoreCallingIdentity(identity);
4613 }
4614 }
4615
4616 @Override
4617 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004618 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4619 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4620 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004621 enforceReadPrivilegedPermission("getImsProvisioningString");
4622 final long identity = Binder.clearCallingIdentity();
4623 try {
4624 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004625 int slotId = getSlotIndex(subId);
4626 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4627 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4628 + subId + "' for key:" + key);
4629 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4630 }
calvinpan9cfff472021-02-08 19:59:36 +08004631 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004632 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004633 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4634 + subId + "' for key:" + key);
4635 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004636 } finally {
4637 Binder.restoreCallingIdentity(identity);
4638 }
4639 }
4640
4641 @Override
4642 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004643 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4644 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4645 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4647 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004648 final long identity = Binder.clearCallingIdentity();
4649 try {
4650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004651 int slotId = getSlotIndex(subId);
4652 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4653 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4654 + subId + "' for key:" + key);
4655 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4656 }
calvinpan9cfff472021-02-08 19:59:36 +08004657 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4658 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004659 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004660 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004661 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004662 } finally {
4663 Binder.restoreCallingIdentity(identity);
4664 }
4665 }
4666
4667 @Override
4668 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4670 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4671 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4673 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004674 final long identity = Binder.clearCallingIdentity();
4675 try {
4676 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004677 int slotId = getSlotIndex(subId);
4678 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4679 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4680 + subId + "' for key:" + key);
4681 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4682 }
calvinpan9cfff472021-02-08 19:59:36 +08004683 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4684 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004685 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004686 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004687 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004688 } finally {
4689 Binder.restoreCallingIdentity(identity);
4690 }
4691 }
4692
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004693 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004694 int slotId = SubscriptionManager.getSlotIndex(subId);
4695 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004696 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4697 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004698 }
4699 return slotId;
4700 }
4701
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004702 private int getSlotIndex(int subId) {
4703 int slotId = SubscriptionManager.getSlotIndex(subId);
4704 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4705 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4706 }
4707 return slotId;
4708 }
4709
Wink Saville36469e72014-06-11 15:17:00 -07004710 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004711 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004712 */
4713 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004714 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4715 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004716 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004717 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004718 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004719 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004720 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004721 mApp, subId, callingPackage, callingFeatureId,
4722 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004723 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4724 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004725
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726 final long identity = Binder.clearCallingIdentity();
4727 try {
4728 final Phone phone = getPhone(subId);
4729 if (phone != null) {
4730 return phone.getServiceState().getDataNetworkType();
4731 } else {
4732 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4733 }
4734 } finally {
4735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004737 }
4738
4739 /**
4740 * Returns the data network type
4741 */
4742 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004743 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004744 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4745 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004746 }
4747
4748 /**
4749 * Returns the data network type for a subId
4750 */
4751 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004752 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4753 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004755 mApp, subId, callingPackage, callingFeatureId,
4756 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004757 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4758 }
4759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 final long identity = Binder.clearCallingIdentity();
4761 try {
4762 final Phone phone = getPhone(subId);
4763 if (phone != null) {
4764 return phone.getServiceState().getDataNetworkType();
4765 } else {
4766 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4767 }
4768 } finally {
4769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004771 }
4772
4773 /**
Wink Saville36469e72014-06-11 15:17:00 -07004774 * Returns the Voice network type for a subId
4775 */
4776 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004777 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4778 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004779 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004780 mApp, subId, callingPackage, callingFeatureId,
4781 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004782 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4783 }
4784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785 final long identity = Binder.clearCallingIdentity();
4786 try {
4787 final Phone phone = getPhone(subId);
4788 if (phone != null) {
4789 return phone.getServiceState().getVoiceNetworkType();
4790 } else {
4791 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4792 }
4793 } finally {
4794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004796 }
4797
4798 /**
4799 * @return true if a ICC card is present
4800 */
4801 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004802 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004803 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4804 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004805 }
4806
4807 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004808 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004809 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004810 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004811 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812 final long identity = Binder.clearCallingIdentity();
4813 try {
4814 final Phone phone = PhoneFactory.getPhone(slotIndex);
4815 if (phone != null) {
4816 return phone.getIccCard().hasIccCard();
4817 } else {
4818 return false;
4819 }
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004823 }
4824
4825 /**
4826 * Return if the current radio is LTE on CDMA. This
4827 * is a tri-state return value as for a period of time
4828 * the mode may be unknown.
4829 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004830 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004831 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004832 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004833 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004834 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004835 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4836 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4837 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004838 }
4839
Sanket Padawe356d7632015-06-22 14:03:32 -07004840 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004841 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4842 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004843 try {
4844 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4845 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004846 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4847 }
4848
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849 final long identity = Binder.clearCallingIdentity();
4850 try {
4851 final Phone phone = getPhone(subId);
4852 if (phone == null) {
4853 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4854 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004855 return TelephonyProperties.lte_on_cdma_device()
4856 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 }
4858 } finally {
4859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004860 }
Wink Saville36469e72014-06-11 15:17:00 -07004861 }
4862
Wink Saville36469e72014-06-11 15:17:00 -07004863 /**
4864 * {@hide}
4865 * Returns Default subId, 0 in the case of single standby.
4866 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004867 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004868 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004869 }
4870
Shishir Agrawala9f32182016-04-12 12:00:16 -07004871 private int getSlotForDefaultSubscription() {
4872 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4873 }
4874
Wink Savilleb564aae2014-10-23 10:18:09 -07004875 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004876 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004877 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004878
Pengquan Menge92a50d2018-09-21 15:54:48 -07004879 private boolean isActiveSubscription(int subId) {
4880 return mSubscriptionController.isActiveSubId(subId);
4881 }
4882
Ihab Awadf2177b72013-11-25 13:33:23 -08004883 /**
4884 * @see android.telephony.TelephonyManager.WifiCallingChoices
4885 */
4886 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 final long identity = Binder.clearCallingIdentity();
4888 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004889 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4891 getWhenToMakeWifiCallsDefaultPreference());
4892 } finally {
4893 Binder.restoreCallingIdentity(identity);
4894 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004895 }
4896
4897 /**
4898 * @see android.telephony.TelephonyManager.WifiCallingChoices
4899 */
4900 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004901 final long identity = Binder.clearCallingIdentity();
4902 try {
4903 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004904 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4906 } finally {
4907 Binder.restoreCallingIdentity(identity);
4908 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004909 }
4910
Sailesh Nepald1e68152013-12-12 19:08:02 -08004911 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004912 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004913 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004914 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004915
Jordan Liu4c733742019-02-28 12:03:40 -08004916 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4917 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4918 if (phoneId == -1) {
4919 throw new IllegalArgumentException("Given slot index: " + slotIndex
4920 + " does not correspond to an active phone");
4921 }
4922 return PhoneFactory.getPhone(phoneId);
4923 }
4924
Shishir Agrawal566b7612013-10-28 14:41:00 -07004925 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004926 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4927 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4929 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004931 if (DBG) {
4932 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4933 }
4934 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4935 p2);
4936 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004937
Jordan Liu4c733742019-02-28 12:03:40 -08004938
4939 @Override
4940 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4941 int slotIndex, String callingPackage, String aid, int p2) {
4942 enforceModifyPermission();
4943 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4944 if (DBG) {
4945 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4946 }
4947 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4948 callingPackage, aid, p2);
4949 }
4950
4951 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4952 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 final long identity = Binder.clearCallingIdentity();
4954 try {
4955 if (TextUtils.equals(ISDR_AID, aid)) {
4956 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004957 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4958 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 if (bestComponent == null
4960 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4961 loge("The calling package is not allowed to access ISD-R.");
4962 throw new SecurityException(
4963 "The calling package is not allowed to access ISD-R.");
4964 }
Derek Tan740e1672017-06-27 14:56:27 -07004965 }
Derek Tan740e1672017-06-27 14:56:27 -07004966
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004968 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4969 null /* workSource */);
4970 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 return response;
4972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004975 }
4976
4977 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004978 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4980 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004981 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4982 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4983 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004984
Jordan Liu4c733742019-02-28 12:03:40 -08004985 @Override
4986 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4987 enforceModifyPermission();
4988 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4989 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4990 channel);
4991 }
4992
4993 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 final long identity = Binder.clearCallingIdentity();
4995 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996 if (channel < 0) {
4997 return false;
4998 }
Jordan Liu4c733742019-02-28 12:03:40 -08004999 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5000 null /* workSource */);
5001 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 return success;
5003 } finally {
5004 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005005 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005006 }
5007
5008 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005009 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005010 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5012 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005013 if (DBG) {
5014 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5015 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5016 + p3 + " data=" + data);
5017 }
5018 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5019 command, p1, p2, p3, data);
5020 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005021
Jordan Liu4c733742019-02-28 12:03:40 -08005022 @Override
5023 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5024 int command, int p1, int p2, int p3, String data) {
5025 enforceModifyPermission();
5026 if (DBG) {
5027 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5028 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5029 + p3 + " data=" + data);
5030 }
5031 return iccTransmitApduLogicalChannelWithPermission(
5032 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5033 data);
5034 }
5035
5036 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5037 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 final long identity = Binder.clearCallingIdentity();
5039 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005040 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 return "";
5042 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005045 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5046 null /* workSource */);
5047 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 // Append the returned status code to the end of the response payload.
5050 String s = Integer.toHexString(
5051 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5052 if (response.payload != null) {
5053 s = IccUtils.bytesToHexString(response.payload) + s;
5054 }
5055 return s;
5056 } finally {
5057 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005058 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005059 }
Jake Hambye994d462014-02-03 13:10:13 -08005060
Evan Charltonc66da362014-05-16 14:06:40 -07005061 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005062 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5063 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5065 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005067 if (DBG) {
5068 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5069 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5070 }
5071 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5072 cla, command, p1, p2, p3, data);
5073 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005074
Jordan Liu4c733742019-02-28 12:03:40 -08005075 @Override
5076 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5077 int command, int p1, int p2, int p3, String data) {
5078 enforceModifyPermission();
5079 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5080 if (DBG) {
5081 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5082 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5083 + " data=" + data);
5084 }
5085
5086 return iccTransmitApduBasicChannelWithPermission(
5087 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5088 p2, p3, data);
5089 }
5090
5091 // open APDU basic channel assuming the caller has sufficient permissions
5092 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5093 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
5096 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5097 && TextUtils.equals(ISDR_AID, data)) {
5098 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005099 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5100 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005101 if (bestComponent == null
5102 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5103 loge("The calling package is not allowed to select ISD-R.");
5104 throw new SecurityException(
5105 "The calling package is not allowed to select ISD-R.");
5106 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005107 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005108
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005110 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5111 null /* workSource */);
5112 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114 // Append the returned status code to the end of the response payload.
5115 String s = Integer.toHexString(
5116 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5117 if (response.payload != null) {
5118 s = IccUtils.bytesToHexString(response.payload) + s;
5119 }
5120 return s;
5121 } finally {
5122 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005123 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005124 }
5125
5126 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005127 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005128 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5130 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 final long identity = Binder.clearCallingIdentity();
5133 try {
5134 if (DBG) {
5135 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5136 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5137 }
5138
5139 IccIoResult response =
5140 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5141 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5142 subId);
5143
5144 if (DBG) {
5145 log("Exchange SIM_IO [R]" + response);
5146 }
5147
5148 byte[] result = null;
5149 int length = 2;
5150 if (response.payload != null) {
5151 length = 2 + response.payload.length;
5152 result = new byte[length];
5153 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5154 } else {
5155 result = new byte[length];
5156 }
5157
5158 result[length - 1] = (byte) response.sw2;
5159 result[length - 2] = (byte) response.sw1;
5160 return result;
5161 } finally {
5162 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005163 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005164 }
5165
Nathan Haroldb3014052017-01-25 15:57:32 -08005166 /**
5167 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5168 * on a particular subscription
5169 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005170 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5171 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005173 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005174 return null;
5175 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176
5177 final long identity = Binder.clearCallingIdentity();
5178 try {
5179 if (appType != TelephonyManager.APPTYPE_USIM
5180 && appType != TelephonyManager.APPTYPE_SIM) {
5181 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5182 return null;
5183 }
5184 Object response = sendRequest(
5185 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5186 if (response instanceof String[]) {
5187 return (String[]) response;
5188 }
yincheng zhaod698b842019-09-06 17:06:54 -07005189 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005191 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 } finally {
5193 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005194 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005195 }
5196
yincheng zhaod698b842019-09-06 17:06:54 -07005197 /**
5198 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5199 * subscription.
5200 *
5201 * @param subId the id of the subscription.
5202 * @param appType the uicc app type, must be USIM or SIM.
5203 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5204 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005205 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005206 * @return number of fplmns that is successfully written to the SIM.
5207 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005208 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5209 String callingFeatureId) {
5210 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5211 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005212 if (DBG) logv("no permissions for setForbiddenplmns");
5213 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5214 }
5215 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5216 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5217 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5218 }
5219 if (fplmns == null) {
5220 throw new IllegalArgumentException("Fplmn List provided is null");
5221 }
5222 for (String fplmn : fplmns) {
5223 if (!CellIdentity.isValidPlmn(fplmn)) {
5224 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5225 }
5226 }
5227 final long identity = Binder.clearCallingIdentity();
5228 try {
5229 Object response = sendRequest(
5230 CMD_SET_FORBIDDEN_PLMNS,
5231 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5232 subId);
5233 return (int) response;
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
5237 }
5238
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005239 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005240 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005241 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5242 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5247 if (response.payload == null) {
5248 return "";
5249 }
Evan Charltonc66da362014-05-16 14:06:40 -07005250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 // Append the returned status code to the end of the response payload.
5252 String s = Integer.toHexString(
5253 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5254 s = IccUtils.bytesToHexString(response.payload) + s;
5255 return s;
5256 } finally {
5257 Binder.restoreCallingIdentity(identity);
5258 }
Evan Charltonc66da362014-05-16 14:06:40 -07005259 }
5260
Jake Hambye994d462014-02-03 13:10:13 -08005261 /**
5262 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5263 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5264 *
5265 * @param itemID the ID of the item to read
5266 * @return the NV item as a String, or null on error.
5267 */
5268 @Override
5269 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005270 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5272 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273
5274 final long identity = Binder.clearCallingIdentity();
5275 try {
5276 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005277 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5279 return value;
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
Jake Hambye994d462014-02-03 13:10:13 -08005283 }
5284
5285 /**
5286 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5287 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5288 *
5289 * @param itemID the ID of the item to read
5290 * @param itemValue the value to write, as a String
5291 * @return true on success; false on any failure
5292 */
5293 @Override
5294 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005295 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5297 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298
5299 final long identity = Binder.clearCallingIdentity();
5300 try {
5301 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5302 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005303 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005304 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5305 return success;
5306 } finally {
5307 Binder.restoreCallingIdentity(identity);
5308 }
Jake Hambye994d462014-02-03 13:10:13 -08005309 }
5310
5311 /**
5312 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5313 * Used for device configuration by some CDMA operators.
5314 *
5315 * @param preferredRoamingList byte array containing the new PRL
5316 * @return true on success; false on any failure
5317 */
5318 @Override
5319 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5321 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322
5323 final long identity = Binder.clearCallingIdentity();
5324 try {
5325 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5326 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5327 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5328 return success;
5329 } finally {
5330 Binder.restoreCallingIdentity(identity);
5331 }
Jake Hambye994d462014-02-03 13:10:13 -08005332 }
5333
5334 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005335 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005336 * Used for device configuration by some CDMA operators.
5337 *
chen xu6dac5ab2018-10-26 17:39:23 -07005338 * @param slotIndex - device slot.
5339 *
Jake Hambye994d462014-02-03 13:10:13 -08005340 * @return true on success; false on any failure
5341 */
5342 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005343 public boolean resetModemConfig(int slotIndex) {
5344 Phone phone = PhoneFactory.getPhone(slotIndex);
5345 if (phone != null) {
5346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5347 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348
chen xu6dac5ab2018-10-26 17:39:23 -07005349 final long identity = Binder.clearCallingIdentity();
5350 try {
5351 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5352 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5353 return success;
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
5356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 }
chen xu6dac5ab2018-10-26 17:39:23 -07005358 return false;
5359 }
5360
5361 /**
5362 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5363 *
5364 * @param slotIndex - device slot.
5365 *
5366 * @return true on success; false on any failure
5367 */
5368 @Override
5369 public boolean rebootModem(int slotIndex) {
5370 Phone phone = PhoneFactory.getPhone(slotIndex);
5371 if (phone != null) {
5372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5373 mApp, phone.getSubId(), "rebootModem");
5374
5375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5378 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5379 return success;
5380 } finally {
5381 Binder.restoreCallingIdentity(identity);
5382 }
5383 }
5384 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005385 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005386
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005387 public String[] getPcscfAddress(String apnType, String callingPackage,
5388 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005389 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5391 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005392 return new String[0];
5393 }
5394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 final long identity = Binder.clearCallingIdentity();
5396 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005397 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 } finally {
5399 Binder.restoreCallingIdentity(identity);
5400 }
Wink Saville36469e72014-06-11 15:17:00 -07005401 }
5402
Brad Ebinger51f743a2017-01-23 13:50:20 -08005403 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005404 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5405 * {@link #disableIms(int)}.
5406 * @param slotIndex device slot.
5407 */
5408 public void resetIms(int slotIndex) {
5409 enforceModifyPermission();
5410
5411 final long identity = Binder.clearCallingIdentity();
5412 try {
5413 if (mImsResolver == null) {
5414 // may happen if the does not support IMS.
5415 return;
5416 }
5417 mImsResolver.disableIms(slotIndex);
5418 mImsResolver.enableIms(slotIndex);
5419 } finally {
5420 Binder.restoreCallingIdentity(identity);
5421 }
5422 }
5423
5424 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005425 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5426 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005427 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005428 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005429 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430
5431 final long identity = Binder.clearCallingIdentity();
5432 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005433 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005434 // may happen if the device does not support IMS.
5435 return;
5436 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005437 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438 } finally {
5439 Binder.restoreCallingIdentity(identity);
5440 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005441 }
5442
5443 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005444 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5445 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005446 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005447 public void disableIms(int slotId) {
5448 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449
5450 final long identity = Binder.clearCallingIdentity();
5451 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005452 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005453 // may happen if the device does not support IMS.
5454 return;
5455 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005456 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005460 }
5461
5462 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005463 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5464 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005465 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005466 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005467 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005468 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469
5470 final long identity = Binder.clearCallingIdentity();
5471 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005472 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005473 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5474 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005475 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005476 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477 } finally {
5478 Binder.restoreCallingIdentity(identity);
5479 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005480 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005481 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005482 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5483 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005484 @Override
5485 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005486 enforceModifyPermission();
5487
5488 final long identity = Binder.clearCallingIdentity();
5489 try {
5490 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005491 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005492 } finally {
5493 Binder.restoreCallingIdentity(identity);
5494 }
5495 }
5496
5497 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005498 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005499 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005500 */
5501 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5502 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503
5504 final long identity = Binder.clearCallingIdentity();
5505 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005506 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005507 // may happen if the device does not support IMS.
5508 return null;
5509 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005510 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 } finally {
5512 Binder.restoreCallingIdentity(identity);
5513 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005514 }
5515
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005516 /**
5517 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005518 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005519 */
5520 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5521 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522
5523 final long identity = Binder.clearCallingIdentity();
5524 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005525 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005526 // may happen if the device does not support IMS.
5527 return null;
5528 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005529 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005533 }
5534
Brad Ebinger884c07b2018-02-15 16:17:40 -08005535 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005536 * Sets the ImsService Package Name that Telephony will bind to.
5537 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005538 * @param slotIndex the slot ID that the ImsService should bind for.
5539 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005540 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005541 * @param featureTypes An integer array of feature types associated with a packageName.
5542 * @param packageName The name of the package that the current configuration will be replaced
5543 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005544 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005545 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005546 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5547 int[] featureTypes, String packageName) {
5548 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5549 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5551 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005552 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 final long identity = Binder.clearCallingIdentity();
5555 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005556 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005557 // may happen if the device does not support IMS.
5558 return false;
5559 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005560 Map<Integer, String> featureConfig = new HashMap<>();
5561 for (int featureType : featureTypes) {
5562 featureConfig.put(featureType, packageName);
5563 }
5564 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5565 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005569 }
5570
5571 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005572 * Clears any carrier ImsService overrides for the slot index specified that were previously
5573 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5574 *
5575 * This should only be used for testing.
5576 *
5577 * @param slotIndex the slot ID that the ImsService should bind for.
5578 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5579 */
5580 @Override
5581 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5582 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5583 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5584 "clearCarrierImsServiceOverride");
5585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5586 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5587 "clearCarrierImsServiceOverride");
5588
5589 final long identity = Binder.clearCallingIdentity();
5590 try {
5591 if (mImsResolver == null) {
5592 // may happen if the device does not support IMS.
5593 return false;
5594 }
5595 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
5599 }
5600
5601 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005602 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005603 *
5604 * @param slotId The slot that the ImsService is associated with.
5605 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5606 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005607 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005608 * @return the package name of the ImsService configuration.
5609 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005610 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5611 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005612 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005613 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005614 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005615 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5616 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 final long identity = Binder.clearCallingIdentity();
5619 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005620 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005621 // may happen if the device does not support IMS.
5622 return "";
5623 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005624 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005625 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5626 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627 } finally {
5628 Binder.restoreCallingIdentity(identity);
5629 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005630 }
5631
Brad Ebinger77b832e2019-10-17 17:03:22 -07005632 /**
5633 * Get the MmTelFeature state associated with the requested subscription id.
5634 * @param subId The subscription that the MmTelFeature is associated with.
5635 * @param callback A callback with an integer containing the
5636 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5637 */
5638 @Override
5639 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5640 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5641 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5642 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5643 "IMS not available on device.");
5644 }
5645 final long token = Binder.clearCallingIdentity();
5646 try {
5647 int slotId = getSlotIndex(subId);
5648 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5649 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5650 + subId + "'");
5651 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5652 }
5653 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5654 try {
5655 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5656 } catch (RemoteException e) {
5657 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5658 + "Ignore");
5659 }
5660 });
5661 } finally {
5662 Binder.restoreCallingIdentity(token);
5663 }
5664 }
5665
Daniel Brightbb5840b2021-01-12 15:48:18 -08005666 /**
5667 * Sets the ims registration state on all valid {@link Phone}s.
5668 */
5669 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005670 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671
5672 final long identity = Binder.clearCallingIdentity();
5673 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005674 // NOTE: Before S, this method only set the default phone.
5675 for (final Phone phone : PhoneFactory.getPhones()) {
5676 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5677 phone.setImsRegistrationState(registered);
5678 }
5679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 } finally {
5681 Binder.restoreCallingIdentity(identity);
5682 }
Wink Saville36469e72014-06-11 15:17:00 -07005683 }
5684
5685 /**
Stuart Scott54788802015-03-30 13:18:01 -07005686 * Set the network selection mode to automatic.
5687 *
5688 */
5689 @Override
5690 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5692 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693
5694 final long identity = Binder.clearCallingIdentity();
5695 try {
shilufc958392020-01-20 11:36:01 -08005696 if (!isActiveSubscription(subId)) {
5697 return;
5698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005700 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5701 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
Stuart Scott54788802015-03-30 13:18:01 -07005705 }
5706
Jack Yud10cdd42020-09-28 20:28:01 -07005707 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005708 * Ask the radio to connect to the input network and change selection mode to manual.
5709 *
5710 * @param subId the id of the subscription.
5711 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5712 * the operator to attach to.
5713 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5714 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5715 * normal network selection next time.
5716 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005717 */
5718 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005719 public boolean setNetworkSelectionModeManual(
5720 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5722 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005723
5724 if (!isActiveSubscription(subId)) {
5725 return false;
5726 }
5727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 final long identity = Binder.clearCallingIdentity();
5729 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005730 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005732 if (DBG) {
5733 log("setNetworkSelectionModeManual: subId: " + subId
5734 + " operator: " + operatorInfo);
5735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005740 }
shilu84f6e8b2019-12-19 13:58:01 -08005741 /**
5742 * Get the manual network selection
5743 *
5744 * @param subId the id of the subscription.
5745 *
5746 * @return the previously saved user selected PLMN
5747 */
5748 @Override
5749 public String getManualNetworkSelectionPlmn(int subId) {
5750 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005751 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005752 mApp, subId, "getManualNetworkSelectionPlmn");
5753
5754 final long identity = Binder.clearCallingIdentity();
5755 try {
5756 if (!isActiveSubscription(subId)) {
5757 return "";
5758 }
5759
5760 final Phone phone = getPhone(subId);
5761 if (phone == null) {
5762 return "";
5763 }
5764 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5765 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5766 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
5770 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005771
5772 /**
5773 * Scans for available networks.
5774 */
5775 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005776 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5777 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5779 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005780 LocationAccessPolicy.LocationPermissionResult locationResult =
5781 LocationAccessPolicy.checkLocationPermission(mApp,
5782 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5783 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005784 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005785 .setCallingPid(Binder.getCallingPid())
5786 .setCallingUid(Binder.getCallingUid())
5787 .setMethod("getCellNetworkScanResults")
5788 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07005789 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5790 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005791 .build());
5792 switch (locationResult) {
5793 case DENIED_HARD:
5794 throw new SecurityException("Not allowed to access scan results -- location");
5795 case DENIED_SOFT:
5796 return null;
5797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798
Pengquan Menga1bb6272018-09-06 09:59:22 -07005799 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 try {
5801 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005802 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 } finally {
5805 Binder.restoreCallingIdentity(identity);
5806 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005807 }
5808
5809 /**
sqian80370722020-01-29 15:02:51 -08005810 * Get the call forwarding info, given the call forwarding reason.
5811 */
5812 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005813 public void getCallForwarding(int subId, int callForwardingReason,
5814 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005815 enforceReadPrivilegedPermission("getCallForwarding");
5816 long identity = Binder.clearCallingIdentity();
5817 try {
5818 if (DBG) {
5819 log("getCallForwarding: subId " + subId
5820 + " callForwardingReason" + callForwardingReason);
5821 }
Hall Liua1acea22020-09-18 19:04:59 -07005822
5823 Phone phone = getPhone(subId);
5824 if (phone == null) {
5825 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005826 callback.onError(
5827 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005828 } catch (RemoteException e) {
5829 // ignore
5830 }
5831 return;
5832 }
5833
5834 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5835 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5836 @Override
5837 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5838 try {
5839 callback.onCallForwardingInfoAvailable(info);
5840 } catch (RemoteException e) {
5841 // ignore
5842 }
5843 }
5844
5845 @Override
5846 public void onError(int error) {
5847 try {
5848 callback.onError(error);
5849 } catch (RemoteException e) {
5850 // ignore
5851 }
5852 }
5853 });
5854 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005855 } finally {
5856 Binder.restoreCallingIdentity(identity);
5857 }
5858 }
5859
5860 /**
5861 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5862 * reason, the number to forward, and the timeout before the forwarding is attempted.
5863 */
5864 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005865 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5866 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005867 enforceModifyPermission();
5868 long identity = Binder.clearCallingIdentity();
5869 try {
5870 if (DBG) {
5871 log("setCallForwarding: subId " + subId
5872 + " callForwardingInfo" + callForwardingInfo);
5873 }
Hall Liua1acea22020-09-18 19:04:59 -07005874
5875 Phone phone = getPhone(subId);
5876 if (phone == null) {
5877 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005878 callback.accept(
5879 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005880 } catch (RemoteException e) {
5881 // ignore
5882 }
5883 return;
5884 }
5885
5886 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5887 FunctionalUtils.ignoreRemoteException(callback::accept));
5888
5889 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005890 } finally {
5891 Binder.restoreCallingIdentity(identity);
5892 }
5893 }
5894
5895 /**
Hall Liua1acea22020-09-18 19:04:59 -07005896 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005897 */
5898 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005899 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWangc63cf522021-03-31 22:08:45 +08005900 enforceReadPrivilegedPermission("getCallWaitingStatus");
sqian80370722020-01-29 15:02:51 -08005901 long identity = Binder.clearCallingIdentity();
5902 try {
Hall Liua1acea22020-09-18 19:04:59 -07005903 Phone phone = getPhone(subId);
5904 if (phone == null) {
5905 try {
5906 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5907 } catch (RemoteException e) {
5908 // ignore
5909 }
5910 return;
5911 }
SongFerngWangc63cf522021-03-31 22:08:45 +08005912 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5913 PersistableBundle c = configManager.getConfigForSubId(subId);
5914 boolean requireUssd = c.getBoolean(
5915 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005916
sqian80370722020-01-29 15:02:51 -08005917 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWangc63cf522021-03-31 22:08:45 +08005918 if (requireUssd) {
5919 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5920 getSubscriptionCarrierId(subId));
5921 String newUssdCommand = "";
5922 try {
5923 newUssdCommand = carrierXmlParser.getFeature(
5924 CarrierXmlParser.FEATURE_CALL_WAITING)
5925 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
5926 } catch (NullPointerException e) {
5927 loge("Failed to generate USSD number" + e);
5928 }
5929 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5930 mMainThreadHandler, callback, carrierXmlParser,
5931 CarrierXmlParser.SsEntry.SSAction.QUERY);
5932 final String ussdCommand = newUssdCommand;
5933 Executors.newSingleThreadExecutor().execute(() -> {
5934 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5935 });
5936 } else {
5937 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
5938 callback::accept);
5939 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
5940 }
sqian80370722020-01-29 15:02:51 -08005941 } finally {
5942 Binder.restoreCallingIdentity(identity);
5943 }
5944 }
5945
5946 /**
Hall Liua1acea22020-09-18 19:04:59 -07005947 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005948 */
5949 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005950 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005951 enforceModifyPermission();
5952 long identity = Binder.clearCallingIdentity();
5953 try {
Hall Liua1acea22020-09-18 19:04:59 -07005954 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5955
5956 Phone phone = getPhone(subId);
5957 if (phone == null) {
5958 try {
5959 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5960 } catch (RemoteException e) {
5961 // ignore
5962 }
5963 return;
5964 }
5965
SongFerngWangc63cf522021-03-31 22:08:45 +08005966 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5967 PersistableBundle c = configManager.getConfigForSubId(subId);
5968 boolean requireUssd = c.getBoolean(
5969 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005970
SongFerngWangc63cf522021-03-31 22:08:45 +08005971 if (DBG) log("getCallWaitingStatus: subId " + subId);
5972 if (requireUssd) {
5973 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5974 getSubscriptionCarrierId(subId));
5975 CarrierXmlParser.SsEntry.SSAction ssAction =
5976 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
5977 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
5978 String newUssdCommand = "";
5979 try {
5980 newUssdCommand = carrierXmlParser.getFeature(
5981 CarrierXmlParser.FEATURE_CALL_WAITING)
5982 .makeCommand(ssAction, null);
5983 } catch (NullPointerException e) {
5984 loge("Failed to generate USSD number" + e);
5985 }
5986 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5987 mMainThreadHandler, callback, carrierXmlParser, ssAction);
5988 final String ussdCommand = newUssdCommand;
5989 Executors.newSingleThreadExecutor().execute(() -> {
5990 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5991 });
5992 } else {
5993 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5994 FunctionalUtils.ignoreRemoteException(callback::accept));
5995
5996 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
5997 }
sqian80370722020-01-29 15:02:51 -08005998 } finally {
5999 Binder.restoreCallingIdentity(identity);
6000 }
6001 }
6002
6003 /**
yinxub1bed742017-04-17 11:45:04 -07006004 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006005 *
yinxub1bed742017-04-17 11:45:04 -07006006 * @param subId id of the subscription
6007 * @param request contains the radio access networks with bands/channels to scan
6008 * @param messenger callback messenger for scan results or errors
6009 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006010 * @return the id of the requested scan which can be used to stop the scan.
6011 */
6012 @Override
6013 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006014 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6016 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006017 LocationAccessPolicy.LocationPermissionResult locationResult =
6018 LocationAccessPolicy.checkLocationPermission(mApp,
6019 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6020 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006021 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006022 .setCallingPid(Binder.getCallingPid())
6023 .setCallingUid(Binder.getCallingUid())
6024 .setMethod("requestNetworkScan")
6025 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6026 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006027 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07006028 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6029 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006030 if (e != null) {
6031 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6032 throw e;
6033 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006034 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006035 return TelephonyScanManager.INVALID_SCAN_ID;
6036 }
6037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 }
Hall Liu912dfd32019-04-25 14:02:26 -07006039 int callingUid = Binder.getCallingUid();
6040 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006041 final long identity = Binder.clearCallingIdentity();
6042 try {
6043 return mNetworkScanRequestTracker.startNetworkScan(
6044 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006045 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006046 } finally {
6047 Binder.restoreCallingIdentity(identity);
6048 }
yinxu504e1392017-04-12 16:03:22 -07006049 }
6050
Hall Liub2ac8ef2019-02-28 15:56:23 -08006051 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07006052 NetworkScanRequest request, int subId, String callingPackage) {
6053 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006054 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6055 boolean hasNetworkScanPermission =
6056 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6057 == PERMISSION_GRANTED;
6058
6059 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6060 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6061 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006062 }
6063
6064 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6065 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006066 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6067 return new SecurityException("Specific channels must not be"
6068 + " scanned without location access.");
6069 }
6070 }
6071 }
6072
Hall Liub2ac8ef2019-02-28 15:56:23 -08006073 return null;
6074 }
6075
yinxu504e1392017-04-12 16:03:22 -07006076 /**
6077 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006078 *
6079 * @param subId id of the subscription
6080 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006081 */
6082 @Override
6083 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6085 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086
Hall Liu912dfd32019-04-25 14:02:26 -07006087 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006088 final long identity = Binder.clearCallingIdentity();
6089 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006090 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 } finally {
6092 Binder.restoreCallingIdentity(identity);
6093 }
yinxu504e1392017-04-12 16:03:22 -07006094 }
6095
6096 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006097 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006098 *
SongFerngWang9e060372020-12-21 16:41:52 +08006099 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006100 */
6101 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006102 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006103 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006104 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006105 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106
6107 final long identity = Binder.clearCallingIdentity();
6108 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006109 if (DBG) log("getAllowedNetworkTypesBitmask");
6110 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6111 int networkTypesBitmask = (result != null ? result[0] : -1);
6112 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6113 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114 } finally {
6115 Binder.restoreCallingIdentity(identity);
6116 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006117 }
6118
6119 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006120 * Get the allowed network types for certain reason.
6121 *
6122 * @param subId the id of the subscription.
6123 * @param reason the reason the allowed network type change is taking place
6124 * @return the allowed network types.
6125 */
6126 @Override
6127 public long getAllowedNetworkTypesForReason(int subId,
6128 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006129 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006130 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006131 final long identity = Binder.clearCallingIdentity();
6132 try {
6133 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
6137 }
6138
6139 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006140 * Enable/Disable E-UTRA-NR Dual Connectivity
6141 * @param subId subscription id of the sim card
6142 * @param nrDualConnectivityState expected NR dual connectivity state
6143 * This can be passed following states
6144 * <ol>
6145 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6146 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6147 * <li>Disable NR dual connectivity and force secondary cell to be released
6148 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6149 * </ol>
6150 * @return operation result.
6151 */
6152 @Override
6153 public int setNrDualConnectivityState(int subId,
6154 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6156 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006157 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006158 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6159 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6160 }
6161
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006162 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6163 final long identity = Binder.clearCallingIdentity();
6164 try {
6165 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6166 nrDualConnectivityState, subId,
6167 workSource);
6168 if (DBG) log("enableNRDualConnectivity result: " + result);
6169 return result;
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
6172 }
6173 }
6174
6175 /**
6176 * Is E-UTRA-NR Dual Connectivity enabled
6177 * @return true if dual connectivity is enabled else false
6178 */
6179 @Override
6180 public boolean isNrDualConnectivityEnabled(int subId) {
6181 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006182 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006183 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006184 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006185 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6186 return false;
6187 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006188 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6189 final long identity = Binder.clearCallingIdentity();
6190 try {
6191 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6192 null, subId, workSource);
6193 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6194 return isEnabled;
6195 } finally {
6196 Binder.restoreCallingIdentity(identity);
6197 }
6198 }
6199
6200 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006201 * Set the allowed network types of the device and
6202 * provide the reason triggering the allowed network change.
6203 *
6204 * @param subId the id of the subscription.
6205 * @param reason the reason the allowed network type change is taking place
6206 * @param allowedNetworkTypes the allowed network types.
6207 * @return true on success; false on any failure.
6208 */
6209 @Override
6210 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006211 @TelephonyManager.AllowedNetworkTypesReason int reason,
6212 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6214 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006215 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6216 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6217 return false;
6218 }
6219
SongFerngWang522637d2021-03-02 22:09:29 +08006220 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6221 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6222
6223
6224 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6225 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6226 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006227 }
SongFerngWang522637d2021-03-02 22:09:29 +08006228
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006229 final long identity = Binder.clearCallingIdentity();
6230 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006231 Boolean success = (Boolean) sendRequest(
6232 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6233 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6234
6235 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6236 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
6240 }
6241
6242 /**
Miaoa84611c2019-03-15 09:21:10 +08006243 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006244 *
Miaoa84611c2019-03-15 09:21:10 +08006245 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006246 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006247 * @hide
6248 */
6249 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006250 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006251 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006253 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254 try {
Miaoa84611c2019-03-15 09:21:10 +08006255 if (phone != null) {
6256 return phone.hasMatchedTetherApnSetting();
6257 } else {
6258 return false;
6259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 } finally {
6261 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006262 }
Junda Liu475951f2014-11-07 16:45:03 -08006263 }
6264
6265 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006266 * Enable or disable always reporting signal strength changes from radio.
6267 *
6268 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6269 */
6270 @Override
6271 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6272 enforceModifyPermission();
6273 enforceSystemCaller();
6274
6275 final long identity = Binder.clearCallingIdentity();
6276 final Phone phone = getPhone(subId);
6277 try {
6278 if (phone != null) {
6279 if (DBG) {
6280 log("setAlwaysReportSignalStrength: subId=" + subId
6281 + " isEnable=" + isEnable);
6282 }
6283 phone.setAlwaysReportSignalStrength(isEnable);
6284 } else {
6285 loge("setAlwaysReportSignalStrength: no phone found for subId="
6286 + subId);
6287 }
6288 } finally {
6289 Binder.restoreCallingIdentity(identity);
6290 }
6291 }
6292
6293 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006294 * Get the user enabled state of Mobile Data.
6295 *
6296 * TODO: remove and use isUserDataEnabled.
6297 * This can't be removed now because some vendor codes
6298 * calls through ITelephony directly while they should
6299 * use TelephonyManager.
6300 *
6301 * @return true on enabled
6302 */
6303 @Override
6304 public boolean getDataEnabled(int subId) {
6305 return isUserDataEnabled(subId);
6306 }
6307
6308 /**
6309 * Get whether mobile data is enabled per user setting.
6310 *
6311 * There are other factors deciding whether mobile data is actually enabled, but they are
6312 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006313 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006314 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006315 *
6316 * @return {@code true} if data is enabled else {@code false}
6317 */
6318 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006319 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006320 try {
6321 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6322 null);
6323 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6325 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327
6328 final long identity = Binder.clearCallingIdentity();
6329 try {
6330 int phoneId = mSubscriptionController.getPhoneId(subId);
6331 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6332 Phone phone = PhoneFactory.getPhone(phoneId);
6333 if (phone != null) {
6334 boolean retVal = phone.isUserDataEnabled();
6335 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6336 return retVal;
6337 } else {
6338 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6339 return false;
6340 }
6341 } finally {
6342 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006343 }
6344 }
6345
6346 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006347 * Checks if the device is capable of mobile data by considering whether whether the
6348 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6349 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006350 *
Shuo Qian985d1232020-01-08 14:30:06 -08006351 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006352 */
6353 @Override
6354 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006355 try {
6356 try {
6357 mApp.enforceCallingOrSelfPermission(
6358 android.Manifest.permission.ACCESS_NETWORK_STATE,
6359 null);
6360 } catch (Exception e) {
6361 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6362 "isDataEnabled");
6363 }
6364 } catch (Exception e) {
6365 enforceReadPrivilegedPermission("isDataEnabled");
6366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367
6368 final long identity = Binder.clearCallingIdentity();
6369 try {
6370 int phoneId = mSubscriptionController.getPhoneId(subId);
6371 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6372 Phone phone = PhoneFactory.getPhone(phoneId);
6373 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006374 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6376 return retVal;
6377 } else {
6378 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6379 return false;
6380 }
6381 } finally {
6382 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006383 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006384 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006385
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006386 /**
6387 * Check if data is enabled for a specific reason
6388 * @param subId Subscription index
6389 * @param reason the reason the data enable change is taking place
6390 * @return {@code true} if the overall data is enabled; {@code false} if not.
6391 */
6392 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006393 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006394 @TelephonyManager.DataEnabledReason int reason) {
6395 try {
6396 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6397 null);
6398 } catch (Exception e) {
6399 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006400 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006401 }
6402
6403
6404 final long identity = Binder.clearCallingIdentity();
6405 try {
6406 int phoneId = mSubscriptionController.getPhoneId(subId);
6407 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006408 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006409 + " reason=" + reason);
6410 }
6411 Phone phone = PhoneFactory.getPhone(phoneId);
6412 if (phone != null) {
6413 boolean retVal;
6414 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6415 retVal = phone.isUserDataEnabled();
6416 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006417 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006418 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006419 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006420 return retVal;
6421 } else {
6422 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006423 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006424 + subId + " retVal=false");
6425 }
6426 return false;
6427 }
6428 } finally {
6429 Binder.restoreCallingIdentity(identity);
6430 }
6431 }
6432
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006433 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006434 Phone phone) {
Sarah Chinca45c312021-04-09 10:37:15 -07006435 if (uid == Process.PHONE_UID) {
6436 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6437 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liuce478d22020-07-13 12:13:03 -07006438 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6439 }
6440
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006441 //load access rules from carrier configs, and check those as well: b/139133814
6442 SubscriptionController subController = SubscriptionController.getInstance();
6443 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6444 || subController == null) return privilegeFromSim;
6445
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006446 PackageManager pkgMgr = phone.getContext().getPackageManager();
6447 String[] packages = pkgMgr.getPackagesForUid(uid);
6448
6449 final long identity = Binder.clearCallingIdentity();
6450 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006451 int subId = phone.getSubId();
6452 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6453 // A test override is in place for the privileges for this subId, so don't try to
6454 // read the subscription privileges.
6455 return privilegeFromSim;
6456 }
6457 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006458 SubscriptionManager subManager = (SubscriptionManager)
6459 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6460 for (String pkg : packages) {
6461 if (subManager.canManageSubscription(subInfo, pkg)) {
6462 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6463 }
6464 }
6465 return privilegeFromSim;
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
6469 }
6470
6471 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6472 String pkgName) {
6473 //load access rules from carrier configs, and check those as well: b/139133814
6474 SubscriptionController subController = SubscriptionController.getInstance();
6475 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6476 || subController == null) return privilegeFromSim;
6477
6478 final long identity = Binder.clearCallingIdentity();
6479 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006480 int subId = phone.getSubId();
6481 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6482 // A test override is in place for the privileges for this subId, so don't try to
6483 // read the subscription privileges.
6484 return privilegeFromSim;
6485 }
6486 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006487 SubscriptionManager subManager = (SubscriptionManager)
6488 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6489 return subManager.canManageSubscription(subInfo, pkgName)
6490 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6491 } finally {
6492 Binder.restoreCallingIdentity(identity);
6493 }
6494 }
6495
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006496 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006497 public int getCarrierPrivilegeStatus(int subId) {
6498 final Phone phone = getPhone(subId);
6499 if (phone == null) {
6500 loge("getCarrierPrivilegeStatus: Invalid subId");
6501 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6502 }
6503 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006504 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006505 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006506 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6507 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006508
6509 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6510 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006511 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006512 }
Junda Liu29340342014-07-10 15:23:27 -07006513
6514 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006515 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006516 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006517 final Phone phone = getPhone(subId);
6518 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006519 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006520 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6521 }
6522 UiccProfile profile =
6523 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6524 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006525 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006526 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6527 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006528 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006529 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006530 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006531 }
6532
6533 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006534 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6535 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006536 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006537 }
6538
6539 int phoneId = SubscriptionManager.getPhoneId(subId);
6540 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006541 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006542 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006543 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6544 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006545 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6546 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6547 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006548 }
6549
6550 @Override
6551 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006552 if (TextUtils.isEmpty(pkgName))
6553 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006554 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6555 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6556 UiccCard card = UiccController.getInstance().getUiccCard(i);
6557 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006558 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006559 continue;
6560 }
6561
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006562 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6563 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6564 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006565 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6566 break;
6567 }
6568 }
6569
6570 return result;
Junda Liu29340342014-07-10 15:23:27 -07006571 }
Derek Tan89e89d42014-07-08 17:00:10 -07006572
6573 @Override
Junda Liue64de782015-04-16 17:19:16 -07006574 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6575 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6576 loge("phoneId " + phoneId + " is not valid.");
6577 return null;
6578 }
6579 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006580 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006581 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006582 return null ;
6583 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006584 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006585 }
6586
Amith Yamasani6e118872016-02-19 12:53:51 -08006587 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006588 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006589 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006590 List<String> privilegedPackages = new ArrayList<>();
6591 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006592 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6593 // has UICC in that slot.
6594 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006595 if (card.hasCarrierPrivilegeRules()) {
6596 if (packages == null) {
6597 // Only check packages in user 0 for now
6598 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006599 PackageManager.MATCH_DISABLED_COMPONENTS
6600 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006601 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006602 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006603 }
6604 for (int p = packages.size() - 1; p >= 0; p--) {
6605 PackageInfo pkgInfo = packages.get(p);
6606 if (pkgInfo != null && pkgInfo.packageName != null
6607 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006608 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006609 privilegedPackages.add(pkgInfo.packageName);
6610 }
6611 }
6612 }
6613 }
6614 return privilegedPackages;
6615 }
6616
chen xuf7e9fe82019-05-09 19:31:02 -07006617 @Override
6618 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006619 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6620
6621 final long identity = Binder.clearCallingIdentity();
6622
chen xuf7e9fe82019-05-09 19:31:02 -07006623 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006624 try {
6625 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6626 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6627 }
6628 } finally {
6629 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006630 }
6631 return privilegedPackages;
6632 }
6633
Wink Savilleb564aae2014-10-23 10:18:09 -07006634 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006635 final Phone phone = getPhone(subId);
6636 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006637 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006638 return null;
6639 }
6640 String iccId = card.getIccId();
6641 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006642 return null;
6643 }
6644 return iccId;
6645 }
6646
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006647 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006648 public void setCallComposerStatus(int subId, int status) {
6649 enforceModifyPermission();
6650
6651 final long identity = Binder.clearCallingIdentity();
6652 try {
6653 Phone phone = getPhone(subId);
6654 if (phone != null) {
6655 Phone defaultPhone = phone.getImsPhone();
6656 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6657 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6658 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006659 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6660 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006661 }
6662 }
Shuo Qiand8782462020-12-22 19:10:14 -08006663 } catch (ImsException e) {
6664 throw new ServiceSpecificException(e.getCode());
6665 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006666 Binder.restoreCallingIdentity(identity);
6667 }
6668 }
6669
6670 @Override
6671 public int getCallComposerStatus(int subId) {
6672 enforceReadPrivilegedPermission("getCallComposerStatus");
6673
6674 final long identity = Binder.clearCallingIdentity();
6675 try {
6676 Phone phone = getPhone(subId);
6677 if (phone != null) {
6678 Phone defaultPhone = phone.getImsPhone();
6679 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6680 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6681 return imsPhone.getCallComposerStatus();
6682 }
6683 }
6684 } finally {
6685 Binder.restoreCallingIdentity(identity);
6686 }
6687 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6688 }
6689
6690 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006691 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6692 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006693 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006694 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 final long identity = Binder.clearCallingIdentity();
6697 try {
6698 final String iccId = getIccId(subId);
6699 final Phone phone = getPhone(subId);
6700 if (phone == null) {
6701 return false;
6702 }
6703 final String subscriberId = phone.getSubscriberId();
6704
6705 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006706 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 + subscriberId + " to " + number);
6708 }
6709
6710 if (TextUtils.isEmpty(iccId)) {
6711 return false;
6712 }
6713
6714 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6715
6716 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6717 if (alphaTag == null) {
6718 editor.remove(alphaTagPrefKey);
6719 } else {
6720 editor.putString(alphaTagPrefKey, alphaTag);
6721 }
6722
6723 // Record both the line number and IMSI for this ICCID, since we need to
6724 // track all merged IMSIs based on line number
6725 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6726 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6727 if (number == null) {
6728 editor.remove(numberPrefKey);
6729 editor.remove(subscriberPrefKey);
6730 } else {
6731 editor.putString(numberPrefKey, number);
6732 editor.putString(subscriberPrefKey, subscriberId);
6733 }
6734
6735 editor.commit();
6736 return true;
6737 } finally {
6738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006739 }
Derek Tan7226c842014-07-02 17:42:23 -07006740 }
6741
6742 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006743 public String getLine1NumberForDisplay(int subId, String callingPackage,
6744 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006745 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006746 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006747 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006748 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006749 return null;
6750 }
Derek Tan97ebb422014-09-05 16:55:38 -07006751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 final long identity = Binder.clearCallingIdentity();
6753 try {
6754 String iccId = getIccId(subId);
6755 if (iccId != null) {
6756 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6757 if (DBG_MERGE) {
6758 log("getLine1NumberForDisplay returning "
6759 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6760 }
6761 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006762 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6764 return null;
6765 } finally {
6766 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006767 }
Derek Tan7226c842014-07-02 17:42:23 -07006768 }
6769
6770 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006771 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6772 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006773 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006774 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006775 return null;
6776 }
Derek Tan97ebb422014-09-05 16:55:38 -07006777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778 final long identity = Binder.clearCallingIdentity();
6779 try {
6780 String iccId = getIccId(subId);
6781 if (iccId != null) {
6782 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6783 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6784 }
6785 return null;
6786 } finally {
6787 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006788 }
Derek Tan7226c842014-07-02 17:42:23 -07006789 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006790
6791 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006792 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6793 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006794 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6795 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006796 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006797 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006798 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006799 return null;
6800 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006801
Jordan Liub49b04b2019-05-06 14:45:15 -07006802 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6803 // the process, where TelephonyManager was instantiated.
6804 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006805 final long identity = Binder.clearCallingIdentity();
6806 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006807 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006808 final TelephonyManager tele = TelephonyManager.from(context);
6809 final SubscriptionManager sub = SubscriptionManager.from(context);
6810
6811 // Figure out what subscribers are currently active
6812 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813
Jordan Liub49b04b2019-05-06 14:45:15 -07006814 // Only consider subs which match the current subId
6815 // This logic can be simplified. See b/131189269 for progress.
6816 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006817 activeSubscriberIds.add(tele.getSubscriberId(subId));
6818 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819
6820 // First pass, find a number override for an active subscriber
6821 String mergeNumber = null;
6822 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6823 for (String key : prefs.keySet()) {
6824 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6825 final String subscriberId = (String) prefs.get(key);
6826 if (activeSubscriberIds.contains(subscriberId)) {
6827 final String iccId = key.substring(
6828 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6829 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6830 mergeNumber = (String) prefs.get(numberKey);
6831 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006832 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006833 + " for active subscriber " + subscriberId);
6834 }
6835 if (!TextUtils.isEmpty(mergeNumber)) {
6836 break;
6837 }
6838 }
6839 }
6840 }
6841
6842 // Shortcut when no active merged subscribers
6843 if (TextUtils.isEmpty(mergeNumber)) {
6844 return null;
6845 }
6846
6847 // Second pass, find all subscribers under that line override
6848 final ArraySet<String> result = new ArraySet<>();
6849 for (String key : prefs.keySet()) {
6850 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6851 final String number = (String) prefs.get(key);
6852 if (mergeNumber.equals(number)) {
6853 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6854 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6855 final String subscriberId = (String) prefs.get(subscriberKey);
6856 if (!TextUtils.isEmpty(subscriberId)) {
6857 result.add(subscriberId);
6858 }
6859 }
6860 }
6861 }
6862
6863 final String[] resultArray = result.toArray(new String[result.size()]);
6864 Arrays.sort(resultArray);
6865 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006866 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6868 }
6869 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006870 } finally {
6871 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006872 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006873 }
6874
6875 @Override
zoey chen38003472019-12-13 17:16:31 +08006876 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6877 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006878
6879 final long identity = Binder.clearCallingIdentity();
6880 try {
6881 final TelephonyManager telephonyManager = mApp.getSystemService(
6882 TelephonyManager.class);
6883 String subscriberId = telephonyManager.getSubscriberId(subId);
6884 if (subscriberId == null) {
6885 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006886 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006887 + subId);
6888 }
6889 return null;
6890 }
6891
6892 final SubscriptionInfo info = SubscriptionController.getInstance()
6893 .getSubscriptionInfo(subId);
6894 final ParcelUuid groupUuid = info.getGroupUuid();
6895 // If it doesn't belong to any group, return just subscriberId of itself.
6896 if (groupUuid == null) {
6897 return new String[]{subscriberId};
6898 }
6899
6900 // Get all subscriberIds from the group.
6901 final List<String> mergedSubscriberIds = new ArrayList<>();
6902 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006903 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006904 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006905 for (SubscriptionInfo subInfo : groupInfos) {
6906 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6907 if (subscriberId != null) {
6908 mergedSubscriberIds.add(subscriberId);
6909 }
6910 }
6911
6912 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6913 } finally {
6914 Binder.restoreCallingIdentity(identity);
6915
6916 }
6917 }
6918
6919 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006920 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006921 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006922 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006923
6924 final long identity = Binder.clearCallingIdentity();
6925 try {
6926 final Phone phone = getPhone(subId);
6927 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6928 } finally {
6929 Binder.restoreCallingIdentity(identity);
6930 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006931 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006932
6933 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006934 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006935 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6936 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006937 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6938 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939
6940 final long identity = Binder.clearCallingIdentity();
6941 try {
6942 final Phone phone = getPhone(subId);
6943 if (phone == null) {
6944 return false;
6945 }
6946 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6947 cdmaNonRoamingList);
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006950 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006951 }
6952
6953 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006954 @Deprecated
6955 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6956 enforceModifyPermission();
6957
6958 int returnValue = 0;
6959 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006960 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006961 if(result.exception == null) {
6962 if (result.result != null) {
6963 byte[] responseData = (byte[])(result.result);
6964 if(responseData.length > oemResp.length) {
6965 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6966 responseData.length + "bytes. Buffer Size is " +
6967 oemResp.length + "bytes.");
6968 }
6969 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6970 returnValue = responseData.length;
6971 }
6972 } else {
6973 CommandException ex = (CommandException) result.exception;
6974 returnValue = ex.getCommandError().ordinal();
6975 if(returnValue > 0) returnValue *= -1;
6976 }
6977 } catch (RuntimeException e) {
6978 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6979 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6980 if(returnValue > 0) returnValue *= -1;
6981 }
6982
6983 return returnValue;
6984 }
6985
6986 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006987 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006988 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006989 try {
6990 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006991 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07006992 mApp, phone.getSubId(), "getRadioAccessFamily");
6993 } catch (SecurityException e) {
6994 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6995 throw e;
6996 }
chen xub97461a2018-10-26 14:17:57 -07006997 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006998 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006999 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007001 final long identity = Binder.clearCallingIdentity();
7002 try {
chen xub97461a2018-10-26 14:17:57 -07007003 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007004 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007005 mApp, phone.getSubId(), "getRadioAccessFamily");
7006 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
chen xub97461a2018-10-26 14:17:57 -07007010 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007011 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007012
7013 @Override
7014 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007015 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007016 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017
7018 final long identity = Binder.clearCallingIdentity();
7019 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007020 ImsManager.getInstance(defaultPhone.getContext(),
7021 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022 } finally {
7023 Binder.restoreCallingIdentity(identity);
7024 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007025 }
7026
7027 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007028 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007029 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007030 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7031 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007032 return false;
7033 }
Svet Ganovb320e182015-04-16 12:30:10 -07007034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 final long identity = Binder.clearCallingIdentity();
7036 try {
7037 // Check the user preference and the system-level IMS setting. Even if the user has
7038 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7039 // In the long run, we may instead need to check if there exists a connection service
7040 // which can support video calling.
7041 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007042 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 return imsManager.isVtEnabledByPlatform()
7044 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7045 && imsManager.isVtEnabledByUser();
7046 } finally {
7047 Binder.restoreCallingIdentity(identity);
7048 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007049 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007050
Andrew Leea1239f22015-03-02 17:44:07 -08007051 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007052 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7053 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007055 mApp, subId, callingPackage, callingFeatureId,
7056 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 return false;
7058 }
7059
7060 final long identity = Binder.clearCallingIdentity();
7061 try {
7062 CarrierConfigManager configManager =
7063 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007064 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7066 } finally {
7067 Binder.restoreCallingIdentity(identity);
7068 }
Andrew Leea1239f22015-03-02 17:44:07 -08007069 }
7070
7071 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007072 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007074 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 return false;
7076 }
7077
7078 final long identity = Binder.clearCallingIdentity();
7079 try {
7080 CarrierConfigManager configManager =
7081 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007082 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7084 } finally {
7085 Binder.restoreCallingIdentity(identity);
7086 }
Andrew Leea1239f22015-03-02 17:44:07 -08007087 }
7088
Andrew Lee9431b832015-03-09 18:46:45 -07007089 @Override
7090 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007091 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007092 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007093 }
7094
7095 @Override
7096 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 final long identity = Binder.clearCallingIdentity();
7098 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007099 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100 } finally {
7101 Binder.restoreCallingIdentity(identity);
7102 }
Andrew Lee9431b832015-03-09 18:46:45 -07007103 }
7104
Hall Liuf6668912018-10-31 17:05:23 -07007105 /**
7106 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7107 * support for the feature and device firmware support.
7108 *
7109 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7110 */
7111 @Override
7112 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007114 final Phone phone = getPhone(subscriptionId);
7115 if (phone == null) {
7116 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7117 return false;
7118 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007120 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7122 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007123 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124 return isCarrierSupported && isDeviceSupported;
7125 } finally {
7126 Binder.restoreCallingIdentity(identity);
7127 }
Hall Liu98187582018-01-22 19:15:32 -08007128 }
7129
Hall Liuf6668912018-10-31 17:05:23 -07007130 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007131 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7132 * RTT setting, will return true if the device and carrier both support RTT.
7133 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007134 */
7135 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 final long identity = Binder.clearCallingIdentity();
7137 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007138 boolean isRttSupported = isRttSupported(subscriptionId);
7139 boolean isUserRttSettingOn = Settings.Secure.getInt(
7140 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7141 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7142 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7143 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144 } finally {
7145 Binder.restoreCallingIdentity(identity);
7146 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007147 }
7148
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007149 @Deprecated
7150 @Override
7151 public String getDeviceId(String callingPackage) {
7152 return getDeviceIdWithFeature(callingPackage, null);
7153 }
7154
Sanket Padawe7310cc72015-01-14 09:53:20 -08007155 /**
7156 * Returns the unique device ID of phone, for example, the IMEI for
7157 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7158 *
7159 * <p>Requires Permission:
7160 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7161 */
7162 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007163 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007164 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007165 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007166 return null;
7167 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007168 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007169 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007170 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007171 return null;
7172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 return phone.getDeviceId();
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
7179 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007180 }
7181
Ping Sunc67b7c22016-03-02 19:16:45 +08007182 /**
7183 * {@hide}
7184 * Returns the IMS Registration Status on a particular subid
7185 *
7186 * @param subId
7187 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007188 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007189 Phone phone = getPhone(subId);
7190 if (phone != null) {
7191 return phone.isImsRegistered();
7192 } else {
7193 return false;
7194 }
7195 }
7196
Santos Cordon7a1885b2015-02-03 11:15:19 -08007197 @Override
7198 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7202 } finally {
7203 Binder.restoreCallingIdentity(identity);
7204 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007205 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007206
Tyler Gunnf70ed162019-04-03 15:28:53 -07007207 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007208 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007209 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007210 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007211 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007212 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7213 }
7214 final long identity = Binder.clearCallingIdentity();
7215 try {
7216 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7217 } finally {
7218 Binder.restoreCallingIdentity(identity);
7219 }
7220 }
7221
7222 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007223 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007224 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7225 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007226 final long identity = Binder.clearCallingIdentity();
7227 try {
7228 Phone phone = getPhone(subscriptionId);
7229 if (phone == null) {
7230 return null;
7231 }
7232 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
7235 }
7236 }
7237
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007238 /**
7239 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007240 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007241 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007242 final long identity = Binder.clearCallingIdentity();
7243 try {
7244 Phone phone = getPhone(subId);
7245 if (phone != null) {
7246 return phone.isWifiCallingEnabled();
7247 } else {
7248 return false;
7249 }
7250 } finally {
7251 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007252 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007253 }
7254
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007255 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007256 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007257 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007258 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259 final long identity = Binder.clearCallingIdentity();
7260 try {
7261 Phone phone = getPhone(subId);
7262 if (phone != null) {
7263 return phone.isVideoEnabled();
7264 } else {
7265 return false;
7266 }
7267 } finally {
7268 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007269 }
7270 }
7271
7272 /**
7273 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7274 * defined in {@link ImsRegistrationImplBase}.
7275 */
7276 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007277 final long identity = Binder.clearCallingIdentity();
7278 try {
7279 Phone phone = getPhone(subId);
7280 if (phone != null) {
7281 return phone.getImsRegistrationTech();
7282 } else {
7283 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7284 }
7285 } finally {
7286 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007287 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007288 }
7289
Stuart Scott8eef64f2015-04-08 15:13:54 -07007290 @Override
7291 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007292 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007293 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7294 return;
7295 }
7296
Svet Ganovcc087f82015-05-12 20:35:54 -07007297 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007298
Svet Ganovcc087f82015-05-12 20:35:54 -07007299 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007300 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7301 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007302 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007303 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007304 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007305 Phone phone = getPhone(subId);
7306 if (phone != null) {
7307 SubscriptionManager.setSubscriptionProperty(subId,
7308 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7309 "user=" + RadioAccessFamily.getRafFromNetworkType(
7310 RILConstants.PREFERRED_NETWORK_MODE));
7311 phone.loadAllowedNetworksFromSubscriptionDatabase();
7312 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007313 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7314 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007315 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007316 // There has been issues when Sms raw table somehow stores orphan
7317 // fragments. They lead to garbled message when new fragments come
7318 // in and combined with those stale ones. In case this happens again,
7319 // user can reset all network settings which will clean up this table.
7320 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007321 // Clean up IMS settings as well here.
7322 int slotId = getSlotIndex(subId);
7323 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7324 ImsManager.getInstance(mApp, slotId).factoryReset();
7325 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007326
7327 // Erase modem config if erase modem on network setting is enabled.
7328 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7329 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7330 if (configValue != null && Boolean.parseBoolean(configValue)) {
7331 sendEraseModemConfig(getDefaultPhone());
7332 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007333 } finally {
7334 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007335 }
7336 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007337
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007338 private void cleanUpSmsRawTable(Context context) {
7339 ContentResolver resolver = context.getContentResolver();
7340 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7341 resolver.delete(uri, null, null);
7342 }
7343
Narayan Kamath1c496c22015-04-16 14:40:19 +01007344 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007345 public String getSimLocaleForSubscriber(int subId) {
7346 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7347 final Phone phone = getPhone(subId);
7348 if (phone == null) {
7349 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007350 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352 final long identity = Binder.clearCallingIdentity();
7353 try {
chen xu5d3637b2019-01-21 23:31:38 -08007354 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007355 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007356 if (info == null) {
7357 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7358 return null;
7359 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 // Try and fetch the locale from the carrier properties or from the SIM language
7361 // preferences (EF-PL and EF-LI)...
7362 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007364 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7365 if (localeFromDefaultSim != null) {
7366 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7367 if (DBG) log("Using locale from subId: " + subId + " locale: "
7368 + localeFromDefaultSim);
7369 return localeFromDefaultSim.toLanguageTag();
7370 } else {
7371 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 }
7373 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 // The SIM language preferences only store a language (e.g. fr = French), not an
7376 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7377 // the SIM and carrier preferences does not include a country we add the country
7378 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007379 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007381 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382 return mccLocale.toLanguageTag();
7383 }
7384
7385 if (DBG) log("No locale found - returning null");
7386 return null;
7387 } finally {
7388 Binder.restoreCallingIdentity(identity);
7389 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007390 }
7391
7392 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007393 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007394 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007395 }
7396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007397 /**
7398 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7399 */
7400 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007401 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007402 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007403 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007404
Chenjie Yu1ba97252018-01-11 18:16:20 -08007405 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007406 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007407
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007408 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007409 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7410 * representing the state of the modem.
7411 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007412 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7413 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007414 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007415 */
7416 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007417 public void requestModemActivityInfo(ResultReceiver result) {
7418 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007419 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420
7421 final long identity = Binder.clearCallingIdentity();
7422 try {
sqian1a1be542020-03-05 11:37:28 -08007423 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 } finally {
7425 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007426 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007427 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007428
Siddharth Rayb8114062018-06-17 15:02:38 -07007429 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7430 // less than total activity duration.
7431 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7432 if (info == null) {
7433 return false;
7434 }
7435 int activityDurationMs =
7436 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7437 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007438 int[] txTimeMs = info.getTransmitTimeMillis();
7439 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7440 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007441 }
7442 return (info.isValid()
7443 && (info.getSleepTimeMillis() <= activityDurationMs)
7444 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007445 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007446 && (totalTxTimeMs <= activityDurationMs));
7447 }
7448
Jack Yu85bd38a2015-11-09 11:34:32 -08007449 /**
7450 * {@hide}
7451 * Returns the service state information on specified subscription.
7452 */
7453 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007454 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7455 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007456 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007457 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007458 return null;
7459 }
7460
Hall Liuf19c44f2018-11-27 14:38:17 -08007461 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7462 LocationAccessPolicy.checkLocationPermission(mApp,
7463 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7464 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007465 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007466 .setCallingPid(Binder.getCallingPid())
7467 .setCallingUid(Binder.getCallingUid())
7468 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007469 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007470 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007471 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7472 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007473 .build());
7474
7475 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
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 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007485 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7486 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007487 .build());
7488 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7489 boolean hasFinePermission =
7490 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7491 boolean hasCoarsePermission =
7492 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 final long identity = Binder.clearCallingIdentity();
7495 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007496 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7497 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7498 Rlog.d(LOG_TAG,
7499 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7500 return null;
7501 }
7502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 final Phone phone = getPhone(subId);
7504 if (phone == null) {
7505 return null;
7506 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007507
Hall Liuf19c44f2018-11-27 14:38:17 -08007508 ServiceState ss = phone.getServiceState();
7509
7510 // Scrub out the location info in ServiceState depending on what level of access
7511 // the caller has.
7512 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007513 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7514 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 } finally {
7516 Binder.restoreCallingIdentity(identity);
7517 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007518 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007519
7520 /**
7521 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7522 *
7523 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7524 * voicemail ringtone.
7525 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7526 * PhoneAccount.
7527 */
7528 @Override
7529 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 final long identity = Binder.clearCallingIdentity();
7531 try {
7532 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7533 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007534 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7538 } finally {
7539 Binder.restoreCallingIdentity(identity);
7540 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007541 }
7542
7543 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007544 * Sets the per-account voicemail ringtone.
7545 *
7546 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7547 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7548 *
7549 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7550 * voicemail ringtone.
7551 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7552 * PhoneAccount.
7553 */
7554 @Override
7555 public void setVoicemailRingtoneUri(String callingPackage,
7556 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007557 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007558 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007559 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7560 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7562 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7563 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565
7566 final long identity = Binder.clearCallingIdentity();
7567 try {
7568 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7569 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007570 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007571 }
7572 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7573 } finally {
7574 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007575 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007576 }
7577
7578 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007579 * Returns whether vibration is set for voicemail notification in Phone settings.
7580 *
7581 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7582 * voicemail vibration setting.
7583 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7584 */
7585 @Override
7586 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 final long identity = Binder.clearCallingIdentity();
7588 try {
7589 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7590 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007591 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007592 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007594 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7595 } finally {
7596 Binder.restoreCallingIdentity(identity);
7597 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007598 }
7599
Youhan Wange64578a2016-05-02 15:32:42 -07007600 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007601 * Sets the per-account voicemail vibration.
7602 *
7603 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7604 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7605 *
7606 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7607 * voicemail vibration setting.
7608 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7609 * specific PhoneAccount.
7610 */
7611 @Override
7612 public void setVoicemailVibrationEnabled(String callingPackage,
7613 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007614 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007615 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007616 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7617 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7619 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7620 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007621 }
7622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623 final long identity = Binder.clearCallingIdentity();
7624 try {
7625 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7626 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007627 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007628 }
7629 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7630 } finally {
7631 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007632 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007633 }
7634
7635 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007636 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7637 *
7638 * @throws SecurityException if the caller does not have the required permission
7639 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007640 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007641 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007642 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007643 }
7644
7645 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007646 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7647 * permission.
7648 *
7649 * @throws SecurityException if the caller does not have the required permission
7650 */
7651 private void enforceSendSmsPermission() {
7652 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7653 }
7654
7655 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007656 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007657 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007658 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007659 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007660 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007661 final long identity = Binder.clearCallingIdentity();
7662 try {
7663 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007664 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665 if (componentName == null) {
7666 throw new SecurityException(
7667 "Caller not current active visual voicemail package[null]");
7668 }
7669 String vvmPackage = componentName.getPackageName();
7670 if (!callingPackage.equals(vvmPackage)) {
7671 throw new SecurityException("Caller not current active visual voicemail package["
7672 + vvmPackage + "]");
7673 }
7674 } finally {
7675 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007676 }
7677 }
7678
7679 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007680 * Return the application ID for the app type.
7681 *
7682 * @param subId the subscription ID that this request applies to.
7683 * @param appType the uicc app type.
7684 * @return Application ID for specificied app type, or null if no uicc.
7685 */
7686 @Override
7687 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007688 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007689 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690
7691 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007692 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 if (phone == null) {
7694 return null;
7695 }
7696 String aid = null;
7697 try {
7698 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7699 .getApplicationByType(appType).getAid();
7700 } catch (Exception e) {
7701 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7702 }
7703 return aid;
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007706 }
Youhan Wange64578a2016-05-02 15:32:42 -07007707 }
7708
Youhan Wang4001d252016-05-11 10:29:41 -07007709 /**
7710 * Return the Electronic Serial Number.
7711 *
7712 * @param subId the subscription ID that this request applies to.
7713 * @return ESN or null if error.
7714 */
7715 @Override
7716 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007717 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007718 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719
7720 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007721 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 if (phone == null) {
7723 return null;
7724 }
7725 String esn = null;
7726 try {
7727 esn = phone.getEsn();
7728 } catch (Exception e) {
7729 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7730 }
7731 return esn;
7732 } finally {
7733 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007734 }
Youhan Wang4001d252016-05-11 10:29:41 -07007735 }
7736
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007737 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007738 * Return the Preferred Roaming List Version.
7739 *
7740 * @param subId the subscription ID that this request applies to.
7741 * @return PRLVersion or null if error.
7742 */
7743 @Override
7744 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007745 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007746 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747
7748 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007749 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007750 if (phone == null) {
7751 return null;
7752 }
7753 String cdmaPrlVersion = null;
7754 try {
7755 cdmaPrlVersion = phone.getCdmaPrlVersion();
7756 } catch (Exception e) {
7757 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7758 }
7759 return cdmaPrlVersion;
7760 } finally {
7761 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007762 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007763 }
7764
7765 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007766 * Get snapshot of Telephony histograms
7767 * @return List of Telephony histograms
7768 * @hide
7769 */
7770 @Override
7771 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7773 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774
7775 final long identity = Binder.clearCallingIdentity();
7776 try {
7777 return RIL.getTelephonyRILTimingHistograms();
7778 } finally {
7779 Binder.restoreCallingIdentity(identity);
7780 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007781 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007782
7783 /**
7784 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007785 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7786 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007787 * Require system privileges. In the future we may add this to carrier APIs.
7788 *
Michele Berionne482f8202018-11-27 18:57:59 -08007789 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007790 */
7791 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007792 @TelephonyManager.SetCarrierRestrictionResult
7793 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007794 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007796
Michele Berionne482f8202018-11-27 18:57:59 -08007797 if (carrierRestrictionRules == null) {
7798 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007799 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 final long identity = Binder.clearCallingIdentity();
7802 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007803 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007804 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805 } finally {
7806 Binder.restoreCallingIdentity(identity);
7807 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007808 }
7809
7810 /**
7811 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007812 * Get the allowed carrier list and the excluded carrier list, including the priority between
7813 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007814 * Require system privileges. In the future we may add this to carrier APIs.
7815 *
Michele Berionne482f8202018-11-27 18:57:59 -08007816 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007817 */
7818 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007819 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007820 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007821 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822
7823 final long identity = Binder.clearCallingIdentity();
7824 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007825 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7826 if (response instanceof CarrierRestrictionRules) {
7827 return (CarrierRestrictionRules) response;
7828 }
7829 // Response is an Exception of some kind,
7830 // which is signalled to the user as a NULL retval
7831 return null;
7832 } catch (Exception e) {
7833 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7834 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007835 } finally {
7836 Binder.restoreCallingIdentity(identity);
7837 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007838 }
7839
fionaxu59545b42016-05-25 15:53:37 -07007840 /**
fionaxu59545b42016-05-25 15:53:37 -07007841 * Action set from carrier signalling broadcast receivers to enable/disable radio
7842 * @param subId the subscription ID that this action applies to.
7843 * @param enabled control enable or disable radio.
7844 * {@hide}
7845 */
7846 @Override
7847 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7848 enforceModifyPermission();
7849 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850
7851 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007852 if (phone == null) {
7853 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7854 return;
7855 }
7856 try {
7857 phone.carrierActionSetRadioEnabled(enabled);
7858 } catch (Exception e) {
7859 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860 } finally {
7861 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007862 }
7863 }
7864
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007865 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007866 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7867 * network status based on which carrier apps could apply actions accordingly,
7868 * enable/disable default url handler for example.
7869 *
7870 * @param subId the subscription ID that this action applies to.
7871 * @param report control start/stop reporting the default network status.
7872 * {@hide}
7873 */
7874 @Override
7875 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7876 enforceModifyPermission();
7877 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007878
7879 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007880 if (phone == null) {
7881 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7882 return;
7883 }
7884 try {
7885 phone.carrierActionReportDefaultNetworkStatus(report);
7886 } catch (Exception e) {
7887 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007888 } finally {
7889 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007890 }
7891 }
7892
7893 /**
fionaxud9622282017-07-17 17:51:30 -07007894 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7895 * @param subId the subscription ID that this action applies to.
7896 * {@hide}
7897 */
7898 @Override
7899 public void carrierActionResetAll(int subId) {
7900 enforceModifyPermission();
7901 final Phone phone = getPhone(subId);
7902 if (phone == null) {
7903 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7904 return;
7905 }
7906 try {
7907 phone.carrierActionResetAll();
7908 } catch (Exception e) {
7909 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7910 }
7911 }
7912
7913 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007914 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7915 * bug report is being generated.
7916 */
7917 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007918 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007919 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7920 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007921 writer.println("Permission Denial: can't dump Phone from pid="
7922 + Binder.getCallingPid()
7923 + ", uid=" + Binder.getCallingUid()
7924 + "without permission "
7925 + android.Manifest.permission.DUMP);
7926 return;
7927 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007928 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007929 }
Jack Yueb89b242016-06-22 13:27:47 -07007930
Brad Ebingerdac2f002018-04-03 15:17:52 -07007931 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007932 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7933 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7934 @NonNull String[] args) {
7935 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7936 this, in.getFileDescriptor(), out.getFileDescriptor(),
7937 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007938 }
7939
Jack Yueb89b242016-06-22 13:27:47 -07007940 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007941 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007942 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007943 * @param reason the reason the data enable change is taking place
7944 * @param enabled True if enabling the data, otherwise disabling.
7945 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007946 */
7947 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007948 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007949 boolean enabled) {
7950 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7951 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7952 try {
7953 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007954 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007955 } catch (SecurityException se) {
7956 enforceModifyPermission();
7957 }
7958 } else {
7959 enforceModifyPermission();
7960 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007961
7962 final long identity = Binder.clearCallingIdentity();
7963 try {
7964 Phone phone = getPhone(subId);
7965 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007966 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7967 phone.carrierActionSetMeteredApnsEnabled(enabled);
7968 } else {
7969 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007971 }
7972 } finally {
7973 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007974 }
7975 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007976
7977 /**
7978 * Get Client request stats
7979 * @return List of Client Request Stats
7980 * @hide
7981 */
7982 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007983 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7984 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007986 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007987 return null;
7988 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007989 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007991 final long identity = Binder.clearCallingIdentity();
7992 try {
7993 if (phone != null) {
7994 return phone.getClientRequestStats();
7995 }
7996
7997 return null;
7998 } finally {
7999 Binder.restoreCallingIdentity(identity);
8000 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008001 }
8002
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008003 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008004 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008005 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008006 }
Jack Yueb4124c2017-02-16 15:32:43 -08008007
8008 /**
Grace Chen70990072017-03-24 17:21:30 -07008009 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008010 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008011 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008012 * @param state State of SIM (power down, power up, pass through)
8013 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8014 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8015 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008016 *
8017 **/
8018 @Override
Grace Chen70990072017-03-24 17:21:30 -07008019 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008020 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008021 Phone phone = PhoneFactory.getPhone(slotIndex);
8022
vagdeviaf9a5b92018-08-15 16:01:53 -07008023 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 final long identity = Binder.clearCallingIdentity();
8026 try {
8027 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008028 phone.setSimPowerState(state, null, workSource);
8029 }
8030 } finally {
8031 Binder.restoreCallingIdentity(identity);
8032 }
8033 }
8034
8035 /**
8036 * Set SIM card power state.
8037 *
8038 * @param slotIndex SIM slot id.
8039 * @param state State of SIM (power down, power up, pass through)
8040 * @param callback callback to trigger after success or failure
8041 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8042 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8043 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8044 *
8045 **/
8046 @Override
8047 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8048 IIntegerConsumer callback) {
8049 enforceModifyPermission();
8050 Phone phone = PhoneFactory.getPhone(slotIndex);
8051
8052 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8053
8054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 if (phone != null) {
8057 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8058 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008059 }
8060 } finally {
8061 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008062 }
8063 }
Shuo Qiandd210312017-04-12 22:11:33 +00008064
Tyler Gunn65d45c22017-06-05 11:22:26 -07008065 private boolean isUssdApiAllowed(int subId) {
8066 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008067 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008068 if (configManager == null) {
8069 return false;
8070 }
8071 PersistableBundle pb = configManager.getConfigForSubId(subId);
8072 if (pb == null) {
8073 return false;
8074 }
8075 return pb.getBoolean(
8076 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8077 }
8078
Shuo Qiandd210312017-04-12 22:11:33 +00008079 /**
8080 * Check if phone is in emergency callback mode
8081 * @return true if phone is in emergency callback mode
8082 * @param subId sub id
8083 */
goneil9c5f4872017-12-05 14:07:56 -08008084 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008085 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008086 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008087 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088
8089 final long identity = Binder.clearCallingIdentity();
8090 try {
8091 if (phone != null) {
8092 return phone.isInEcm();
8093 } else {
8094 return false;
8095 }
8096 } finally {
8097 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008098 }
8099 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008100
8101 /**
8102 * Get the current signal strength information for the given subscription.
8103 * Because this information is not updated when the device is in a low power state
8104 * it should not be relied-upon to be current.
8105 * @param subId Subscription index
8106 * @return the most recent cached signal strength info from the modem
8107 */
8108 @Override
8109 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008110 final long identity = Binder.clearCallingIdentity();
8111 try {
8112 Phone p = getPhone(subId);
8113 if (p == null) {
8114 return null;
8115 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008116
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117 return p.getSignalStrength();
8118 } finally {
8119 Binder.restoreCallingIdentity(identity);
8120 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008121 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008122
Pengquan Meng77b7f132018-08-22 14:49:57 -07008123 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008124 * Get the current modem radio state for the given slot.
8125 * @param slotIndex slot index.
8126 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008127 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008128 * @return the current radio power state from the modem
8129 */
8130 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008131 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008132 Phone phone = PhoneFactory.getPhone(slotIndex);
8133 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8135 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008136 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8137 }
8138
8139 final long identity = Binder.clearCallingIdentity();
8140 try {
8141 return phone.getRadioPowerState();
8142 } finally {
8143 Binder.restoreCallingIdentity(identity);
8144 }
8145 }
8146 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8147 }
8148
8149 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008150 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8151 *
8152 * <p>Requires one of the following permissions:
8153 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8154 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8155 * privileges.
8156 *
8157 * @param subId subscription id
8158 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8159 * {@code false}.
8160 */
8161 @Override
8162 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008163 try {
8164 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8165 null);
8166 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008167 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008168 mApp, subId, "isDataRoamingEnabled");
8169 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008170
Pengquan Menga1bb6272018-09-06 09:59:22 -07008171 boolean isEnabled = false;
8172 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008173 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008174 Phone phone = getPhone(subId);
8175 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008176 } finally {
8177 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008178 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008179 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008180 }
8181
8182
8183 /**
8184 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8185 *
8186 * <p> Requires permission:
8187 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8188 * privileges.
8189 *
8190 * @param subId subscription id
8191 * @param isEnabled {@code true} means enable, {@code false} means disable.
8192 */
8193 @Override
8194 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8196 mApp, subId, "setDataRoamingEnabled");
8197
Pengquan Menga1bb6272018-09-06 09:59:22 -07008198 final long identity = Binder.clearCallingIdentity();
8199 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008200 Phone phone = getPhone(subId);
8201 if (phone != null) {
8202 phone.setDataRoamingEnabled(isEnabled);
8203 }
8204 } finally {
8205 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008206 }
8207 }
8208
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008209 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008210 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008211 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008212 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008213 mApp, subId, "isManualNetworkSelectionAllowed");
8214
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008215 boolean isAllowed = true;
8216 final long identity = Binder.clearCallingIdentity();
8217 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008218 Phone phone = getPhone(subId);
8219 if (phone != null) {
8220 isAllowed = phone.isCspPlmnEnabled();
8221 }
8222 } finally {
8223 Binder.restoreCallingIdentity(identity);
8224 }
8225 return isAllowed;
8226 }
8227
8228 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008229 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008230 // Verify that tha callingPackage belongs to the calling UID
8231 mApp.getSystemService(AppOpsManager.class)
8232 .checkPackage(Binder.getCallingUid(), callingPackage);
8233
Jordan Liu1e142fc2019-04-22 15:10:43 -07008234 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008235 try {
8236 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008237 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008238 } catch (SecurityException e) {
8239 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8240 // has carrier privileges on an active UICC
8241 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8242 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008243 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008244 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008245 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008246
8247 final long identity = Binder.clearCallingIdentity();
8248 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008249 UiccController uiccController = UiccController.getInstance();
8250 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008251 if (hasReadPermission) {
8252 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008253 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008254
8255 // Remove private info if the caller doesn't have access
8256 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8257 for (UiccCardInfo cardInfo : cardInfos) {
8258 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8259 // is available
8260 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8261 if (card == null || card.getUiccProfile() == null) {
8262 // assume no access if the card or profile is unavailable
8263 filteredInfos.add(cardInfo.getUnprivileged());
8264 continue;
8265 }
8266 UiccProfile profile = card.getUiccProfile();
8267 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8268 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8269 filteredInfos.add(cardInfo);
8270 } else {
8271 filteredInfos.add(cardInfo.getUnprivileged());
8272 }
8273 }
8274 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008275 } finally {
8276 Binder.restoreCallingIdentity(identity);
8277 }
8278 }
8279
8280 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008281 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008282 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284 final long identity = Binder.clearCallingIdentity();
8285 try {
8286 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8287 if (slots == null) {
8288 Rlog.i(LOG_TAG, "slots is null.");
8289 return null;
8290 }
8291
8292 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8293 for (int i = 0; i < slots.length; i++) {
8294 UiccSlot slot = slots[i];
8295 if (slot == null) {
8296 continue;
8297 }
8298
Jordan Liu7be7e652019-05-06 18:55:02 +00008299 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008300 UiccCard card = slot.getUiccCard();
8301 if (card != null) {
8302 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008303 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008304 cardId = slot.getEid();
8305 if (TextUtils.isEmpty(cardId)) {
8306 cardId = slot.getIccId();
8307 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308 }
8309
Jordan Liu857451f2019-05-09 16:35:35 -07008310 if (cardId != null) {
8311 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8312 // if cardId is an EID, it's all digits so this is fine
8313 cardId = IccUtils.stripTrailingFs(cardId);
8314 }
8315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008316 int cardState = 0;
8317 switch (slot.getCardState()) {
8318 case CARDSTATE_ABSENT:
8319 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8320 break;
8321 case CARDSTATE_PRESENT:
8322 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8323 break;
8324 case CARDSTATE_ERROR:
8325 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8326 break;
8327 case CARDSTATE_RESTRICTED:
8328 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8329 break;
8330 default:
8331 break;
8332
8333 }
8334
8335 infos[i] = new UiccSlotInfo(
8336 slot.isActive(),
8337 slot.isEuicc(),
8338 cardId,
8339 cardState,
8340 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008341 slot.isExtendedApduSupported(),
8342 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008343 }
8344 return infos;
8345 } finally {
8346 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008347 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008348 }
8349
8350 @Override
8351 public boolean switchSlots(int[] physicalSlots) {
8352 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008353
8354 final long identity = Binder.clearCallingIdentity();
8355 try {
8356 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8357 } finally {
8358 Binder.restoreCallingIdentity(identity);
8359 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008360 }
Jack Yu4c988042018-02-27 15:30:01 -08008361
8362 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008363 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008364 final long identity = Binder.clearCallingIdentity();
8365 try {
8366 return UiccController.getInstance().getCardIdForDefaultEuicc();
8367 } finally {
8368 Binder.restoreCallingIdentity(identity);
8369 }
8370 }
8371
Pengquan Meng85728fb2018-03-12 16:31:21 -07008372 /**
goneil47ffb6e2018-04-06 15:40:58 -07008373 * A test API to reload the UICC profile.
8374 *
8375 * <p>Requires that the calling app has permission
8376 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8377 * @hide
8378 */
8379 @Override
8380 public void refreshUiccProfile(int subId) {
8381 enforceModifyPermission();
8382
8383 final long identity = Binder.clearCallingIdentity();
8384 try {
8385 Phone phone = getPhone(subId);
8386 if (phone == null) {
8387 return;
8388 }
8389 UiccCard uiccCard = phone.getUiccCard();
8390 if (uiccCard == null) {
8391 return;
8392 }
8393 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8394 if (uiccProfile == null) {
8395 return;
8396 }
8397 uiccProfile.refresh();
8398 } finally {
8399 Binder.restoreCallingIdentity(identity);
8400 }
8401 }
8402
8403 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008404 * Returns false if the mobile data is disabled by default, otherwise return true.
8405 */
8406 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008407 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008408 }
8409
8410 /**
8411 * Returns true if the data roaming is enabled by default, i.e the system property
8412 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8413 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8414 */
8415 private boolean getDefaultDataRoamingEnabled(int subId) {
8416 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008417 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008418 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008419 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8420 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8421 return isDataRoamingEnabled;
8422 }
8423
8424 /**
8425 * Returns the default network type for the given {@code subId}, if the default network type is
8426 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8427 */
8428 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008429 List<Integer> list = TelephonyProperties.default_network();
8430 int phoneId = mSubscriptionController.getPhoneId(subId);
8431 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8432 return list.get(phoneId);
8433 }
8434 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008435 }
fionaxua13278b2018-03-21 00:08:13 -07008436
8437 @Override
8438 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008439 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008440 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008441
8442 final long identity = Binder.clearCallingIdentity();
8443 try {
8444 final Phone phone = getPhone(subId);
8445 if (phone == null) {
8446 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8447 return;
8448 }
chen xueaba88a2019-03-15 13:15:10 -07008449 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8450 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008451 if (carrierPrivilegeRules == null) {
8452 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8453 } else {
8454 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008456 } finally {
8457 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008458 }
fionaxua13278b2018-03-21 00:08:13 -07008459 }
8460
8461 @Override
8462 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008463 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008464
8465 final long identity = Binder.clearCallingIdentity();
8466 try {
8467 final Phone phone = getPhone(subId);
8468 if (phone == null) {
8469 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8470 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8471 }
8472 return phone.getCarrierIdListVersion();
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008475 }
fionaxua13278b2018-03-21 00:08:13 -07008476 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008477
8478 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008479 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8480 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008482 mApp, subId, callingPackage, callingFeatureId,
8483 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008484 return -1;
8485 }
8486
8487 final long identity = Binder.clearCallingIdentity();
8488 try {
8489 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8490 } finally {
8491 Binder.restoreCallingIdentity(identity);
8492 }
8493 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008494
8495 @Override
8496 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008497 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008498 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008499 mApp, subId, "getCdmaRoamingMode");
8500
8501 final long identity = Binder.clearCallingIdentity();
8502 try {
8503 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8504 } finally {
8505 Binder.restoreCallingIdentity(identity);
8506 }
8507 }
8508
8509 @Override
8510 public boolean setCdmaRoamingMode(int subId, int mode) {
8511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8512 mApp, subId, "setCdmaRoamingMode");
8513
8514 final long identity = Binder.clearCallingIdentity();
8515 try {
8516 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
8519 }
8520 }
8521
8522 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008523 public int getCdmaSubscriptionMode(int subId) {
8524 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008525 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008526 mApp, subId, "getCdmaSubscriptionMode");
8527
8528 final long identity = Binder.clearCallingIdentity();
8529 try {
8530 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8531 } finally {
8532 Binder.restoreCallingIdentity(identity);
8533 }
8534 }
8535
8536 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008537 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8539 mApp, subId, "setCdmaSubscriptionMode");
8540
8541 final long identity = Binder.clearCallingIdentity();
8542 try {
8543 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8544 } finally {
8545 Binder.restoreCallingIdentity(identity);
8546 }
8547 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008548
sqianc5eccab2018-10-19 18:46:41 -07008549 @Override
sqian8c685422019-02-22 15:55:18 -08008550 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008551 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008552 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008553 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8554 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008555 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8556 }
8557 final long identity = Binder.clearCallingIdentity();
8558 try {
sqian854d44b2018-12-12 16:48:18 -08008559 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8560 for (Phone phone: PhoneFactory.getPhones()) {
8561 if (phone.getEmergencyNumberTracker() != null
8562 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8563 emergencyNumberListInternal.put(
8564 phone.getSubId(),
8565 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8566 }
sqian11b7a0e2018-12-05 18:48:28 -08008567 }
sqian854d44b2018-12-12 16:48:18 -08008568 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008569 } finally {
8570 Binder.restoreCallingIdentity(identity);
8571 }
sqianc5eccab2018-10-19 18:46:41 -07008572 }
8573
8574 @Override
sqian8c685422019-02-22 15:55:18 -08008575 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008576 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008577 if (!exactMatch) {
8578 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008579 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008580 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008581 }
8582 final long identity = Binder.clearCallingIdentity();
8583 try {
sqian854d44b2018-12-12 16:48:18 -08008584 for (Phone phone: PhoneFactory.getPhones()) {
8585 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008586 && phone.getEmergencyNumberTracker()
8587 .isEmergencyNumber(number, exactMatch)) {
8588 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008589 }
sqian11b7a0e2018-12-05 18:48:28 -08008590 }
8591 return false;
8592 } finally {
8593 Binder.restoreCallingIdentity(identity);
8594 }
8595 }
8596
sqianf4ca7ed2019-01-15 18:32:07 -08008597 /**
Shuo Qian479dd9e2021-02-22 18:32:21 -08008598 * Start emergency callback mode for GsmCdmaPhone for testing.
8599 */
8600 @Override
8601 public void startEmergencyCallbackMode() {
8602 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8603 "startEmergencyCallbackMode");
8604 enforceModifyPermission();
8605 final long identity = Binder.clearCallingIdentity();
8606 try {
8607 for (Phone phone : PhoneFactory.getPhones()) {
8608 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8609 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8610 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8611 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8612 gsmCdmaPhone.obtainMessage(
8613 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8614 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8615 }
8616 }
8617 } finally {
8618 Binder.restoreCallingIdentity(identity);
8619 }
8620 }
8621
8622 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008623 * Update emergency number list for test mode.
8624 */
8625 @Override
8626 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8628 "updateEmergencyNumberListTestMode");
8629
8630 final long identity = Binder.clearCallingIdentity();
8631 try {
8632 for (Phone phone: PhoneFactory.getPhones()) {
8633 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8634 if (tracker != null) {
8635 tracker.executeEmergencyNumberTestModeCommand(action, num);
8636 }
8637 }
8638 } finally {
8639 Binder.restoreCallingIdentity(identity);
8640 }
8641 }
8642
8643 /**
8644 * Get the full emergency number list for test mode.
8645 */
8646 @Override
8647 public List<String> getEmergencyNumberListTestMode() {
8648 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8649 "getEmergencyNumberListTestMode");
8650
8651 final long identity = Binder.clearCallingIdentity();
8652 try {
8653 Set<String> emergencyNumbers = new HashSet<>();
8654 for (Phone phone: PhoneFactory.getPhones()) {
8655 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8656 if (tracker != null) {
8657 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8658 emergencyNumbers.add(num.getNumber());
8659 }
8660 }
8661 }
8662 return new ArrayList<>(emergencyNumbers);
8663 } finally {
8664 Binder.restoreCallingIdentity(identity);
8665 }
8666 }
8667
chen xud6b45bd2018-10-30 22:27:10 -07008668 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008669 public int getEmergencyNumberDbVersion(int subId) {
8670 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8671
8672 final long identity = Binder.clearCallingIdentity();
8673 try {
8674 final Phone phone = getPhone(subId);
8675 if (phone == null) {
8676 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8677 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8678 }
8679 return phone.getEmergencyNumberDbVersion();
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
8683 }
8684
8685 @Override
8686 public void notifyOtaEmergencyNumberDbInstalled() {
8687 enforceModifyPermission();
8688
8689 final long identity = Binder.clearCallingIdentity();
8690 try {
8691 for (Phone phone: PhoneFactory.getPhones()) {
8692 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8693 if (tracker != null) {
8694 tracker.updateOtaEmergencyNumberDatabase();
8695 }
8696 }
8697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
8700 }
8701
8702 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008703 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008704 enforceActiveEmergencySessionPermission();
8705
8706 final long identity = Binder.clearCallingIdentity();
8707 try {
8708 for (Phone phone: PhoneFactory.getPhones()) {
8709 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8710 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008711 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8712 }
8713 }
8714 } finally {
8715 Binder.restoreCallingIdentity(identity);
8716 }
8717 }
8718
8719 @Override
8720 public void resetOtaEmergencyNumberDbFilePath() {
8721 enforceActiveEmergencySessionPermission();
8722
8723 final long identity = Binder.clearCallingIdentity();
8724 try {
8725 for (Phone phone: PhoneFactory.getPhones()) {
8726 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8727 if (tracker != null) {
8728 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008729 }
8730 }
8731 } finally {
8732 Binder.restoreCallingIdentity(identity);
8733 }
8734 }
8735
8736 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008737 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8738 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8739 Phone phone = getPhone(subId);
8740 if (phone == null) {
8741 return null;
8742 }
8743 final long identity = Binder.clearCallingIdentity();
8744 try {
8745 UiccProfile profile = UiccController.getInstance()
8746 .getUiccProfileForPhone(phone.getPhoneId());
8747 if (profile != null) {
8748 return profile.getCertsFromCarrierPrivilegeAccessRules();
8749 }
8750 } finally {
8751 Binder.restoreCallingIdentity(identity);
8752 }
8753 return null;
8754 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008755
8756 /**
8757 * Enable or disable a modem stack.
8758 */
8759 @Override
8760 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8761 enforceModifyPermission();
8762
8763 final long identity = Binder.clearCallingIdentity();
8764 try {
8765 Phone phone = PhoneFactory.getPhone(slotIndex);
8766 if (phone == null) {
8767 return false;
8768 } else {
8769 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8770 }
8771 } finally {
8772 Binder.restoreCallingIdentity(identity);
8773 }
8774 }
Michelecea4cf22018-12-21 15:00:11 -08008775
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008776 /**
8777 * Whether a modem stack is enabled or not.
8778 */
8779 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008780 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8781 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008782 Phone phone = PhoneFactory.getPhone(slotIndex);
8783 if (phone == null) return false;
8784
8785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008786 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8787 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008788 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8789 }
8790
8791 final long identity = Binder.clearCallingIdentity();
8792 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008793 try {
8794 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8795 } catch (NoSuchElementException ex) {
8796 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8797 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008798 } finally {
8799 Binder.restoreCallingIdentity(identity);
8800 }
8801 }
8802
Michelecea4cf22018-12-21 15:00:11 -08008803 @Override
Michele0ea7d782019-03-19 14:58:42 -07008804 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008805 enforceModifyPermission();
8806
8807 final long identity = Binder.clearCallingIdentity();
8808 try {
8809 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008810 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008811 .commit();
8812 } finally {
8813 Binder.restoreCallingIdentity(identity);
8814 }
8815 }
8816
8817 @Override
Michele0ea7d782019-03-19 14:58:42 -07008818 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008819 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008820 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008821 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8822 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008823 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008824 }
Michelecea4cf22018-12-21 15:00:11 -08008825
8826 final long identity = Binder.clearCallingIdentity();
8827 try {
Michele0ea7d782019-03-19 14:58:42 -07008828 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008829 } finally {
8830 Binder.restoreCallingIdentity(identity);
8831 }
8832 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008833
Michele0ea7d782019-03-19 14:58:42 -07008834 @TelephonyManager.IsMultiSimSupportedResult
8835 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008836 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8837 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8838 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008839 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8840 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008841 }
8842 // Check if the hardware supports multisim functionality. If usage of multisim is not
8843 // supported by the modem, indicate that it is restricted.
8844 PhoneCapability staticCapability =
8845 mPhoneConfigurationManager.getStaticPhoneCapability();
8846 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008847 loge("isMultiSimSupportedInternal: no static configuration available");
8848 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008849 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008850 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008851 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8852 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008853 }
8854 // Check if support of multiple SIMs is restricted by carrier
8855 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008856 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008857 }
8858
Michele0ea7d782019-03-19 14:58:42 -07008859 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008860 }
8861
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008862 /**
8863 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008864 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8865 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8866 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008867 * @param numOfSims number of active sims we want to switch to
8868 */
8869 @Override
8870 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008871 if (numOfSims == 1) {
8872 enforceModifyPermission();
8873 } else {
8874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8875 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8876 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008877 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008878
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008879 try {
Michele30b57b22019-03-01 12:01:14 -08008880 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008881 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008882 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8883 return;
8884 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008885 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8886 } finally {
8887 Binder.restoreCallingIdentity(identity);
8888 }
8889 }
8890
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008891 @Override
8892 public boolean isApplicationOnUicc(int subId, int appType) {
8893 enforceReadPrivilegedPermission("isApplicationOnUicc");
8894 Phone phone = getPhone(subId);
8895 if (phone == null) {
8896 return false;
8897 }
8898 final long identity = Binder.clearCallingIdentity();
8899 try {
8900 UiccCard uiccCard = phone.getUiccCard();
8901 if (uiccCard == null) {
8902 return false;
8903 }
8904 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8905 if (uiccProfile == null) {
8906 return false;
8907 }
8908 if (TelephonyManager.APPTYPE_SIM <= appType
8909 && appType <= TelephonyManager.APPTYPE_ISIM) {
8910 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8911 }
8912 return false;
8913 } finally {
8914 Binder.restoreCallingIdentity(identity);
8915 }
8916 }
8917
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008918 /**
chen xub4baa772019-04-03 10:23:41 -07008919 * Get whether making changes to modem configurations will trigger reboot.
8920 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008921 */
8922 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008923 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8924 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008926 mApp, subId, callingPackage, callingFeatureId,
8927 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008928 return false;
8929 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008930 final long identity = Binder.clearCallingIdentity();
8931 try {
8932 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8933 } finally {
8934 Binder.restoreCallingIdentity(identity);
8935 }
8936 }
8937
Nathan Harold29f5f052019-02-15 13:41:57 -08008938 private void updateModemStateMetrics() {
8939 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8940 // TODO: check the state for each modem if the api is ready.
8941 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8942 }
8943
Pengquan Meng3889a572019-01-23 11:16:29 -08008944 @Override
8945 public int[] getSlotsMapping() {
8946 enforceReadPrivilegedPermission("getSlotsMapping");
8947
8948 final long identity = Binder.clearCallingIdentity();
8949 try {
8950 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8951 // All logical slots should have a mapping to a physical slot.
8952 int[] logicalSlotsMapping = new int[phoneCount];
8953 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8954 for (int i = 0; i < slotInfos.length; i++) {
8955 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8956 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8957 }
8958 }
8959 return logicalSlotsMapping;
8960 } finally {
8961 Binder.restoreCallingIdentity(identity);
8962 }
8963 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008964
8965 /**
8966 * Get the IRadio HAL Version
8967 */
8968 @Override
8969 public int getRadioHalVersion() {
8970 Phone phone = getDefaultPhone();
8971 if (phone == null) return -1;
8972 HalVersion hv = phone.getHalVersion();
8973 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8974 return hv.major * 100 + hv.minor;
8975 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008976
8977 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008978 * Get the current calling package name.
8979 * @return the current calling package name
8980 */
8981 @Override
8982 public String getCurrentPackageName() {
8983 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8984 }
8985
8986 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008987 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8988 * corresponding network requests on a subId.
8989 *
8990 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008991 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008992 * 2) APN is un-metered for this subscription, or
8993 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008994 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008995 *
8996 * @return whether data is allowed for a apn type.
8997 *
8998 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008999 */
9000 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009001 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009002 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9003 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009004
9005 // Now that all security checks passes, perform the operation as ourselves.
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 Phone phone = getPhone(subId);
9009 if (phone == null) return false;
9010
Jack Yu41407ee2019-05-13 16:54:09 -07009011 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009012 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9013 } finally {
9014 Binder.restoreCallingIdentity(identity);
9015 }
9016 }
9017
9018 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009019 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009020 enforceReadPrivilegedPermission("isApnMetered");
9021
9022 // Now that all security checks passes, perform the operation as ourselves.
9023 final long identity = Binder.clearCallingIdentity();
9024 try {
9025 Phone phone = getPhone(subId);
9026 if (phone == null) return true; // By default return true.
9027
Jack Yu41407ee2019-05-13 16:54:09 -07009028 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009029 } finally {
9030 Binder.restoreCallingIdentity(identity);
9031 }
9032 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009033
9034 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009035 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9036 int subscriptionId, IBooleanConsumer resultCallback) {
9037 enforceModifyPermission();
9038 long token = Binder.clearCallingIdentity();
9039 try {
9040 Phone phone = getPhone(subscriptionId);
9041 if (phone == null) {
9042 try {
9043 if (resultCallback != null) {
9044 resultCallback.accept(false);
9045 }
9046 } catch (RemoteException e) {
9047 // ignore
9048 }
9049 return;
9050 }
9051 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9052 Pair.create(specifiers, (x) -> {
9053 try {
9054 if (resultCallback != null) {
9055 resultCallback.accept(x);
9056 }
9057 } catch (RemoteException e) {
9058 // ignore
9059 }
9060 });
9061 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9062 } finally {
9063 Binder.restoreCallingIdentity(token);
9064 }
9065 }
9066
9067 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009068 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9069 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07009070 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08009071 mApp, subId, "getSystemSelectionChannels");
9072 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9073 final long identity = Binder.clearCallingIdentity();
9074 try {
Sarah Chin58691872021-03-13 03:17:40 -08009075 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9076 if (result instanceof IllegalStateException) {
9077 throw (IllegalStateException) result;
9078 }
9079 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chincc055732020-11-18 13:39:35 -08009080 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9081 return specifiers;
9082 } finally {
9083 Binder.restoreCallingIdentity(identity);
9084 }
9085 }
9086
9087 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009088 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009089 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009090 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9091 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9092 if (iccRecords == null) {
9093 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9094 return false;
9095 }
9096 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9097 }
9098
9099 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009100 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9101 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009102 if (callingPackage == null) {
9103 callingPackage = getCurrentPackageName();
9104 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009105 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9106 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009107 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9108 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009109 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9110 }
9111 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9112 Intent intent = new Intent();
9113 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9114 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9115 // Bring up choose default SMS subscription dialog right now
9116 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9117 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9118 mApp.startActivity(intent);
9119 }
chen xud5ca2d52019-05-28 15:20:57 -07009120
9121 @Override
9122 public String getMmsUAProfUrl(int subId) {
9123 //TODO investigate if this API should require proper permission check in R b/133791609
9124 final long identity = Binder.clearCallingIdentity();
9125 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009126 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9127 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9128 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9129 return carrierUAProfUrl;
9130 }
chen xud5ca2d52019-05-28 15:20:57 -07009131 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9132 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9133 } finally {
9134 Binder.restoreCallingIdentity(identity);
9135 }
9136 }
9137
9138 @Override
9139 public String getMmsUserAgent(int subId) {
9140 //TODO investigate if this API should require proper permission check in R b/133791609
9141 final long identity = Binder.clearCallingIdentity();
9142 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009143 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9144 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9145 if (!TextUtils.isEmpty(carrierUserAgent)) {
9146 return carrierUserAgent;
9147 }
chen xud5ca2d52019-05-28 15:20:57 -07009148 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9149 .getString(com.android.internal.R.string.config_mms_user_agent);
9150 } finally {
9151 Binder.restoreCallingIdentity(identity);
9152 }
9153 }
Jack Yub07d4972019-05-28 16:12:25 -07009154
9155 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009156 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9157 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9158
9159 final long identity = Binder.clearCallingIdentity();
9160 try {
9161 Phone phone = getPhone(subscriptionId);
9162 if (phone == null) return false;
9163
9164 switch (policy) {
9165 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9166 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9167 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9168 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9169 default:
9170 throw new IllegalArgumentException(policy + " is not a valid policy");
9171 }
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
9174 }
9175 }
9176
9177 @Override
9178 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9179 boolean enabled) {
9180 enforceModifyPermission();
9181
9182 final long identity = Binder.clearCallingIdentity();
9183 try {
9184 Phone phone = getPhone(subscriptionId);
9185 if (phone == null) return;
9186
9187 switch (policy) {
9188 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9189 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9190 break;
9191 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9192 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9193 break;
9194 default:
9195 throw new IllegalArgumentException(policy + " is not a valid policy");
9196 }
9197 } finally {
9198 Binder.restoreCallingIdentity(identity);
9199 }
9200 }
9201
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009202 /**
Hall Liub48cf452020-09-25 11:13:49 -07009203 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009204 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9205 * otherwise.
9206 */
9207 @Override
9208 public void setCepEnabled(boolean isCepEnabled) {
9209 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9210
9211 final long identity = Binder.clearCallingIdentity();
9212 try {
9213 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9214 for (Phone phone : PhoneFactory.getPhones()) {
9215 Phone defaultPhone = phone.getImsPhone();
9216 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9217 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9218 ImsPhoneCallTracker imsPhoneCallTracker =
9219 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9220 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9221 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9222 + imsPhone.getMsisdn());
9223 }
9224 }
9225 } finally {
9226 Binder.restoreCallingIdentity(identity);
9227 }
9228 }
allenwtsu46dcc572020-01-08 18:24:03 +08009229
9230 /**
9231 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9232 *
9233 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9234 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9235 * before being read.
9236 */
9237 @Override
9238 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9239 isCompressed) {
9240 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9241 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009242 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9243 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9244 }
9245 if (!isImsAvailableOnDevice()) {
9246 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9247 "IMS not available on device.");
9248 }
9249
9250 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009251 try {
Hui Wang068ab862020-10-31 05:12:53 +00009252 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9253 } finally {
9254 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009255 }
9256 }
zoey chenf95ca592019-12-30 16:11:23 +08009257
9258 @Override
9259 public boolean isIccLockEnabled(int subId) {
9260 enforceReadPrivilegedPermission("isIccLockEnabled");
9261
9262 // Now that all security checks passes, perform the operation as ourselves.
9263 final long identity = Binder.clearCallingIdentity();
9264 try {
9265 Phone phone = getPhone(subId);
9266 if (phone != null && phone.getIccCard() != null) {
9267 return phone.getIccCard().getIccLockEnabled();
9268 } else {
9269 return false;
9270 }
9271 } finally {
9272 Binder.restoreCallingIdentity(identity);
9273 }
9274 }
9275
9276 /**
zoey chene02881a2019-12-30 16:11:23 +08009277 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009278 *
zoey chene02881a2019-12-30 16:11:23 +08009279 * @return an integer representing the status of IccLock enabled or disabled in the following
9280 * three cases:
9281 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9282 * successfully.
9283 * - Positive number and zero for remaining password attempts.
9284 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009285 *
9286 */
9287 @Override
9288 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9289 enforceModifyPermission();
9290
9291 Phone phone = getPhone(subId);
9292 if (phone == null) {
9293 return 0;
9294 }
9295 // Now that all security checks passes, perform the operation as ourselves.
9296 final long identity = Binder.clearCallingIdentity();
9297 try {
9298 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9299 new Pair<Boolean, String>(enabled, password), phone, null);
9300 return attemptsRemaining;
9301
9302 } catch (Exception e) {
9303 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 return 0;
9308 }
9309
9310 /**
9311 * Change the ICC password used in ICC pin lock.
9312 *
zoey chene02881a2019-12-30 16:11:23 +08009313 * @return an integer representing the status of IccLock changed in the following three cases:
9314 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9315 * - Positive number and zero for remaining password attempts.
9316 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009317 *
9318 */
9319 @Override
9320 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9321 enforceModifyPermission();
9322
9323 Phone phone = getPhone(subId);
9324 if (phone == null) {
9325 return 0;
9326 }
9327 // Now that all security checks passes, perform the operation as ourselves.
9328 final long identity = Binder.clearCallingIdentity();
9329 try {
9330 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9331 new Pair<String, String>(oldPassword, newPassword), phone, null);
9332 return attemptsRemaining;
9333
9334 } catch (Exception e) {
9335 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9336 } finally {
9337 Binder.restoreCallingIdentity(identity);
9338 }
9339 return 0;
9340 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009341
Peter Wangdafb9ac2020-01-15 14:13:38 -08009342 /**
9343 * Request for receiving user activity notification
9344 */
9345 @Override
9346 public void requestUserActivityNotification() {
9347 if (!mNotifyUserActivity.get()
9348 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9349 mNotifyUserActivity.set(true);
9350 }
9351 }
9352
9353 /**
9354 * Called when userActivity is signalled in the power manager.
9355 * This is safe to call from any thread, with any window manager locks held or not.
9356 */
9357 @Override
9358 public void userActivity() {
9359 // ***************************************
9360 // * Inherited from PhoneWindowManager *
9361 // ***************************************
9362 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9363 // WITH ITS LOCKS HELD.
9364 //
9365 // This code must be VERY careful about the locks
9366 // it acquires.
9367 // In fact, the current code acquires way too many,
9368 // and probably has lurking deadlocks.
9369
9370 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9371 throw new SecurityException("Only the OS may call notifyUserActivity()");
9372 }
9373
9374 if (mNotifyUserActivity.getAndSet(false)) {
9375 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9376 USER_ACTIVITY_NOTIFICATION_DELAY);
9377 }
9378 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009379
Malcolm Chen884180b2020-04-13 11:59:40 -07009380 @Override
9381 public boolean canConnectTo5GInDsdsMode() {
9382 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9383 }
Jack Yud10cdd42020-09-28 20:28:01 -07009384
9385 @Override
9386 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9387 String callingFeatureId) {
9388 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9389 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9390 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9391 }
9392
9393 Phone phone = getPhone(subId);
9394 if (phone == null) {
9395 throw new RuntimeException("phone is not available");
9396 }
9397 // Now that all security checks passes, perform the operation as ourselves.
9398 final long identity = Binder.clearCallingIdentity();
9399 try {
9400 return phone.getEquivalentHomePlmns();
9401 } finally {
9402 Binder.restoreCallingIdentity(identity);
9403 }
9404 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009405
Hui Wang0866fcc2020-10-12 12:14:23 -07009406 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009407 public boolean isRadioInterfaceCapabilitySupported(
9408 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009409 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009410 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009411 if (radioInterfaceCapabilities == null) {
9412 throw new RuntimeException("radio interface capabilities are not available");
9413 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009414 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009415 }
9416 }
9417
9418 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009419 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9420 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009421 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9422 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9423 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9424 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9425 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009426 if (DBG) {
9427 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9428 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9429 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9430 }
9431
9432 if (!SubscriptionManager.isValidSubscriptionId(subId)
9433 || appType < TelephonyManager.APPTYPE_UNKNOWN
9434 || appType > TelephonyManager.APPTYPE_ISIM
9435 || nafUrl == null || securityProtocol == null || callback == null) {
9436 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9437 if (callback != null) {
9438 try {
9439 callback.onAuthenticationFailure(
9440 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9441 } catch (RemoteException exception) {
9442 log("Fail to notify onAuthenticationFailure due to " + exception);
9443 }
9444 return;
9445 }
9446 }
9447
9448 final long token = Binder.clearCallingIdentity();
9449 try {
9450 getGbaManager(subId).bootstrapAuthenticationRequest(
9451 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9452 forceBootStrapping, callback));
9453 } finally {
9454 Binder.restoreCallingIdentity(token);
9455 }
9456 }
9457
Jack Nudelman24d51a52020-11-24 12:08:04 -08009458 /**
9459 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9460 * requested radio power state will actually be set. See {@link
9461 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9462 *
9463 * @param subId the subscription ID of the phone requesting to set the radio power state.
9464 * @param enable {@code true} if trying to turn radio on.
9465 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9466 * false}.
9467 */
9468 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9469 Phone phone = getPhone(subId);
9470 if (phone != null) {
9471 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9472 return true;
9473 }
9474 return false;
9475 }
9476
9477 private int handleDataThrottlingRequest(int subId,
9478 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009479 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9480 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9481 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9482 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9483 throw new IllegalArgumentException("modem does not support data throttling");
9484 }
9485
Jack Nudelman24d51a52020-11-24 12:08:04 -08009486 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9487 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9488 if (!setRadioPowerForThermal(subId, true)) {
9489 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9490 }
9491
9492 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9493
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009494 if (isDataThrottlingSupported) {
9495 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009496 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009497 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9498 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9499 } else if (thermalMitigationResult
9500 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman20352592021-05-20 13:57:30 -07009501 log("Modem likely does not support data throttling on secondary carrier. Data " +
9502 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9503 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009504 }
9505 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009506 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009507
9508 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009509 }
9510
Jack Nudelman644b91a2021-03-12 14:09:48 -08009511 private static List<String> getThermalMitigationAllowlist(Context context) {
9512 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9513 for (String pckg : context.getResources()
9514 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9515 sThermalMitigationAllowlistedPackages.add(pckg);
9516 }
9517 }
9518
9519 return sThermalMitigationAllowlistedPackages;
9520 }
9521
Jack Nudelmane634f962021-05-13 10:00:15 -07009522 private boolean isAnyPhoneInEmergencyState() {
9523 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9524 if (tm.isInEmergencyCall()) {
9525 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9526 return true;
9527 }
9528 for (Phone phone : PhoneFactory.getPhones()) {
9529 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9530 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9531 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9532 + phone.isInEcm());
9533 return true;
9534 }
9535 }
9536
9537 return false;
9538 }
9539
Jack Nudelman644b91a2021-03-12 14:09:48 -08009540 /**
9541 * Used by shell commands to add an authorized package name for thermal mitigation.
9542 * @param packageName name of package to be allowlisted
9543 * @param context
9544 */
9545 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9546 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9547 sThermalMitigationAllowlistedPackages.add(packageName);
9548 }
9549
9550 /**
9551 * Used by shell commands to remove an authorized package name for thermal mitigation.
9552 * @param packageName name of package to remove from allowlist
9553 * @param context
9554 */
9555 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9556 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9557 sThermalMitigationAllowlistedPackages.remove(packageName);
9558 }
9559
Jack Nudelman24d51a52020-11-24 12:08:04 -08009560 /**
9561 * Thermal mitigation request to control functionalities at modem.
9562 *
9563 * @param subId the id of the subscription.
9564 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009565 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009566 *
9567 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9568 */
9569 @Override
9570 @ThermalMitigationResult
9571 public int sendThermalMitigationRequest(
9572 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009573 ThermalMitigationRequest thermalMitigationRequest,
9574 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009575 enforceModifyPermission();
9576
Jack Nudelman644b91a2021-03-12 14:09:48 -08009577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9578 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9579 .contains(callingPackage)) {
9580 throw new SecurityException("Calling package must be configured in the device config. "
9581 + "calling package: " + callingPackage);
9582 }
9583
Jack Nudelman24d51a52020-11-24 12:08:04 -08009584 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9585 final long identity = Binder.clearCallingIdentity();
9586
9587 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9588 try {
9589 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9590 switch (thermalMitigationAction) {
9591 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9592 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009593 handleDataThrottlingRequest(subId,
9594 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009595 break;
9596 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9597 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9598 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9599 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9600 }
9601
9602 // Ensure that radio is on. If not able to power on due to phone being
9603 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9604 if (!setRadioPowerForThermal(subId, true)) {
9605 thermalMitigationResult =
9606 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9607 break;
9608 }
9609
9610 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9611 false);
9612 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9613 break;
9614 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9615 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9616 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9617 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9618 }
9619
9620 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9621 if (registry != null) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009622 Phone phone = getPhone(subId);
9623 if (phone == null) {
9624 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009625 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009626 break;
9627 }
9628
Jack Nudelmane634f962021-05-13 10:00:15 -07009629 TelephonyConnectionService service =
9630 registry.getTelephonyConnectionService();
Jack Nudelmana80c0012021-06-17 15:39:58 -07009631 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane634f962021-05-13 10:00:15 -07009632 Log.e(LOG_TAG, "An emergency call is pending");
9633 thermalMitigationResult =
9634 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9635 break;
9636 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009637 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009638 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009639 break;
9640 }
9641 } else {
9642 thermalMitigationResult =
9643 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9644 break;
9645 }
9646
9647 // Turn radio off. If not able to power off due to phone being unavailable,
9648 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9649 if (!setRadioPowerForThermal(subId, false)) {
9650 thermalMitigationResult =
9651 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9652 break;
9653 }
9654 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009655 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009656 break;
9657 default:
9658 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9659 + "not exist. Requested action: " + thermalMitigationAction);
9660 }
9661 } catch (IllegalArgumentException e) {
9662 throw e;
9663 } catch (Exception e) {
9664 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9665 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9666 } finally {
9667 Binder.restoreCallingIdentity(identity);
9668 }
9669
9670 if (DBG) {
9671 log("thermalMitigationRequest returning with thermalMitigationResult: "
9672 + thermalMitigationResult);
9673 }
9674
9675 return thermalMitigationResult;
9676 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009677
9678 /**
9679 * Set the GbaService Package Name that Telephony will bind to.
9680 *
9681 * @param subId The sim that the GbaService is associated with.
9682 * @param packageName The name of the package to be replaced with.
9683 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9684 */
9685 @Override
9686 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9687 enforceModifyPermission();
9688
9689 final long identity = Binder.clearCallingIdentity();
9690 try {
9691 return getGbaManager(subId).overrideServicePackage(packageName);
9692 } finally {
9693 Binder.restoreCallingIdentity(identity);
9694 }
9695 }
9696
9697 /**
9698 * Return the package name of the currently bound GbaService.
9699 *
9700 * @param subId The sim that the GbaService is associated with.
9701 * @return the package name of the GbaService configuration, null if GBA is not supported.
9702 */
9703 @Override
9704 public String getBoundGbaService(int subId) {
9705 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9706
9707 final long identity = Binder.clearCallingIdentity();
9708 try {
9709 return getGbaManager(subId).getServicePackage();
9710 } finally {
9711 Binder.restoreCallingIdentity(identity);
9712 }
9713 }
9714
9715 /**
9716 * Set the release time for telephony to unbind GbaService.
9717 *
9718 * @param subId The sim that the GbaService is associated with.
9719 * @param interval The release time to unbind GbaService by millisecond.
9720 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9721 */
9722 @Override
9723 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9724 enforceModifyPermission();
9725
9726 final long identity = Binder.clearCallingIdentity();
9727 try {
9728 return getGbaManager(subId).overrideReleaseTime(interval);
9729 } finally {
9730 Binder.restoreCallingIdentity(identity);
9731 }
9732 }
9733
9734 /**
9735 * Return the release time for telephony to unbind GbaService.
9736 *
9737 * @param subId The sim that the GbaService is associated with.
9738 * @return The release time to unbind GbaService by millisecond.
9739 */
9740 @Override
9741 public int getGbaReleaseTime(int subId) {
9742 enforceReadPrivilegedPermission("getGbaReleaseTime");
9743
9744 final long identity = Binder.clearCallingIdentity();
9745 try {
9746 return getGbaManager(subId).getReleaseTime();
9747 } finally {
9748 Binder.restoreCallingIdentity(identity);
9749 }
9750 }
9751
9752 private GbaManager getGbaManager(int subId) {
9753 GbaManager instance = GbaManager.getInstance(subId);
9754 if (instance == null) {
9755 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9756 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9757 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9758 }
9759 return instance;
9760 }
Hui Wang068ab862020-10-31 05:12:53 +00009761
9762 /**
9763 * indicate whether the device and the carrier can support
9764 * RCS VoLTE single registration.
9765 */
9766 @Override
9767 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009768 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9769 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9770 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9771 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009772
9773 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9774 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9775 }
9776
9777 final long identity = Binder.clearCallingIdentity();
9778 try {
9779 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9780 if (rpm != null) {
Hui Wang048c10a2021-06-21 18:05:57 +00009781 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
9782 if (isCapable != null) {
9783 return isCapable;
9784 }
Hui Wang068ab862020-10-31 05:12:53 +00009785 }
Hui Wang048c10a2021-06-21 18:05:57 +00009786 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
9787 "service is temporarily unavailable.");
Hui Wang068ab862020-10-31 05:12:53 +00009788 } finally {
9789 Binder.restoreCallingIdentity(identity);
9790 }
9791 }
9792
9793 /**
9794 * Register RCS provisioning callback.
9795 */
9796 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009797 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009798 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009799 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009800 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009801 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9802 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009803
9804 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9805 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9806 }
9807 if (!isImsAvailableOnDevice()) {
9808 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9809 "IMS not available on device.");
9810 }
9811
9812 final long identity = Binder.clearCallingIdentity();
9813 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009814 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009815 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009816 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9817 "Service not available for the subscription.");
9818 }
Hui Wang068ab862020-10-31 05:12:53 +00009819 } finally {
9820 Binder.restoreCallingIdentity(identity);
9821 }
9822 }
9823
9824 /**
9825 * Unregister RCS provisioning callback.
9826 */
9827 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009828 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009829 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009830 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009831 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009832 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9833 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009834
9835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9836 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9837 }
9838 if (!isImsAvailableOnDevice()) {
9839 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9840 "IMS not available on device.");
9841 }
9842
9843 final long identity = Binder.clearCallingIdentity();
9844 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009845 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009846 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009847 } finally {
9848 Binder.restoreCallingIdentity(identity);
9849 }
9850 }
9851
9852 /**
9853 * trigger RCS reconfiguration.
9854 */
9855 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009856 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9857 "triggerRcsReconfiguration",
9858 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009859
9860 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9861 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9862 }
9863 if (!isImsAvailableOnDevice()) {
9864 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9865 "IMS not available on device.");
9866 }
9867
9868 final long identity = Binder.clearCallingIdentity();
9869 try {
9870 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9871 } finally {
9872 Binder.restoreCallingIdentity(identity);
9873 }
9874 }
9875
9876 /**
9877 * Provide the client configuration parameters of the RCS application.
9878 */
9879 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009880 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9881 "setRcsClientConfiguration",
9882 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009883
9884 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9885 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9886 }
9887 if (!isImsAvailableOnDevice()) {
9888 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9889 "IMS not available on device.");
9890 }
9891
9892 final long identity = Binder.clearCallingIdentity();
9893
9894 try {
9895 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9896 if (configBinder == null) {
9897 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9898 } else {
9899 configBinder.setRcsClientConfiguration(rcc);
9900 }
9901 } catch (RemoteException e) {
9902 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9903 } finally {
9904 Binder.restoreCallingIdentity(identity);
9905 }
9906 }
9907
9908 /**
Hui Wang19a21872021-02-19 20:45:36 -08009909 * Enables or disables the test mode for RCS VoLTE single registration.
9910 */
9911 @Override
9912 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9913 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9914 "setRcsSingleRegistrationTestModeEnabled");
9915
9916 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9917 }
9918
9919 /**
9920 * Gets the test mode for RCS VoLTE single registration.
9921 */
9922 @Override
9923 public boolean getRcsSingleRegistrationTestModeEnabled() {
9924 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9925 "getRcsSingleRegistrationTestModeEnabled");
9926
9927 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9928 }
9929
9930 /**
Hui Wang068ab862020-10-31 05:12:53 +00009931 * Overrides the config of RCS VoLTE single registration enabled for the device.
9932 */
9933 @Override
9934 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9935 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9936 "setDeviceSingleRegistrationEnabledOverride");
9937 enforceModifyPermission();
9938
9939 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9940 : Boolean.parseBoolean(enabledStr);
9941 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009942 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009943 }
9944
9945 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009946 * Sends a device to device communication message. Only usable via shell.
9947 * @param message message to send.
9948 * @param value message value.
9949 */
9950 @Override
9951 public void sendDeviceToDeviceMessage(int message, int value) {
9952 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9953 "setCarrierSingleRegistrationEnabledOverride");
9954 enforceModifyPermission();
9955
9956 final long identity = Binder.clearCallingIdentity();
9957 try {
9958 TelephonyConnectionService service =
9959 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9960 if (service == null) {
9961 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9962 return;
9963 }
9964 service.sendTestDeviceToDeviceMessage(message, value);
9965 } finally {
9966 Binder.restoreCallingIdentity(identity);
9967 }
9968 }
9969
9970
9971 /**
Hui Wang068ab862020-10-31 05:12:53 +00009972 * Gets the config of RCS VoLTE single registration enabled for the device.
9973 */
9974 @Override
9975 public boolean getDeviceSingleRegistrationEnabled() {
9976 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9977 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9978 }
9979
9980 /**
9981 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9982 */
9983 @Override
9984 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9985 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9986 "setCarrierSingleRegistrationEnabledOverride");
9987 enforceModifyPermission();
9988
9989 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9990 : Boolean.parseBoolean(enabledStr);
9991 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9992 subId, enabled);
9993 }
9994
9995 /**
9996 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9997 */
9998 @Override
9999 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10000 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10001 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10002 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010003
10004 /**
Hui Wangeadb2562021-02-26 09:33:38 -080010005 * Overrides the ims feature validation result
10006 */
10007 @Override
10008 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10009 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10010 "setImsFeatureValidationOverride");
10011
10012 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10013 : Boolean.parseBoolean(enabledStr);
10014 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10015 subId, enabled);
10016 }
10017
10018 /**
10019 * Gets the ims feature validation override value
10020 */
10021 @Override
10022 public boolean getImsFeatureValidationOverride(int subId) {
10023 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10024 "getImsFeatureValidationOverride");
10025 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10026 }
10027
10028 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010029 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10030 * their mobile plan.
10031 */
10032 @Override
10033 public String getMobileProvisioningUrl() {
10034 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10035 final long identity = Binder.clearCallingIdentity();
10036 try {
10037 return getDefaultPhone().getMobileProvisioningUrl();
10038 } finally {
10039 Binder.restoreCallingIdentity(identity);
10040 }
10041 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010042
James.cf Linbcdf8b32021-01-14 16:44:13 +080010043 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010044 * Get the EAB contact from the EAB database.
10045 */
10046 @Override
10047 public String getContactFromEab(String contact) {
10048 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10049 enforceModifyPermission();
10050 final long identity = Binder.clearCallingIdentity();
10051 try {
10052 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10053 } finally {
10054 Binder.restoreCallingIdentity(identity);
10055 }
10056 }
10057
10058 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010059 * Remove the EAB contacts from the EAB database.
10060 */
10061 @Override
10062 public int removeContactFromEab(int subId, String contacts) {
10063 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10064 enforceModifyPermission();
10065 final long identity = Binder.clearCallingIdentity();
10066 try {
10067 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10068 } finally {
10069 Binder.restoreCallingIdentity(identity);
10070 }
10071 }
10072
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010073 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010074 public boolean getDeviceUceEnabled() {
10075 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10076 final long identity = Binder.clearCallingIdentity();
10077 try {
10078 return mApp.getDeviceUceEnabled();
10079 } finally {
10080 Binder.restoreCallingIdentity(identity);
10081 }
10082 }
10083
10084 @Override
10085 public void setDeviceUceEnabled(boolean isEnabled) {
10086 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10087 final long identity = Binder.clearCallingIdentity();
10088 try {
10089 mApp.setDeviceUceEnabled(isEnabled);
10090 } finally {
10091 Binder.restoreCallingIdentity(identity);
10092 }
10093 }
10094
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010095 /**
10096 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10097 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10098 */
10099 // Used for SHELL command only right now.
10100 @Override
10101 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10102 List<String> featureTags) {
10103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10104 "addUceRegistrationOverrideShell");
10105 final long identity = Binder.clearCallingIdentity();
10106 try {
10107 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10108 new ArraySet<>(featureTags));
10109 } catch (ImsException e) {
10110 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10111 } finally {
10112 Binder.restoreCallingIdentity(identity);
10113 }
10114 }
10115
10116 /**
10117 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10118 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10119 */
10120 // Used for SHELL command only right now.
10121 @Override
10122 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10123 List<String> featureTags) {
10124 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10125 "removeUceRegistrationOverrideShell");
10126 final long identity = Binder.clearCallingIdentity();
10127 try {
10128 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10129 new ArraySet<>(featureTags));
10130 } catch (ImsException e) {
10131 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10132 } finally {
10133 Binder.restoreCallingIdentity(identity);
10134 }
10135 }
10136
10137 /**
10138 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10139 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10140 */
10141 // Used for SHELL command only right now.
10142 @Override
10143 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10144 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10145 "clearUceRegistrationOverrideShell");
10146 final long identity = Binder.clearCallingIdentity();
10147 try {
10148 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10149 } catch (ImsException e) {
10150 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10151 } finally {
10152 Binder.restoreCallingIdentity(identity);
10153 }
10154 }
10155
10156 /**
10157 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10158 */
10159 // Used for SHELL command only right now.
10160 @Override
10161 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10162 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10163 "getLatestRcsContactUceCapabilityShell");
10164 final long identity = Binder.clearCallingIdentity();
10165 try {
10166 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10167 } catch (ImsException e) {
10168 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10169 } finally {
10170 Binder.restoreCallingIdentity(identity);
10171 }
10172 }
10173
10174 /**
10175 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10176 * device does not have an active PUBLISH.
10177 */
10178 // Used for SHELL command only right now.
10179 @Override
10180 public String getLastUcePidfXmlShell(int subId) {
10181 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10182 final long identity = Binder.clearCallingIdentity();
10183 try {
10184 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10185 } catch (ImsException e) {
10186 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10187 } finally {
10188 Binder.restoreCallingIdentity(identity);
10189 }
10190 }
10191
James.cf Line8713a42021-04-29 16:04:26 +080010192 /**
10193 * Remove UCE requests cannot be sent to the network status.
10194 */
10195 // Used for SHELL command only right now.
10196 @Override
10197 public boolean removeUceRequestDisallowedStatus(int subId) {
10198 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10199 final long identity = Binder.clearCallingIdentity();
10200 try {
10201 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10202 } catch (ImsException e) {
10203 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10204 } finally {
10205 Binder.restoreCallingIdentity(identity);
10206 }
10207 }
10208
James.cf Lin18bb9002021-05-25 01:37:38 +080010209 /**
10210 * Remove UCE requests cannot be sent to the network status.
10211 */
10212 // Used for SHELL command only.
10213 @Override
10214 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10215 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10216 final long identity = Binder.clearCallingIdentity();
10217 try {
10218 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10219 } catch (ImsException e) {
10220 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10221 } finally {
10222 Binder.restoreCallingIdentity(identity);
10223 }
10224 }
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010225
James.cf Lin4b784aa2021-01-31 03:25:15 +080010226 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010227 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10228 String callingPackage) {
10229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10230 mApp, subId, "setSignalStrengthUpdateRequest");
10231
10232 final int callingUid = Binder.getCallingUid();
10233 // Verify that tha callingPackage belongs to the calling UID
10234 mApp.getSystemService(AppOpsManager.class)
10235 .checkPackage(callingUid, callingPackage);
10236
10237 validateSignalStrengthUpdateRequest(request, callingUid);
10238
10239 final long identity = Binder.clearCallingIdentity();
10240 try {
10241 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10242 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10243
10244 if (result instanceof IllegalStateException) {
10245 throw (IllegalStateException) result;
10246 }
10247 } finally {
10248 Binder.restoreCallingIdentity(identity);
10249 }
10250 }
10251
10252 @Override
10253 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10254 String callingPackage) {
10255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10256 mApp, subId, "clearSignalStrengthUpdateRequest");
10257
10258 final int callingUid = Binder.getCallingUid();
10259 // Verify that tha callingPackage belongs to the calling UID
10260 mApp.getSystemService(AppOpsManager.class)
10261 .checkPackage(callingUid, callingPackage);
10262
10263 final long identity = Binder.clearCallingIdentity();
10264 try {
10265 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10266 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10267
10268 if (result instanceof IllegalStateException) {
10269 throw (IllegalStateException) result;
10270 }
10271 } finally {
10272 Binder.restoreCallingIdentity(identity);
10273 }
10274 }
10275
10276 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10277 int callingUid) {
10278 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10279 // phone/system process do not have further restriction on request
10280 return;
10281 }
10282
10283 // Applications has restrictions on how to use the request:
10284 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10285 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10286 // This is not system caller which has been checked above
10287 throw new IllegalArgumentException(
10288 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10289 }
10290
10291 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10292 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10293 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10294 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10295 || info.isEnabled()) {
10296 throw new IllegalArgumentException(
10297 "Only system can set hide fields in SignalThresholdInfo");
10298 }
10299
10300 // Thresholds length for each RAN need in range. This has been validated in
10301 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10302 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10303 final int[] thresholds = info.getThresholds();
10304 Objects.requireNonNull(thresholds);
10305 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10306 || thresholds.length
10307 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10308 throw new IllegalArgumentException(
10309 "thresholds length is out of range: " + thresholds.length);
10310 }
10311 }
10312 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010313
10314 /**
10315 * Prepare TelephonyManager for an unattended reboot. The reboot is
10316 * required to be done shortly after the API is invoked.
10317 */
10318 @Override
10319 @TelephonyManager.PrepareUnattendedRebootResult
10320 public int prepareForUnattendedReboot() {
10321 enforceRebootPermission();
10322
10323 final long identity = Binder.clearCallingIdentity();
10324 try {
10325 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10326 } finally {
10327 Binder.restoreCallingIdentity(identity);
10328 }
10329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010330}