blob: 3f4643017ea4c9e3154570a62490612a0f6bfef9 [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
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080027import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070028import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070031import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070032import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.content.Context;
34import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070035import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070036import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080037import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070038import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080052import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080053import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070054import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080056import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070058import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070059import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070060import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070061import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080062import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070063import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090064import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080065import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080066import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070067import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070068import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080069import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080070import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070071import android.telephony.CarrierBandwidth;
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;
Daniel Bright52006302021-02-24 19:51:22 +000093import android.telephony.RadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080095import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080096import android.telephony.SignalStrengthUpdateRequest;
97import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080098import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080099import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800100import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700101import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700102import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800103import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800104import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800105import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000106import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700107import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700108import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800109import android.telephony.data.ApnSetting;
110import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700111import android.telephony.gba.GbaAuthRequest;
112import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700113import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000115import android.telephony.ims.RcsClientConfiguration;
Brad 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;
Svet Ganovb320e182015-04-16 12:30:10 -0700165import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700166import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700167import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700168import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800169import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800170import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700172import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800173import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700174import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800175import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700176import com.android.internal.telephony.imsphone.ImsPhone;
177import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800178import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900179import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700180import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800181import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800183import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700184import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800185import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700186import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800187import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000188import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800189import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700190import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700191import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800192import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700193import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700194import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800195import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700196import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700197import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800198import com.android.services.telephony.TelecomAccountRegistry;
199import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800200import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800201
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700202import java.io.FileDescriptor;
203import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800205import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800206import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800207import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800208import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100209import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800210import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700211import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800212import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800213import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800214import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800215import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216
217/**
218 * Implementation of the ITelephony interface.
219 */
Santos Cordon117fee72014-05-16 17:56:12 -0700220public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221 private static final String LOG_TAG = "PhoneInterfaceManager";
222 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
223 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800224 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225
226 // Message codes used with mMainThreadHandler
227 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700228 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
229 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700230 private static final int CMD_OPEN_CHANNEL = 9;
231 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
232 private static final int CMD_CLOSE_CHANNEL = 11;
233 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800234 private static final int CMD_NV_READ_ITEM = 13;
235 private static final int EVENT_NV_READ_ITEM_DONE = 14;
236 private static final int CMD_NV_WRITE_ITEM = 15;
237 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
238 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
239 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700240 private static final int CMD_RESET_MODEM_CONFIG = 19;
241 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800242 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
243 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
244 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
245 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
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;
Michele Berionned9fbae52020-11-13 02:36:59 +0000328 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800330 // Parameters of select command.
331 private static final int SELECT_COMMAND = 0xA4;
332 private static final int SELECT_P1 = 0x04;
333 private static final int SELECT_P2 = 0;
334 private static final int SELECT_P3 = 0x10;
335
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 /** The singleton instance. */
337 private static PhoneInterfaceManager sInstance;
338
Wink Saville3ab207e2014-11-20 13:07:20 -0800339 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800340 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800341 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700342 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800343 private AppOpsManager mAppOps;
344 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800345 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800346 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700347 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Peter Wangdafb9ac2020-01-15 14:13:38 -0800349 /** User Activity */
350 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800351 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
352
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700353 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
354
Derek Tan97ebb422014-09-05 16:55:38 -0700355 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
356 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800357 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800358 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700359
Michelecea4cf22018-12-21 15:00:11 -0800360 // String to store multi SIM allowed
361 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
362
Derek Tan740e1672017-06-27 14:56:27 -0700363 // The AID of ISD-R.
364 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
365
yinxub1bed742017-04-17 11:45:04 -0700366 private NetworkScanRequestTracker mNetworkScanRequestTracker;
367
David Kelly5e06a7f2018-03-12 14:10:59 +0000368 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
369 private static final int MANUFACTURER_CODE_LENGTH = 8;
370
Jack Nudelman24d51a52020-11-24 12:08:04 -0800371 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
372
Derek Tan89e89d42014-07-08 17:00:10 -0700373 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700374 * Experiment flag to enable erase modem config on reset network, default value is false
375 */
376 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
377 "reset_network_erase_modem_config_enabled";
378
Rambo Wang0f050d82021-02-12 11:43:36 -0800379 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
380
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700381 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700382 * A request object to use for transmitting data to an ICC.
383 */
384 private static final class IccAPDUArgument {
385 public int channel, cla, command, p1, p2, p3;
386 public String data;
387
388 public IccAPDUArgument(int channel, int cla, int command,
389 int p1, int p2, int p3, String data) {
390 this.channel = channel;
391 this.cla = cla;
392 this.command = command;
393 this.p1 = p1;
394 this.p2 = p2;
395 this.p3 = p3;
396 this.data = data;
397 }
398 }
399
400 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700401 * A request object to use for transmitting data to an ICC.
402 */
403 private static final class ManualNetworkSelectionArgument {
404 public OperatorInfo operatorInfo;
405 public boolean persistSelection;
406
407 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
408 this.operatorInfo = operatorInfo;
409 this.persistSelection = persistSelection;
410 }
411 }
412
413 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
415 * request after sending. The main thread will notify the request when it is complete.
416 */
417 private static final class MainThreadRequest {
418 /** The argument to use for the request */
419 public Object argument;
420 /** The result of the request that is run on the main thread */
421 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800422 // The subscriber id that this request applies to. Defaults to
423 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
424 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425
Nathan Harold92bed182018-10-12 18:16:49 -0700426 // In cases where subId is unavailable, the caller needs to specify the phone.
427 public Phone phone;
428
vagdeviaf9a5b92018-08-15 16:01:53 -0700429 public WorkSource workSource;
430
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 public MainThreadRequest(Object argument) {
432 this.argument = argument;
433 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800434
Nathan Harold92bed182018-10-12 18:16:49 -0700435 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
436 this.argument = argument;
437 if (phone != null) {
438 this.phone = phone;
439 }
440 this.workSource = workSource;
441 }
442
vagdeviaf9a5b92018-08-15 16:01:53 -0700443 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800444 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800445 if (subId != null) {
446 this.subId = subId;
447 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700448 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 }
451
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800452 private static final class IncomingThirdPartyCallArgs {
453 public final ComponentName component;
454 public final String callId;
455 public final String callerDisplayName;
456
457 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
458 String callerDisplayName) {
459 this.component = component;
460 this.callId = callId;
461 this.callerDisplayName = callerDisplayName;
462 }
463 }
464
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465 /**
466 * A handler that processes messages on the main thread in the phone process. Since many
467 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
468 * inbound binder threads to the main thread in the phone process. The Binder thread
469 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
470 * on, which will be notified when the operation completes and will contain the result of the
471 * request.
472 *
473 * <p>If a MainThreadRequest object is provided in the msg.obj field,
474 * note that request.result must be set to something non-null for the calling thread to
475 * unblock.
476 */
477 private final class MainThreadHandler extends Handler {
478 @Override
479 public void handleMessage(Message msg) {
480 MainThreadRequest request;
481 Message onCompleted;
482 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800483 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800485 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486
487 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 case CMD_HANDLE_USSD_REQUEST: {
489 request = (MainThreadRequest) msg.obj;
490 final Phone phone = getPhoneFromRequest(request);
491 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
492 String ussdRequest = ussdObject.first;
493 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700494
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 if (!isUssdApiAllowed(request.subId)) {
496 // Carrier does not support use of this API, return failure.
497 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
498 UssdResponse response = new UssdResponse(ussdRequest, null);
499 Bundle returnData = new Bundle();
500 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
501 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700502
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 request.result = true;
504 notifyRequester(request);
505 return;
506 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700507
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 try {
509 request.result = phone != null
510 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
511 } catch (CallStateException cse) {
512 request.result = false;
513 }
514 // Wake up the requesting thread
515 notifyRequester(request);
516 break;
pkanwar32d516d2016-10-14 19:37:38 -0700517 }
518
Yorke Lee716f67e2015-06-17 15:39:16 -0700519 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700521 final Phone phone = getPhoneFromRequest(request);
522 request.result = phone != null ?
523 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
524 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700527 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700531 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800533 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700534 if (uiccCard == null) {
535 loge("iccTransmitApduLogicalChannel: No UICC");
536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700537 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
540 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 iccArgument.channel, iccArgument.cla, iccArgument.command,
543 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 break;
547
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
553 } else {
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
555 if (ar.result == null) {
556 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800557 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800559 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 } else {
561 loge("iccTransmitApduLogicalChannel: Unknown exception");
562 }
563 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700564 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
568 request = (MainThreadRequest) msg.obj;
569 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800570 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 if (uiccCard == null) {
572 loge("iccTransmitApduBasicChannel: No UICC");
573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700574 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 } else {
576 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
577 request);
578 uiccCard.iccTransmitApduBasicChannel(
579 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
580 iccArgument.p3, iccArgument.data, onCompleted);
581 }
582 break;
583
584 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
585 ar = (AsyncResult) msg.obj;
586 request = (MainThreadRequest) ar.userObj;
587 if (ar.exception == null && ar.result != null) {
588 request.result = ar.result;
589 } else {
590 request.result = new IccIoResult(0x6F, 0, (byte[])null);
591 if (ar.result == null) {
592 loge("iccTransmitApduBasicChannel: Empty response");
593 } else if (ar.exception instanceof CommandException) {
594 loge("iccTransmitApduBasicChannel: CommandException: " +
595 ar.exception);
596 } else {
597 loge("iccTransmitApduBasicChannel: Unknown exception");
598 }
599 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 break;
602
603 case CMD_EXCHANGE_SIM_IO:
604 request = (MainThreadRequest) msg.obj;
605 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800606 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 if (uiccCard == null) {
608 loge("iccExchangeSimIO: No UICC");
609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 } else {
612 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
613 request);
614 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
615 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
616 iccArgument.data, onCompleted);
617 }
618 break;
619
620 case EVENT_EXCHANGE_SIM_IO_DONE:
621 ar = (AsyncResult) msg.obj;
622 request = (MainThreadRequest) ar.userObj;
623 if (ar.exception == null && ar.result != null) {
624 request.result = ar.result;
625 } else {
626 request.result = new IccIoResult(0x6f, 0, (byte[])null);
627 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 break;
630
Derek Tan4d5e5c12014-02-04 11:54:58 -0800631 case CMD_SEND_ENVELOPE:
632 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800633 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 if (uiccCard == null) {
635 loge("sendEnvelopeWithStatus: No UICC");
636 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 } else {
639 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
640 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
641 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800642 break;
643
644 case EVENT_SEND_ENVELOPE_DONE:
645 ar = (AsyncResult) msg.obj;
646 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700647 if (ar.exception == null && ar.result != null) {
648 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800649 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700650 request.result = new IccIoResult(0x6F, 0, (byte[])null);
651 if (ar.result == null) {
652 loge("sendEnvelopeWithStatus: Empty response");
653 } else if (ar.exception instanceof CommandException) {
654 loge("sendEnvelopeWithStatus: CommandException: " +
655 ar.exception);
656 } else {
657 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
658 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800659 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800661 break;
662
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 case CMD_OPEN_CHANNEL:
664 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800665 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800666 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700667 if (uiccCard == null) {
668 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800669 request.result = new IccOpenLogicalChannelResponse(-1,
670 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 } else {
673 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800674 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
675 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
679 case EVENT_OPEN_CHANNEL_DONE:
680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700682 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 int[] result = (int[]) ar.result;
685 int channelId = result[0];
686 byte[] selectResponse = null;
687 if (result.length > 1) {
688 selectResponse = new byte[result.length - 1];
689 for (int i = 1; i < result.length; ++i) {
690 selectResponse[i - 1] = (byte) result[i];
691 }
692 }
693 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700694 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 if (ar.result == null) {
697 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 if (ar.exception != null) {
700 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
701 }
702
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700703 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700704 if (ar.exception instanceof CommandException) {
705 CommandException.Error error =
706 ((CommandException) (ar.exception)).getCommandError();
707 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700708 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700709 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700710 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700711 }
712 }
713 openChannelResp = new IccOpenLogicalChannelResponse(
714 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700716 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 break;
719
720 case CMD_CLOSE_CHANNEL:
721 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800722 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 if (uiccCard == null) {
724 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900725 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700727 } else {
728 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
729 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
730 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700731 break;
732
733 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800734 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
735 break;
736
737 case CMD_NV_READ_ITEM:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800740 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
741 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800742 break;
743
744 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 ar = (AsyncResult) msg.obj;
746 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800747 if (ar.exception == null && ar.result != null) {
748 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700749 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800750 request.result = "";
751 if (ar.result == null) {
752 loge("nvReadItem: Empty response");
753 } else if (ar.exception instanceof CommandException) {
754 loge("nvReadItem: CommandException: " +
755 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800757 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 }
759 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 break;
762
Jake Hambye994d462014-02-03 13:10:13 -0800763 case CMD_NV_WRITE_ITEM:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
766 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800767 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700768 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800769 break;
770
771 case EVENT_NV_WRITE_ITEM_DONE:
772 handleNullReturnEvent(msg, "nvWriteItem");
773 break;
774
775 case CMD_NV_WRITE_CDMA_PRL:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800778 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800779 break;
780
781 case EVENT_NV_WRITE_CDMA_PRL_DONE:
782 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
783 break;
784
chen xu6dac5ab2018-10-26 17:39:23 -0700785 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800786 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700787 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800788 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800789 break;
790
chen xu6dac5ab2018-10-26 17:39:23 -0700791 case EVENT_RESET_MODEM_CONFIG_DONE:
792 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800793 break;
794
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700795 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
798 request);
799 Phone phone = getPhoneFromRequest(request);
800 if (phone != null) {
801 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
802 } else {
803 loge("isNRDualConnectivityEnabled: No phone object");
804 request.result = false;
805 notifyRequester(request);
806 }
807 break;
808 }
809
810 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
811 ar = (AsyncResult) msg.obj;
812 request = (MainThreadRequest) ar.userObj;
813 if (ar.exception == null && ar.result != null) {
814 request.result = ar.result;
815 } else {
816 // request.result must be set to something non-null
817 // for the calling thread to unblock
818 if (request.result != null) {
819 request.result = ar.result;
820 } else {
821 request.result = false;
822 }
823 if (ar.result == null) {
824 loge("isNRDualConnectivityEnabled: Empty response");
825 } else if (ar.exception instanceof CommandException) {
826 loge("isNRDualConnectivityEnabled: CommandException: "
827 + ar.exception);
828 } else {
829 loge("isNRDualConnectivityEnabled: Unknown exception");
830 }
831 }
832 notifyRequester(request);
833 break;
834
835 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
836 request = (MainThreadRequest) msg.obj;
837 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
838 Phone phone = getPhoneFromRequest(request);
839 if (phone != null) {
840 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
841 request.workSource);
842 } else {
843 loge("enableNrDualConnectivity: No phone object");
844 request.result =
845 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
846 notifyRequester(request);
847 }
848 break;
849 }
850
851 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null) {
855 request.result =
856 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
857 } else {
858 request.result =
859 TelephonyManager
860 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
861 if (ar.exception instanceof CommandException) {
862 CommandException.Error error =
863 ((CommandException) (ar.exception)).getCommandError();
864 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
865 request.result =
866 TelephonyManager
867 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
868 }
869 loge("enableNrDualConnectivity" + ": CommandException: "
870 + ar.exception);
871 } else {
872 loge("enableNrDualConnectivity" + ": Unknown exception");
873 }
874 }
875 notifyRequester(request);
876 break;
877 }
878
Jake Hamby7c27be32014-03-03 13:25:59 -0800879 case CMD_GET_PREFERRED_NETWORK_TYPE:
880 request = (MainThreadRequest) msg.obj;
881 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700882 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800883 break;
884
885 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
886 ar = (AsyncResult) msg.obj;
887 request = (MainThreadRequest) ar.userObj;
888 if (ar.exception == null && ar.result != null) {
889 request.result = ar.result; // Integer
890 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530891 // request.result must be set to something non-null
892 // for the calling thread to unblock
893 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800894 if (ar.result == null) {
895 loge("getPreferredNetworkType: Empty response");
896 } else if (ar.exception instanceof CommandException) {
897 loge("getPreferredNetworkType: CommandException: " +
898 ar.exception);
899 } else {
900 loge("getPreferredNetworkType: Unknown exception");
901 }
902 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700903 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 break;
905
906 case CMD_SET_PREFERRED_NETWORK_TYPE:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
909 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700910 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800911 break;
912
913 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
914 handleNullReturnEvent(msg, "setPreferredNetworkType");
915 break;
916
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000917 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
918 request = (MainThreadRequest)msg.obj;
919 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800920 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000921 break;
922
923 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
924 ar = (AsyncResult)msg.obj;
925 request = (MainThreadRequest)ar.userObj;
926 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700927 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000928 break;
929
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800930 case CMD_SET_VOICEMAIL_NUMBER:
931 request = (MainThreadRequest) msg.obj;
932 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
933 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800934 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
935 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800936 break;
937
938 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
939 handleNullReturnEvent(msg, "setVoicemailNumber");
940 break;
941
Stuart Scott54788802015-03-30 13:18:01 -0700942 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
943 request = (MainThreadRequest) msg.obj;
944 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
945 request);
946 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
947 break;
948
949 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
950 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
951 break;
952
Shishir Agrawal302c8692015-06-19 13:49:39 -0700953 case CMD_PERFORM_NETWORK_SCAN:
954 request = (MainThreadRequest) msg.obj;
955 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
956 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
957 break;
958
Hall Liua1acea22020-09-18 19:04:59 -0700959 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700962 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
963 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
964 request.argument;
965 int callForwardingReason = args.first;
966 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800967 break;
Hall Liua1acea22020-09-18 19:04:59 -0700968 }
969 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800970 ar = (AsyncResult) msg.obj;
971 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700972 TelephonyManager.CallForwardingInfoCallback callback =
973 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
974 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800975 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700976 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800977 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
978 for (CallForwardInfo callForwardInfo : callForwardInfos) {
979 // Service Class is a bit mask per 3gpp 27.007. Search for
980 // any service for voice call.
981 if ((callForwardInfo.serviceClass
982 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700983 callForwardingInfo = new CallForwardingInfo(true,
984 callForwardInfo.reason,
985 callForwardInfo.number,
986 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800987 break;
988 }
989 }
990 // Didn't find a call forward info for voice call.
991 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700992 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
993 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800994 }
Hall Liua1acea22020-09-18 19:04:59 -0700995 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800996 } else {
997 if (ar.result == null) {
998 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
999 }
1000 if (ar.exception != null) {
1001 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1002 }
Hall Liuae527aa2020-09-29 17:10:18 -07001003 int errorCode = TelephonyManager
1004 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001005 if (ar.exception instanceof CommandException) {
1006 CommandException.Error error =
1007 ((CommandException) (ar.exception)).getCommandError();
1008 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001009 errorCode = TelephonyManager
1010 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001011 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001012 errorCode = TelephonyManager
1013 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001014 }
1015 }
Hall Liua1acea22020-09-18 19:04:59 -07001016 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001017 }
sqian80370722020-01-29 15:02:51 -08001018 break;
Hall Liua1acea22020-09-18 19:04:59 -07001019 }
sqian80370722020-01-29 15:02:51 -08001020
Hall Liua1acea22020-09-18 19:04:59 -07001021 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001024 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001025 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001026 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1027 request.argument).first;
1028 request.phone.setCallForwardingOption(
1029 callForwardingInfoToSet.isEnabled()
1030 ? CommandsInterface.CF_ACTION_ENABLE
1031 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001032 callForwardingInfoToSet.getReason(),
1033 callForwardingInfoToSet.getNumber(),
1034 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1035 break;
Hall Liua1acea22020-09-18 19:04:59 -07001036 }
sqian80370722020-01-29 15:02:51 -08001037
Hall Liua1acea22020-09-18 19:04:59 -07001038 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001041 Consumer<Integer> callback =
1042 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1043 request.argument).second;
1044 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001045 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001046 int errorCode = TelephonyManager.CallForwardingInfoCallback
1047 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001048 if (ar.exception instanceof CommandException) {
1049 CommandException.Error error =
1050 ((CommandException) (ar.exception)).getCommandError();
1051 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001052 errorCode = TelephonyManager.CallForwardingInfoCallback
1053 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001054 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001055 errorCode = TelephonyManager.CallForwardingInfoCallback
1056 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001057 }
1058 }
1059 callback.accept(errorCode);
1060 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001061 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001062 }
sqian80370722020-01-29 15:02:51 -08001063 break;
Hall Liua1acea22020-09-18 19:04:59 -07001064 }
sqian80370722020-01-29 15:02:51 -08001065
Hall Liua1acea22020-09-18 19:04:59 -07001066 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001067 request = (MainThreadRequest) msg.obj;
1068 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1069 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1070 break;
Hall Liua1acea22020-09-18 19:04:59 -07001071 }
sqian80370722020-01-29 15:02:51 -08001072
Hall Liua1acea22020-09-18 19:04:59 -07001073 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001074 ar = (AsyncResult) msg.obj;
1075 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001076 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001077 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1078 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001079 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001080 // Service Class is a bit mask per 3gpp 27.007.
1081 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001082 if (callForwardResults.length > 1
1083 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001084 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001085 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001086 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1087 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001088 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001089 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001090 }
1091 } else {
1092 if (ar.result == null) {
1093 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1094 }
1095 if (ar.exception != null) {
1096 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1097 }
1098 if (ar.exception instanceof CommandException) {
1099 CommandException.Error error =
1100 ((CommandException) (ar.exception)).getCommandError();
1101 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1102 callForwardingStatus =
1103 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1104 }
1105 }
1106 }
Hall Liua1acea22020-09-18 19:04:59 -07001107 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001108 break;
Hall Liua1acea22020-09-18 19:04:59 -07001109 }
sqian80370722020-01-29 15:02:51 -08001110
Hall Liua1acea22020-09-18 19:04:59 -07001111 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001112 request = (MainThreadRequest) msg.obj;
1113 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001114 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1115 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001116 break;
Hall Liua1acea22020-09-18 19:04:59 -07001117 }
sqian80370722020-01-29 15:02:51 -08001118
Hall Liua1acea22020-09-18 19:04:59 -07001119 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001120 ar = (AsyncResult) msg.obj;
1121 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001122 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1123 Consumer<Integer> callback =
1124 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1125 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001126 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001127 if (ar.exception instanceof CommandException) {
1128 CommandException.Error error =
1129 ((CommandException) (ar.exception)).getCommandError();
1130 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1131 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1132 } else {
1133 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1134 }
1135 } else {
1136 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1137 }
1138 } else {
1139 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1140 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001141 }
sqian80370722020-01-29 15:02:51 -08001142 break;
Hall Liua1acea22020-09-18 19:04:59 -07001143 }
sqian80370722020-01-29 15:02:51 -08001144
Shishir Agrawal302c8692015-06-19 13:49:39 -07001145 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1146 ar = (AsyncResult) msg.obj;
1147 request = (MainThreadRequest) ar.userObj;
1148 CellNetworkScanResult cellScanResult;
1149 if (ar.exception == null && ar.result != null) {
1150 cellScanResult = new CellNetworkScanResult(
1151 CellNetworkScanResult.STATUS_SUCCESS,
1152 (List<OperatorInfo>) ar.result);
1153 } else {
1154 if (ar.result == null) {
1155 loge("getCellNetworkScanResults: Empty response");
1156 }
1157 if (ar.exception != null) {
1158 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1159 }
1160 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1161 if (ar.exception instanceof CommandException) {
1162 CommandException.Error error =
1163 ((CommandException) (ar.exception)).getCommandError();
1164 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1165 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1166 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1167 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1168 }
1169 }
1170 cellScanResult = new CellNetworkScanResult(errorCode, null);
1171 }
1172 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001173 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001174 break;
1175
1176 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1177 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001178 ManualNetworkSelectionArgument selArg =
1179 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001180 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1181 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001182 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1183 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001184 break;
1185
1186 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001187 ar = (AsyncResult) msg.obj;
1188 request = (MainThreadRequest) ar.userObj;
1189 if (ar.exception == null) {
1190 request.result = true;
1191 } else {
1192 request.result = false;
1193 loge("setNetworkSelectionModeManual " + ar.exception);
1194 }
1195 notifyRequester(request);
1196 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001197 break;
1198
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001199 case CMD_GET_MODEM_ACTIVITY_INFO:
1200 request = (MainThreadRequest) msg.obj;
1201 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001202 if (defaultPhone != null) {
1203 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001204 } else {
1205 ResultReceiver result = (ResultReceiver) request.argument;
1206 Bundle bundle = new Bundle();
1207 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1208 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1209 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001210 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001211 break;
1212
1213 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1214 ar = (AsyncResult) msg.obj;
1215 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001216 ResultReceiver result = (ResultReceiver) request.argument;
1217
1218 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001219 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001220 // Update the last modem activity info and the result of the request.
1221 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1222 if (isModemActivityInfoValid(info)) {
1223 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1224 int[] txTimeMs = info.getTransmitTimeMillis();
1225 int[] lastModemTxTimeMs = mLastModemActivityInfo
1226 .getTransmitTimeMillis();
1227 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1228 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1229 }
1230 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1231 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1232 + mLastModemActivityInfo.getSleepTimeMillis());
1233 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1234 + mLastModemActivityInfo.getIdleTimeMillis());
1235 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1236 mLastModemActivityInfo.setReceiveTimeMillis(
1237 info.getReceiveTimeMillis()
1238 + mLastModemActivityInfo.getReceiveTimeMillis());
1239 }
1240 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1241 mLastModemActivityInfo.getSleepTimeMillis(),
1242 mLastModemActivityInfo.getIdleTimeMillis(),
1243 mLastModemActivityInfo.getTransmitTimeMillis(),
1244 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001245 } else {
1246 if (ar.result == null) {
1247 loge("queryModemActivityInfo: Empty response");
1248 } else if (ar.exception instanceof CommandException) {
1249 loge("queryModemActivityInfo: CommandException: " +
1250 ar.exception);
1251 } else {
1252 loge("queryModemActivityInfo: Unknown exception");
1253 }
1254 }
sqian1a1be542020-03-05 11:37:28 -08001255 Bundle bundle = new Bundle();
1256 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1257 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001258 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001259 break;
1260
Meng Wang1a7c35a2016-05-05 20:56:15 -07001261 case CMD_SET_ALLOWED_CARRIERS:
1262 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001263 CarrierRestrictionRules argument =
1264 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001265 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001266 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001267 break;
1268
1269 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1270 ar = (AsyncResult) msg.obj;
1271 request = (MainThreadRequest) ar.userObj;
1272 if (ar.exception == null && ar.result != null) {
1273 request.result = ar.result;
1274 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001275 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1276 if (ar.exception instanceof CommandException) {
1277 loge("setAllowedCarriers: CommandException: " + ar.exception);
1278 CommandException.Error error =
1279 ((CommandException) (ar.exception)).getCommandError();
1280 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1281 request.result =
1282 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1283 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001284 } else {
1285 loge("setAllowedCarriers: Unknown exception");
1286 }
1287 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001288 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001289 break;
1290
1291 case CMD_GET_ALLOWED_CARRIERS:
1292 request = (MainThreadRequest) msg.obj;
1293 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001294 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001295 break;
1296
1297 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1298 ar = (AsyncResult) msg.obj;
1299 request = (MainThreadRequest) ar.userObj;
1300 if (ar.exception == null && ar.result != null) {
1301 request.result = ar.result;
1302 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001303 request.result = new IllegalStateException(
1304 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001305 if (ar.result == null) {
1306 loge("getAllowedCarriers: Empty response");
1307 } else if (ar.exception instanceof CommandException) {
1308 loge("getAllowedCarriers: CommandException: " +
1309 ar.exception);
1310 } else {
1311 loge("getAllowedCarriers: Unknown exception");
1312 }
1313 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001314 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001315 break;
1316
Nathan Haroldb3014052017-01-25 15:57:32 -08001317 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1318 ar = (AsyncResult) msg.obj;
1319 request = (MainThreadRequest) ar.userObj;
1320 if (ar.exception == null && ar.result != null) {
1321 request.result = ar.result;
1322 } else {
1323 request.result = new IllegalArgumentException(
1324 "Failed to retrieve Forbidden Plmns");
1325 if (ar.result == null) {
1326 loge("getForbiddenPlmns: Empty response");
1327 } else {
1328 loge("getForbiddenPlmns: Unknown exception");
1329 }
1330 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001331 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001332 break;
1333
1334 case CMD_GET_FORBIDDEN_PLMNS:
1335 request = (MainThreadRequest) msg.obj;
1336 uiccCard = getUiccCardFromRequest(request);
1337 if (uiccCard == null) {
1338 loge("getForbiddenPlmns() UiccCard is null");
1339 request.result = new IllegalArgumentException(
1340 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001341 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001342 break;
1343 }
1344 Integer appType = (Integer) request.argument;
1345 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1346 if (uiccApp == null) {
1347 loge("getForbiddenPlmns() no app with specified type -- "
1348 + appType);
1349 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001350 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001351 break;
1352 } else {
1353 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1354 + " specified type -- " + appType);
1355 }
1356 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1357 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1358 onCompleted);
1359 break;
1360
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001361 case CMD_SWITCH_SLOTS:
1362 request = (MainThreadRequest) msg.obj;
1363 int[] physicalSlots = (int[]) request.argument;
1364 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1365 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1366 break;
1367
1368 case EVENT_SWITCH_SLOTS_DONE:
1369 ar = (AsyncResult) msg.obj;
1370 request = (MainThreadRequest) ar.userObj;
1371 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001372 notifyRequester(request);
1373 break;
1374 case CMD_GET_NETWORK_SELECTION_MODE:
1375 request = (MainThreadRequest) msg.obj;
1376 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1377 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1378 break;
1379
1380 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1381 ar = (AsyncResult) msg.obj;
1382 request = (MainThreadRequest) ar.userObj;
1383 if (ar.exception != null) {
1384 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1385 } else {
1386 int mode = ((int[]) ar.result)[0];
1387 if (mode == 0) {
1388 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1389 } else {
1390 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1391 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001392 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001393 notifyRequester(request);
1394 break;
1395 case CMD_GET_CDMA_ROAMING_MODE:
1396 request = (MainThreadRequest) msg.obj;
1397 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1398 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1399 break;
1400 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
1403 if (ar.exception != null) {
1404 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1405 } else {
1406 request.result = ((int[]) ar.result)[0];
1407 }
1408 notifyRequester(request);
1409 break;
1410 case CMD_SET_CDMA_ROAMING_MODE:
1411 request = (MainThreadRequest) msg.obj;
1412 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1413 int mode = (int) request.argument;
1414 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1415 break;
1416 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1417 ar = (AsyncResult) msg.obj;
1418 request = (MainThreadRequest) ar.userObj;
1419 request.result = ar.exception == null;
1420 notifyRequester(request);
1421 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001422 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1423 request = (MainThreadRequest) msg.obj;
1424 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1425 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1426 break;
1427 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1428 ar = (AsyncResult) msg.obj;
1429 request = (MainThreadRequest) ar.userObj;
1430 if (ar.exception != null) {
1431 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1432 } else {
1433 request.result = ((int[]) ar.result)[0];
1434 }
1435 notifyRequester(request);
1436 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001437 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1438 request = (MainThreadRequest) msg.obj;
1439 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1440 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001441 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1442 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001443 break;
1444 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1445 ar = (AsyncResult) msg.obj;
1446 request = (MainThreadRequest) ar.userObj;
1447 request.result = ar.exception == null;
1448 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001449 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001450 case CMD_GET_ALL_CELL_INFO:
1451 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001452 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001453 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001454 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001455 case EVENT_GET_ALL_CELL_INFO_DONE:
1456 ar = (AsyncResult) msg.obj;
1457 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001458 // If a timeout occurs, the response will be null
1459 request.result = (ar.exception == null && ar.result != null)
1460 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001461 synchronized (request) {
1462 request.notifyAll();
1463 }
1464 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001465 case CMD_REQUEST_CELL_INFO_UPDATE:
1466 request = (MainThreadRequest) msg.obj;
1467 request.phone.requestCellInfoUpdate(request.workSource,
1468 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1469 break;
1470 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
1473 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1474 try {
1475 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001476 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001477 cb.onError(
1478 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1479 ar.exception.getClass().getName(),
1480 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001481 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001482 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001483 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001484 } else {
1485 // use the result as returned
1486 cb.onCellInfo((List<CellInfo>) ar.result);
1487 }
1488 } catch (RemoteException re) {
1489 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1490 }
1491 break;
Sarah Chincc055732020-11-18 13:39:35 -08001492 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 request = (MainThreadRequest) msg.obj;
1494 WorkSource ws = (WorkSource) request.argument;
1495 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001496 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001497 break;
Sarah Chincc055732020-11-18 13:39:35 -08001498 }
1499 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001500 ar = (AsyncResult) msg.obj;
1501 request = (MainThreadRequest) ar.userObj;
1502 if (ar.exception == null) {
1503 request.result = ar.result;
1504 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001505 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001506 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001507 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001508 }
1509
1510 synchronized (request) {
1511 request.notifyAll();
1512 }
1513 break;
Sarah Chincc055732020-11-18 13:39:35 -08001514 }
chen xu6dac5ab2018-10-26 17:39:23 -07001515 case CMD_MODEM_REBOOT:
1516 request = (MainThreadRequest) msg.obj;
1517 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001518 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001519 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001520 case EVENT_CMD_MODEM_REBOOT_DONE:
1521 handleNullReturnEvent(msg, "rebootModem");
1522 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001523 case CMD_REQUEST_ENABLE_MODEM:
1524 request = (MainThreadRequest) msg.obj;
1525 boolean enable = (boolean) request.argument;
1526 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001527 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001528 PhoneConfigurationManager.getInstance()
1529 .enablePhone(request.phone, enable, onCompleted);
1530 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001531 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001532 ar = (AsyncResult) msg.obj;
1533 request = (MainThreadRequest) ar.userObj;
1534 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001535 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001536 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001537 if ((boolean) request.result) {
1538 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1539 updateModemStateMetrics();
1540 } else {
1541 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1542 + ar.exception);
1543 }
1544 notifyRequester(request);
1545 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001546 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001547 case CMD_GET_MODEM_STATUS:
1548 request = (MainThreadRequest) msg.obj;
1549 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1550 PhoneConfigurationManager.getInstance()
1551 .getPhoneStatusFromModem(request.phone, onCompleted);
1552 break;
1553 case EVENT_GET_MODEM_STATUS_DONE:
1554 ar = (AsyncResult) msg.obj;
1555 request = (MainThreadRequest) ar.userObj;
1556 int id = request.phone.getPhoneId();
1557 if (ar.exception == null && ar.result != null) {
1558 request.result = ar.result;
1559 //update the cache as modem status has changed
1560 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1561 (boolean) request.result);
1562 } else {
1563 // Return true if modem status cannot be retrieved. For most cases,
1564 // modem status is on. And for older version modems, GET_MODEM_STATUS
1565 // and disable modem are not supported. Modem is always on.
1566 // TODO: this should be fixed in R to support a third
1567 // status UNKNOWN b/131631629
1568 request.result = true;
1569 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1570 + ar.exception);
1571 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001572 notifyRequester(request);
1573 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001574 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1575 request = (MainThreadRequest) msg.obj;
1576 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1577 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1578 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1579 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1580 break;
1581 }
1582 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1583 ar = (AsyncResult) msg.obj;
1584 request = (MainThreadRequest) ar.userObj;
1585 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1586 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1587 args.second.accept(ar.exception == null);
1588 notifyRequester(request);
1589 break;
1590 }
Sarah Chincc055732020-11-18 13:39:35 -08001591 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1592 request = (MainThreadRequest) msg.obj;
1593 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1594 Phone phone = getPhoneFromRequest(request);
1595 if (phone != null) {
1596 phone.getSystemSelectionChannels(onCompleted);
1597 } else {
1598 loge("getSystemSelectionChannels: No phone object");
1599 request.result = new ArrayList<RadioAccessSpecifier>();
1600 notifyRequester(request);
1601 }
1602 break;
1603 }
1604 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
1607 if (ar.exception == null && ar.result != null) {
1608 request.result = ar.result;
1609 } else {
1610 request.result = new IllegalArgumentException(
1611 "Failed to retrieve system selection channels");
1612 if (ar.result == null) {
1613 loge("getSystemSelectionChannels: Empty response");
1614 } else {
1615 loge("getSystemSelectionChannels: Unknown exception");
1616 }
1617 }
1618 notifyRequester(request);
1619 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001620 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1621 ar = (AsyncResult) msg.obj;
1622 request = (MainThreadRequest) ar.userObj;
1623 if (ar.exception == null && ar.result != null) {
1624 request.result = ar.result;
1625 } else {
1626 request.result = -1;
1627 loge("Failed to set Forbidden Plmns");
1628 if (ar.result == null) {
1629 loge("setForbidenPlmns: Empty response");
1630 } else if (ar.exception != null) {
1631 loge("setForbiddenPlmns: Exception: " + ar.exception);
1632 request.result = -1;
1633 } else {
1634 loge("setForbiddenPlmns: Unknown exception");
1635 }
1636 }
1637 notifyRequester(request);
1638 break;
1639 case CMD_SET_FORBIDDEN_PLMNS:
1640 request = (MainThreadRequest) msg.obj;
1641 uiccCard = getUiccCardFromRequest(request);
1642 if (uiccCard == null) {
1643 loge("setForbiddenPlmns: UiccCard is null");
1644 request.result = -1;
1645 notifyRequester(request);
1646 break;
1647 }
1648 Pair<Integer, List<String>> setFplmnsArgs =
1649 (Pair<Integer, List<String>>) request.argument;
1650 appType = setFplmnsArgs.first;
1651 List<String> fplmns = setFplmnsArgs.second;
1652 uiccApp = uiccCard.getApplicationByType(appType);
1653 if (uiccApp == null) {
1654 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1655 request.result = -1;
1656 loge("Failed to get UICC App");
1657 notifyRequester(request);
1658 } else {
1659 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1660 ((SIMRecords) uiccApp.getIccRecords())
1661 .setForbiddenPlmns(onCompleted, fplmns);
1662 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001663 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001664 case CMD_ERASE_MODEM_CONFIG:
1665 request = (MainThreadRequest) msg.obj;
1666 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1667 defaultPhone.eraseModemConfig(onCompleted);
1668 break;
1669 case EVENT_ERASE_MODEM_CONFIG_DONE:
1670 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001671 break;
zoey chenf95ca592019-12-30 16:11:23 +08001672
1673 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1674 request = (MainThreadRequest) msg.obj;
1675 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1676 Pair<String, String> changed = (Pair<String, String>) request.argument;
1677 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1678 changed.first, changed.second, onCompleted);
1679 break;
1680 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1681 ar = (AsyncResult) msg.obj;
1682 request = (MainThreadRequest) ar.userObj;
1683 if (ar.exception == null) {
1684 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001685 // If the operation is successful, update the PIN storage
1686 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1687 int phoneId = getPhoneFromRequest(request).getPhoneId();
1688 UiccController.getInstance().getPinStorage()
1689 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001690 } else {
1691 request.result = msg.arg1;
1692 }
1693 notifyRequester(request);
1694 break;
1695
Michele Berionned9fbae52020-11-13 02:36:59 +00001696 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001697 request = (MainThreadRequest) msg.obj;
1698 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1699 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1700 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1701 enabled.first, enabled.second, onCompleted);
1702 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001703 }
zoey chenf95ca592019-12-30 16:11:23 +08001704 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1705 ar = (AsyncResult) msg.obj;
1706 request = (MainThreadRequest) ar.userObj;
1707 if (ar.exception == null) {
1708 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001709 // If the operation is successful, update the PIN storage
1710 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1711 int phoneId = getPhoneFromRequest(request).getPhoneId();
1712 if (enabled.first) {
1713 UiccController.getInstance().getPinStorage()
1714 .storePin(enabled.second, phoneId);
1715 } else {
1716 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1717 }
zoey chenf95ca592019-12-30 16:11:23 +08001718 } else {
1719 request.result = msg.arg1;
1720 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001721
1722
zoey chenf95ca592019-12-30 16:11:23 +08001723 notifyRequester(request);
1724 break;
1725
Peter Wangdafb9ac2020-01-15 14:13:38 -08001726 case MSG_NOTIFY_USER_ACTIVITY:
1727 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001728 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001729 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1730 getDefaultPhone().getContext().sendBroadcastAsUser(
1731 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1732 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001733
1734 case CMD_SET_DATA_THROTTLING: {
1735 request = (MainThreadRequest) msg.obj;
1736 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1737 DataThrottlingRequest dataThrottlingRequest =
1738 (DataThrottlingRequest) request.argument;
1739 Phone phone = getPhoneFromRequest(request);
1740 if (phone != null) {
1741 phone.setDataThrottling(onCompleted,
1742 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1743 dataThrottlingRequest.getCompletionDurationMillis());
1744 } else {
1745 loge("setDataThrottling: No phone object");
1746 request.result =
1747 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1748 notifyRequester(request);
1749 }
1750
1751 break;
1752 }
1753 case EVENT_SET_DATA_THROTTLING_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
1756
1757 if (ar.exception == null) {
1758 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1759 } else if (ar.exception instanceof CommandException) {
1760 loge("setDataThrottling: CommandException: " + ar.exception);
1761 CommandException.Error error =
1762 ((CommandException) (ar.exception)).getCommandError();
1763
1764 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1765 request.result = TelephonyManager
1766 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1767 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1768 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1769 } else {
1770 request.result =
1771 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1772 }
1773 } else {
1774 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1775 }
1776 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1777 notifyRequester(request);
1778 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001779
1780 case CMD_SET_SIM_POWER: {
1781 request = (MainThreadRequest) msg.obj;
1782 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1783 request = (MainThreadRequest) msg.obj;
1784 int stateToSet =
1785 ((Pair<Integer, IIntegerConsumer>)
1786 request.argument).first;
1787 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1788 break;
1789 }
1790 case EVENT_SET_SIM_POWER_DONE: {
1791 ar = (AsyncResult) msg.obj;
1792 request = (MainThreadRequest) ar.userObj;
1793 IIntegerConsumer callback =
1794 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1795 if (ar.exception != null) {
1796 loge("setSimPower exception: " + ar.exception);
1797 int errorCode = TelephonyManager.CallForwardingInfoCallback
1798 .RESULT_ERROR_UNKNOWN;
1799 if (ar.exception instanceof CommandException) {
1800 CommandException.Error error =
1801 ((CommandException) (ar.exception)).getCommandError();
1802 if (error == CommandException.Error.SIM_ERR) {
1803 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1804 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1805 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1806 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1807 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1808 } else {
1809 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1810 }
1811 }
1812 try {
1813 callback.accept(errorCode);
1814 } catch (RemoteException e) {
1815 // Ignore if the remote process is no longer available to call back.
1816 Log.w(LOG_TAG, "setSimPower: callback not available.");
1817 }
1818 } else {
1819 try {
1820 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1821 } catch (RemoteException e) {
1822 // Ignore if the remote process is no longer available to call back.
1823 Log.w(LOG_TAG, "setSimPower: callback not available.");
1824 }
1825 }
1826 break;
1827 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001828 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1829 request = (MainThreadRequest) msg.obj;
1830
1831 final Phone phone = getPhoneFromRequest(request);
1832 if (phone == null || phone.getServiceStateTracker() == null) {
1833 request.result = new IllegalStateException("Phone or SST is null");
1834 notifyRequester(request);
1835 break;
1836 }
1837
1838 Pair<Integer, SignalStrengthUpdateRequest> pair =
1839 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1840 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1841 request);
1842 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1843 request.subId, pair.first /*callingUid*/,
1844 pair.second /*request*/, onCompleted);
1845 break;
1846 }
1847 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1848 ar = (AsyncResult) msg.obj;
1849 request = (MainThreadRequest) ar.userObj;
1850 // request.result will be the exception of ar if present, true otherwise.
1851 // Be cautious not to leave result null which will wait() forever
1852 request.result = ar.exception != null ? ar.exception : true;
1853 notifyRequester(request);
1854 break;
1855 }
1856 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1857 request = (MainThreadRequest) msg.obj;
1858
1859 Phone phone = getPhoneFromRequest(request);
1860 if (phone == null || phone.getServiceStateTracker() == null) {
1861 request.result = new IllegalStateException("Phone or SST is null");
1862 notifyRequester(request);
1863 break;
1864 }
1865
1866 Pair<Integer, SignalStrengthUpdateRequest> pair =
1867 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1868 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1869 request);
1870 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1871 request.subId, pair.first /*callingUid*/,
1872 pair.second /*request*/, onCompleted);
1873 break;
1874 }
1875 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1876 ar = (AsyncResult) msg.obj;
1877 request = (MainThreadRequest) ar.userObj;
1878 request.result = ar.exception != null ? ar.exception : true;
1879 notifyRequester(request);
1880 break;
1881 }
Jordan Liud5366d92020-11-24 14:50:34 -08001882
Michele Berionned9fbae52020-11-13 02:36:59 +00001883 case CMD_PREPARE_UNATTENDED_REBOOT:
1884 request = (MainThreadRequest) msg.obj;
1885 request.result =
1886 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1887 notifyRequester(request);
1888 break;
1889
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 default:
1891 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1892 break;
1893 }
1894 }
Jake Hambye994d462014-02-03 13:10:13 -08001895
Pengquan Menga1bb6272018-09-06 09:59:22 -07001896 private void notifyRequester(MainThreadRequest request) {
1897 synchronized (request) {
1898 request.notifyAll();
1899 }
1900 }
1901
Jake Hambye994d462014-02-03 13:10:13 -08001902 private void handleNullReturnEvent(Message msg, String command) {
1903 AsyncResult ar = (AsyncResult) msg.obj;
1904 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1905 if (ar.exception == null) {
1906 request.result = true;
1907 } else {
1908 request.result = false;
1909 if (ar.exception instanceof CommandException) {
1910 loge(command + ": CommandException: " + ar.exception);
1911 } else {
1912 loge(command + ": Unknown exception");
1913 }
1914 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001915 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 }
1918
1919 /**
1920 * Posts the specified command to be executed on the main thread,
1921 * waits for the request to complete, and returns the result.
1922 * @see #sendRequestAsync
1923 */
1924 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001925 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1926 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001927 }
1928
1929 /**
1930 * Posts the specified command to be executed on the main thread,
1931 * waits for the request to complete, and returns the result.
1932 * @see #sendRequestAsync
1933 */
1934 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1935 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001936 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001937 }
1938
1939 /**
1940 * Posts the specified command to be executed on the main thread,
1941 * waits for the request to complete, and returns the result.
1942 * @see #sendRequestAsync
1943 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001944 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001945 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1946 }
1947
1948 /**
1949 * Posts the specified command to be executed on the main thread,
1950 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1951 * if not timeout or null otherwise.
1952 * @see #sendRequestAsync
1953 */
1954 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1955 long timeoutInMs) {
1956 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001957 }
1958
1959 /**
1960 * Posts the specified command to be executed on the main thread,
1961 * waits for the request to complete, and returns the result.
1962 * @see #sendRequestAsync
1963 */
Nathan Harold92bed182018-10-12 18:16:49 -07001964 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001965 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001966 }
1967
1968 /**
1969 * Posts the specified command to be executed on the main thread,
1970 * waits for the request to complete, and returns the result.
1971 * @see #sendRequestAsync
1972 */
1973 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001974 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1975 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001976 }
1977
1978 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001979 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1980 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1981 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001982 * @see #sendRequestAsync
1983 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001984 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1985 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001986 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1987 throw new RuntimeException("This method will deadlock if called from the main thread.");
1988 }
1989
Nathan Harold92bed182018-10-12 18:16:49 -07001990 MainThreadRequest request = null;
1991 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1992 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1993 } else if (phone != null) {
1994 request = new MainThreadRequest(argument, phone, workSource);
1995 } else {
1996 request = new MainThreadRequest(argument, subId, workSource);
1997 }
1998
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 Message msg = mMainThreadHandler.obtainMessage(command, request);
2000 msg.sendToTarget();
2001
Rambo Wang0f050d82021-02-12 11:43:36 -08002002
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002004 if (timeoutInMs >= 0) {
2005 // Wait for at least timeoutInMs before returning null request result
2006 long now = SystemClock.elapsedRealtime();
2007 long deadline = now + timeoutInMs;
2008 while (request == null && now < deadline) {
2009 try {
2010 request.wait(deadline - now);
2011 } catch (InterruptedException e) {
2012 // Do nothing, go back and check if request is completed or timeout
2013 } finally {
2014 now = SystemClock.elapsedRealtime();
2015 }
2016 }
2017 } else {
2018 // Wait for the request to complete
2019 while (request.result == null) {
2020 try {
2021 request.wait();
2022 } catch (InterruptedException e) {
2023 // Do nothing, go back and wait until the request is complete
2024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002025 }
2026 }
2027 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002028 if (request.result == null) {
2029 Log.wtf(LOG_TAG,
2030 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 return request.result;
2033 }
2034
2035 /**
2036 * Asynchronous ("fire and forget") version of sendRequest():
2037 * Posts the specified command to be executed on the main thread, and
2038 * returns immediately.
2039 * @see #sendRequest
2040 */
2041 private void sendRequestAsync(int command) {
2042 mMainThreadHandler.sendEmptyMessage(command);
2043 }
2044
2045 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002046 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002047 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002048 */
2049 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002050 sendRequestAsync(command, argument, null, null);
2051 }
2052
2053 /**
2054 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2055 * @see {@link #sendRequest(int,Object)}
2056 */
2057 private void sendRequestAsync(
2058 int command, Object argument, Phone phone, WorkSource workSource) {
2059 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002060 Message msg = mMainThreadHandler.obtainMessage(command, request);
2061 msg.sendToTarget();
2062 }
2063
2064 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065 * Initialize the singleton PhoneInterfaceManager instance.
2066 * This is only done once, at startup, from PhoneApp.onCreate().
2067 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002068 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 synchronized (PhoneInterfaceManager.class) {
2070 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002071 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 } else {
2073 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2074 }
2075 return sInstance;
2076 }
2077 }
2078
2079 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002080 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002083 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002084 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2086 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002087 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002088 mTelephonySharedPreferences =
2089 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002090 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002091 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002092 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002093
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 publish();
2095 }
2096
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002097 private Phone getDefaultPhone() {
2098 Phone thePhone = getPhone(getDefaultSubscription());
2099 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2100 }
2101
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 private void publish() {
2103 if (DBG) log("publish: " + this);
2104
Peter Wangc035ce42020-01-08 21:00:22 -08002105 TelephonyFrameworkInitializer
2106 .getTelephonyServiceManager()
2107 .getTelephonyServiceRegisterer()
2108 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 }
2110
Stuart Scott584921c2015-01-15 17:10:34 -08002111 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002112 if (request.phone != null) {
2113 return request.phone;
2114 } else {
2115 return getPhoneFromSubId(request.subId);
2116 }
2117 }
2118
2119 private Phone getPhoneFromSubId(int subId) {
2120 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2121 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002122 }
2123
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002124 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2125 Phone phone = getPhoneFromRequest(request);
2126 return phone == null ? null :
2127 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2128 }
2129
Wink Saville36469e72014-06-11 15:17:00 -07002130 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002131 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002132 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002135 private void sendEraseModemConfig(Phone phone) {
2136 if (phone != null) {
2137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2138 mApp, phone.getSubId(), "eraseModemConfig");
2139 final long identity = Binder.clearCallingIdentity();
2140 try {
2141 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2142 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
2145 }
2146 }
2147 }
2148
Peter Wang050bb052020-01-13 23:33:09 -08002149 private boolean isImsAvailableOnDevice() {
2150 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2151 if (pm == null) {
2152 // For some reason package manger is not available.. This will fail internally anyway,
2153 // so do not throw error and allow.
2154 return true;
2155 }
2156 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2157 }
2158
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002160 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002161 }
2162
Wink Savilleb564aae2014-10-23 10:18:09 -07002163 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 if (DBG) log("dial: " + number);
2165 // No permission check needed here: This is just a wrapper around the
2166 // ACTION_DIAL intent, which is available to any app since it puts up
2167 // the UI before it does anything.
2168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002169 final long identity = Binder.clearCallingIdentity();
2170 try {
2171 String url = createTelUrl(number);
2172 if (url == null) {
2173 return;
2174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 // PENDING: should we just silently fail if phone is offhook or ringing?
2177 PhoneConstants.State state = mCM.getState(subId);
2178 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2179 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2180 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2181 mApp.startActivity(intent);
2182 }
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186 }
2187
2188 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002189 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002190 }
2191
Wink Savilleb564aae2014-10-23 10:18:09 -07002192 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 if (DBG) log("call: " + number);
2194
2195 // This is just a wrapper around the ACTION_CALL intent, but we still
2196 // need to do a permission check since we're calling startActivity()
2197 // from the context of the phone app.
2198 enforceCallPermission();
2199
Jordan Liu1617b712019-07-10 15:06:26 -07002200 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 != AppOpsManager.MODE_ALLOWED) {
2202 return;
2203 }
2204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 String url = createTelUrl(number);
2208 if (url == null) {
2209 return;
2210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002212 boolean isValid = false;
2213 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2214 if (slist != null) {
2215 for (SubscriptionInfo subInfoRecord : slist) {
2216 if (subInfoRecord.getSubscriptionId() == subId) {
2217 isValid = true;
2218 break;
2219 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002220 }
Wink Saville08874612014-08-31 19:19:58 -07002221 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002222 if (!isValid) {
2223 return;
2224 }
Wink Saville08874612014-08-31 19:19:58 -07002225
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2227 intent.putExtra(SUBSCRIPTION_KEY, subId);
2228 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2229 mApp.startActivity(intent);
2230 } finally {
2231 Binder.restoreCallingIdentity(identity);
2232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233 }
2234
Wink Savilleb564aae2014-10-23 10:18:09 -07002235 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002236 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002237 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2238 }
2239
Wink Savilleb564aae2014-10-23 10:18:09 -07002240 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002241 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002242 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2243 }
2244
Wink Savilleb564aae2014-10-23 10:18:09 -07002245 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002247
2248 final long identity = Binder.clearCallingIdentity();
2249 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002250 Phone phone = getPhone(subId);
2251 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002252 checkSimPin.start();
2253 return checkSimPin.unlockSim(null, pin);
2254 } finally {
2255 Binder.restoreCallingIdentity(identity);
2256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 }
2258
Wink Savilleb564aae2014-10-23 10:18:09 -07002259 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261
2262 final long identity = Binder.clearCallingIdentity();
2263 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002264 Phone phone = getPhone(subId);
2265 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002266 checkSimPuk.start();
2267 return checkSimPuk.unlockSim(puk, pin);
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
2270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
2273 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002274 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 * a synchronous one.
2276 */
2277 private static class UnlockSim extends Thread {
2278
2279 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002280 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281
2282 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002283 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2284 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285
2286 // For replies from SimCard interface
2287 private Handler mHandler;
2288
2289 // For async handler to identify request type
2290 private static final int SUPPLY_PIN_COMPLETE = 100;
2291
Michele Berionned9fbae52020-11-13 02:36:59 +00002292 UnlockSim(int phoneId, IccCard simCard) {
2293 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 mSimCard = simCard;
2295 }
2296
2297 @Override
2298 public void run() {
2299 Looper.prepare();
2300 synchronized (UnlockSim.this) {
2301 mHandler = new Handler() {
2302 @Override
2303 public void handleMessage(Message msg) {
2304 AsyncResult ar = (AsyncResult) msg.obj;
2305 switch (msg.what) {
2306 case SUPPLY_PIN_COMPLETE:
2307 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2308 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002309 mRetryCount = msg.arg1;
2310 if (ar.exception != null) {
2311 if (ar.exception instanceof CommandException &&
2312 ((CommandException)(ar.exception)).getCommandError()
2313 == CommandException.Error.PASSWORD_INCORRECT) {
2314 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002315 } //When UiccCardApp dispose,handle message and return exception
2316 else if (ar.exception instanceof CommandException &&
2317 ((CommandException) (ar.exception)).getCommandError()
2318 == CommandException.Error.ABORTED) {
2319 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002320 } else {
2321 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2322 }
2323 } else {
2324 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 mDone = true;
2327 UnlockSim.this.notifyAll();
2328 }
2329 break;
2330 }
2331 }
2332 };
2333 UnlockSim.this.notifyAll();
2334 }
2335 Looper.loop();
2336 }
2337
2338 /*
2339 * Use PIN or PUK to unlock SIM card
2340 *
2341 * If PUK is null, unlock SIM card with PIN
2342 *
2343 * If PUK is not null, unlock SIM card with PUK and set PIN code
2344 */
Wink Saville9de0f752013-10-22 19:04:03 -07002345 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346
2347 while (mHandler == null) {
2348 try {
2349 wait();
2350 } catch (InterruptedException e) {
2351 Thread.currentThread().interrupt();
2352 }
2353 }
2354 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2355
2356 if (puk == null) {
2357 mSimCard.supplyPin(pin, callback);
2358 } else {
2359 mSimCard.supplyPuk(puk, pin, callback);
2360 }
2361
2362 while (!mDone) {
2363 try {
2364 Log.d(LOG_TAG, "wait for done");
2365 wait();
2366 } catch (InterruptedException e) {
2367 // Restore the interrupted status
2368 Thread.currentThread().interrupt();
2369 }
2370 }
2371 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002372 int[] resultArray = new int[2];
2373 resultArray[0] = mResult;
2374 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002375
2376 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2377 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2378 }
2379
Wink Saville9de0f752013-10-22 19:04:03 -07002380 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 }
2382 }
2383
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002384 /**
2385 * This method has been removed due to privacy and stability concerns.
2386 */
2387 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002389 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2390 return;
Wink Saville36469e72014-06-11 15:17:00 -07002391 }
2392
Nathan Harold1f889d82020-06-04 17:05:26 -07002393 @Override
2394 public void updateServiceLocationWithPackageName(String callingPackage) {
2395 mApp.getSystemService(AppOpsManager.class)
2396 .checkPackage(Binder.getCallingUid(), callingPackage);
2397
Nathan Haroldf096d982020-11-18 17:18:06 -08002398 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002399 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2400 // Callers targeting S have no business invoking this method.
2401 return;
2402 }
2403
2404 LocationAccessPolicy.LocationPermissionResult locationResult =
2405 LocationAccessPolicy.checkLocationPermission(mApp,
2406 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2407 .setCallingPackage(callingPackage)
2408 .setCallingFeatureId(null)
2409 .setCallingPid(Binder.getCallingPid())
2410 .setCallingUid(Binder.getCallingUid())
2411 .setMethod("updateServiceLocation")
2412 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2413 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2414 .build());
2415 // Apps that lack location permission have no business calling this method;
2416 // however, because no permission was declared in the public API, denials must
2417 // all be "soft".
2418 switch (locationResult) {
2419 case DENIED_HARD: /* fall through */
2420 case DENIED_SOFT:
2421 return;
2422 }
2423
2424 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425 final long identity = Binder.clearCallingIdentity();
2426 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002427 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002428 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002429 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002430 }
2431 } finally {
2432 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 }
2435
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002436 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002437 @Override
2438 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002439 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002440 }
2441
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002442
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002443 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002444 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2445 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2446 callingFeatureId);
2447 }
2448
2449 @Deprecated
2450 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002451 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002452 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2453 }
2454
2455 @Override
2456 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2457 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002459 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002460 return false;
2461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462
2463 final long identity = Binder.clearCallingIdentity();
2464 try {
2465 return isRadioOnForSubscriber(subId);
2466 } finally {
2467 Binder.restoreCallingIdentity(identity);
2468 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002469 }
2470
2471 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 final Phone phone = getPhone(subId);
2475 if (phone != null) {
2476 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2477 } else {
2478 return false;
2479 }
2480 } finally {
2481 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 }
2484
2485 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002486 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 }
Wink Saville36469e72014-06-11 15:17:00 -07002488
Wink Savilleb564aae2014-10-23 10:18:09 -07002489 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491
2492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 final Phone phone = getPhone(subId);
2495 if (phone != null) {
2496 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2497 }
2498 } finally {
2499 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002500 }
Wink Saville36469e72014-06-11 15:17:00 -07002501 }
2502
2503 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002504 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002505 }
2506
Wink Savilleb564aae2014-10-23 10:18:09 -07002507 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002508 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509
2510 final long identity = Binder.clearCallingIdentity();
2511 try {
2512 final Phone phone = getPhone(subId);
2513 if (phone == null) {
2514 return false;
2515 }
2516 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2517 toggleRadioOnOffForSubscriber(subId);
2518 }
2519 return true;
2520 } finally {
2521 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002522 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 }
Wink Saville36469e72014-06-11 15:17:00 -07002524
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002525 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002526 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002527 /*
2528 * If any of the Radios are available, it will need to be
2529 * shutdown. So return true if any Radio is available.
2530 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2534 Phone phone = PhoneFactory.getPhone(i);
2535 if (phone != null && phone.isRadioAvailable()) return true;
2536 }
2537 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2538 return false;
2539 } finally {
2540 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002541 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002542 }
2543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002545 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002546 enforceModifyPermission();
2547
2548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2551 logv("Shutting down Phone " + i);
2552 shutdownRadioUsingPhoneId(i);
2553 }
2554 } finally {
2555 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002556 }
2557 }
2558
2559 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002560 Phone phone = PhoneFactory.getPhone(phoneId);
2561 if (phone != null && phone.isRadioAvailable()) {
2562 phone.shutdownRadio();
2563 }
2564 }
2565
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2572 if (defaultPhone != null) {
2573 defaultPhone.setRadioPower(turnOn);
2574 return true;
2575 } else {
2576 loge("There's no default phone.");
2577 return false;
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002581 }
Wink Saville36469e72014-06-11 15:17:00 -07002582 }
2583
Wink Savilleb564aae2014-10-23 10:18:09 -07002584 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002585 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002586
2587 final long identity = Binder.clearCallingIdentity();
2588 try {
2589 final Phone phone = getPhone(subId);
2590 if (phone != null) {
2591 phone.setRadioPower(turnOn);
2592 return true;
2593 } else {
2594 return false;
2595 }
2596 } finally {
2597 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 }
2600
Wink Saville36469e72014-06-11 15:17:00 -07002601 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002602 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 public boolean enableDataConnectivity() {
2604 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605
2606 final long identity = Binder.clearCallingIdentity();
2607 try {
2608 int subId = mSubscriptionController.getDefaultDataSubId();
2609 final Phone phone = getPhone(subId);
2610 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002611 phone.getDataEnabledSettings().setDataEnabled(
2612 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 return true;
2614 } else {
2615 return false;
2616 }
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002620 }
2621
Wink Saville36469e72014-06-11 15:17:00 -07002622 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002623 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002624 public boolean disableDataConnectivity() {
2625 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 int subId = mSubscriptionController.getDefaultDataSubId();
2630 final Phone phone = getPhone(subId);
2631 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002632 phone.getDataEnabledSettings().setDataEnabled(
2633 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634 return true;
2635 } else {
2636 return false;
2637 }
2638 } finally {
2639 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002641 }
2642
Sanket Padawe356d7632015-06-22 14:03:32 -07002643 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002644 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 final Phone phone = getPhone(subId);
2648 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002649 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 } else {
2651 return false;
2652 }
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002656 }
2657
2658 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002659 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002660 }
2661
pkanwarae03a6b2016-11-06 20:37:09 -08002662 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663 enforceCallPermission();
2664
2665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2668 return;
2669 }
2670 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2671 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
2674 }
pkanwar32d516d2016-10-14 19:37:38 -07002675 };
2676
Wink Savilleb564aae2014-10-23 10:18:09 -07002677 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679
2680 final long identity = Binder.clearCallingIdentity();
2681 try {
2682 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2683 return false;
2684 }
2685 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 }
2690
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002692 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002693 }
2694
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002695 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 Phone phone = PhoneFactory.getPhone(slotIndex);
2699 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2700 PhoneConstantConversions.convertCallState(phone.getState());
2701 } finally {
2702 Binder.restoreCallingIdentity(identity);
2703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 }
2705
Sanket Padawe356d7632015-06-22 14:03:32 -07002706 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002707 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002708 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2709 }
2710
2711 @Override
2712 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 final long identity = Binder.clearCallingIdentity();
2714 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002715 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 if (phone != null) {
2717 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2718 } else {
2719 return PhoneConstantConversions.convertDataState(
2720 PhoneConstants.DataState.DISCONNECTED);
2721 }
2722 } finally {
2723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 }
2726
Sanket Padawe356d7632015-06-22 14:03:32 -07002727 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002728 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002729 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2730 }
2731
2732 @Override
2733 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 final long identity = Binder.clearCallingIdentity();
2735 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002736 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 if (phone != null) {
2738 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2739 } else {
2740 return TelephonyManager.DATA_ACTIVITY_NONE;
2741 }
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
2746
2747 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002748 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002749 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002750 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002751
2752 LocationAccessPolicy.LocationPermissionResult locationResult =
2753 LocationAccessPolicy.checkLocationPermission(mApp,
2754 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2755 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002756 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002757 .setCallingPid(Binder.getCallingPid())
2758 .setCallingUid(Binder.getCallingUid())
2759 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002760 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002761 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2762 .build());
2763 switch (locationResult) {
2764 case DENIED_HARD:
2765 throw new SecurityException("Not allowed to access cell location");
2766 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002767 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2768 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002771 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 final long identity = Binder.clearCallingIdentity();
2773 try {
2774 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002775 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002776 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 } finally {
2778 Binder.restoreCallingIdentity(identity);
2779 }
Svetoslav64fad262015-04-14 14:35:21 -07002780 }
2781
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002782 @Override
Jack Yu01425032020-02-22 19:38:58 -08002783 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002784 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2785 // registered cell info, so return a NULL country instead.
2786 final long identity = Binder.clearCallingIdentity();
2787 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002788 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2789 // Get default phone in this case.
2790 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2791 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002792 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002794 if (phone == null) return "";
2795 ServiceStateTracker sst = phone.getServiceStateTracker();
2796 if (sst == null) return "";
2797 LocaleTracker lt = sst.getLocaleTracker();
2798 if (lt == null) return "";
2799 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2800 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2801 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002802 } finally {
2803 Binder.restoreCallingIdentity(identity);
2804 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002805 }
2806
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002807 /**
2808 * This method was removed due to potential issues caused by performing partial
2809 * updates of service state, and lack of a credible use case.
2810 *
2811 * This has the ability to break the telephony implementation by disabling notification of
2812 * changes in device connectivity. DO NOT USE THIS!
2813 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002814 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 public void enableLocationUpdates() {
2816 mApp.enforceCallingOrSelfPermission(
2817 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 }
2819
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002820 /**
2821 * This method was removed due to potential issues caused by performing partial
2822 * updates of service state, and lack of a credible use case.
2823 *
2824 * This has the ability to break the telephony implementation by disabling notification of
2825 * changes in device connectivity. DO NOT USE THIS!
2826 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 @Override
2828 public void disableLocationUpdates() {
2829 mApp.enforceCallingOrSelfPermission(
2830 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 }
2832
2833 @Override
2834 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002835 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2836 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002837 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002838 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2839 throw new SecurityException(
2840 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2841 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002842
Jordan Liu1617b712019-07-10 15:06:26 -07002843 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2845 return null;
2846 }
Svetoslav64fad262015-04-14 14:35:21 -07002847
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002848 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002850 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002851 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852
Nathan Haroldf180aac2018-06-01 18:43:55 -07002853 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2854 for (CellInfo ci : info) {
2855 if (ci instanceof CellInfoGsm) {
2856 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2857 } else if (ci instanceof CellInfoWcdma) {
2858 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002861 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 }
2863
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002864 private List<CellInfo> getCachedCellInfo() {
2865 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2866 for (Phone phone : PhoneFactory.getPhones()) {
2867 List<CellInfo> info = phone.getAllCellInfo();
2868 if (info != null) cellInfos.addAll(info);
2869 }
2870 return cellInfos;
2871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872
2873 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002874 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002875 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002876 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002877
2878 LocationAccessPolicy.LocationPermissionResult locationResult =
2879 LocationAccessPolicy.checkLocationPermission(mApp,
2880 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2881 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002882 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002883 .setCallingPid(Binder.getCallingPid())
2884 .setCallingUid(Binder.getCallingUid())
2885 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002886 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002887 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2888 .build());
2889 switch (locationResult) {
2890 case DENIED_HARD:
2891 throw new SecurityException("Not allowed to access cell info");
2892 case DENIED_SOFT:
2893 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002894 }
2895
Nathan Haroldf096d982020-11-18 17:18:06 -08002896 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002897 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2898 return getCachedCellInfo();
2899 }
2900
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002901 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002902 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2906 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002907 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002908 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 if (info != null) cellInfos.addAll(info);
2910 }
2911 return cellInfos;
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002914 }
2915 }
2916
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002917 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002918 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2919 String callingFeatureId) {
2920 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2921 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002922 }
2923
2924 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002925 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2926 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002927 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002928 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002929 }
2930
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002931 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2932 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002933 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002934 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002935
2936 LocationAccessPolicy.LocationPermissionResult locationResult =
2937 LocationAccessPolicy.checkLocationPermission(mApp,
2938 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2939 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002940 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002941 .setCallingPid(Binder.getCallingPid())
2942 .setCallingUid(Binder.getCallingUid())
2943 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002944 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2945 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002946 .build());
2947 switch (locationResult) {
2948 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002949 if (TelephonyPermissions
2950 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002951 // Safetynet logging for b/154934934
2952 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2953 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002954 throw new SecurityException("Not allowed to access cell info");
2955 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002956 if (TelephonyPermissions
2957 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002958 // Safetynet logging for b/154934934
2959 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2960 }
Nathan Harold5320c422019-05-09 10:26:08 -07002961 try {
2962 cb.onCellInfo(new ArrayList<CellInfo>());
2963 } catch (RemoteException re) {
2964 // Drop without consequences
2965 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002966 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002967 }
2968
Nathan Harolda939a962019-05-09 10:13:47 -07002969
2970 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002971 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2972
2973 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2974 }
2975
2976 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002978 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980
2981 final long identity = Binder.clearCallingIdentity();
2982 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002983 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002987 }
2988
Shishir Agrawala9f32182016-04-12 12:00:16 -07002989 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002990 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002991 Phone phone = PhoneFactory.getPhone(slotIndex);
2992 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002993 return null;
2994 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002995 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002996 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002997 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002998 return null;
2999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 return phone.getImei();
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003007 }
3008
3009 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003010 public String getTypeAllocationCodeForSlot(int slotIndex) {
3011 Phone phone = PhoneFactory.getPhone(slotIndex);
3012 String tac = null;
3013 if (phone != null) {
3014 String imei = phone.getImei();
3015 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3016 }
3017 return tac;
3018 }
3019
3020 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003021 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003022 Phone phone = PhoneFactory.getPhone(slotIndex);
3023 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003024 return null;
3025 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003026
Jeff Davidson913390f2018-02-23 17:11:49 -08003027 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003028 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003029 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003030 return null;
3031 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 return phone.getMeid();
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
Jack Yu2af8d712017-03-15 17:14:14 -07003039 }
3040
3041 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003042 public String getManufacturerCodeForSlot(int slotIndex) {
3043 Phone phone = PhoneFactory.getPhone(slotIndex);
3044 String manufacturerCode = null;
3045 if (phone != null) {
3046 String meid = phone.getMeid();
3047 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3048 }
3049 return manufacturerCode;
3050 }
3051
3052 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003053 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3054 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003055 Phone phone = PhoneFactory.getPhone(slotIndex);
3056 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003057 return null;
3058 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003059 int subId = phone.getSubId();
3060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003061 mApp, subId, callingPackage, callingFeatureId,
3062 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003063 return null;
3064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065
3066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 return phone.getDeviceSvn();
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003072 }
3073
fionaxu43304da2017-11-27 22:51:16 -08003074 @Override
3075 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 final Phone phone = getPhone(subId);
3079 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3080 } finally {
3081 Binder.restoreCallingIdentity(identity);
3082 }
fionaxu43304da2017-11-27 22:51:16 -08003083 }
3084
3085 @Override
3086 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 final Phone phone = getPhone(subId);
3090 return phone == null ? null : phone.getCarrierName();
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
fionaxu43304da2017-11-27 22:51:16 -08003094 }
3095
calvinpanffe225e2018-11-01 19:43:06 +08003096 @Override
chen xu0026ca62019-03-06 15:28:50 -08003097 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 final Phone phone = getPhone(subId);
3101 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003102 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
3106 }
3107
3108 @Override
chen xu0026ca62019-03-06 15:28:50 -08003109 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003113 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
3117 }
3118
chen xu651eec72018-11-11 19:03:44 -08003119 @Override
chen xu864e11c2018-12-06 22:10:03 -08003120 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3121 if (!isSubscriptionMccMnc) {
3122 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3123 }
chen xu651eec72018-11-11 19:03:44 -08003124 final Phone phone = PhoneFactory.getPhone(slotIndex);
3125 if (phone == null) {
3126 return TelephonyManager.UNKNOWN_CARRIER_ID;
3127 }
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3131 } finally {
3132 Binder.restoreCallingIdentity(identity);
3133 }
3134 }
3135
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003136 //
3137 // Internal helper methods.
3138 //
3139
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003140 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3142 *
3143 * @throws SecurityException if the caller does not have the required permission
3144 */
3145 private void enforceModifyPermission() {
3146 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3147 }
3148
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003149 /**
3150 * Make sure the caller is system.
3151 *
3152 * @throws SecurityException if the caller is not system.
3153 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003154 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003155 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3156 throw new SecurityException("Caller must be system");
3157 }
3158 }
3159
Shuo Qianf2b2df42019-11-13 17:43:31 -08003160 private void enforceActiveEmergencySessionPermission() {
3161 mApp.enforceCallingOrSelfPermission(
3162 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3163 }
3164
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 /**
3166 * Make sure the caller has the CALL_PHONE permission.
3167 *
3168 * @throws SecurityException if the caller does not have the required permission
3169 */
3170 private void enforceCallPermission() {
3171 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3172 }
3173
paulhu423b5f22019-08-23 19:17:33 +08003174 private void enforceSettingsPermission() {
3175 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003176 }
3177
Michele Berionned9fbae52020-11-13 02:36:59 +00003178 private void enforceRebootPermission() {
3179 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3180 }
3181
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003182 private String createTelUrl(String number) {
3183 if (TextUtils.isEmpty(number)) {
3184 return null;
3185 }
3186
Jake Hambye994d462014-02-03 13:10:13 -08003187 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003188 }
3189
Ihab Awadf9e92732013-12-05 18:02:52 -08003190 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3192 }
3193
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003194 private static void logv(String msg) {
3195 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3196 }
3197
Ihab Awadf9e92732013-12-05 18:02:52 -08003198 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3200 }
3201
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003202 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003204 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003205 }
3206
Sanket Padawe356d7632015-06-22 14:03:32 -07003207 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003208 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209 final long identity = Binder.clearCallingIdentity();
3210 try {
3211 final Phone phone = PhoneFactory.getPhone(slotIndex);
3212 if (phone == null) {
3213 return PhoneConstants.PHONE_TYPE_NONE;
3214 } else {
3215 return phone.getPhoneType();
3216 }
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003220 }
3221
3222 /**
3223 * Returns the CDMA ERI icon index to display
3224 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003225 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003226 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3227 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3228 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003229 }
3230
Sanket Padawe356d7632015-06-22 14:03:32 -07003231 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003232 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3233 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003235 mApp, subId, callingPackage, callingFeatureId,
3236 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003237 return -1;
3238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003239
3240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 final Phone phone = getPhone(subId);
3243 if (phone != null) {
3244 return phone.getCdmaEriIconIndex();
3245 } else {
3246 return -1;
3247 }
3248 } finally {
3249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003251 }
3252
3253 /**
3254 * Returns the CDMA ERI icon mode,
3255 * 0 - ON
3256 * 1 - FLASHING
3257 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003258 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003259 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3260 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3261 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003262 }
3263
Sanket Padawe356d7632015-06-22 14:03:32 -07003264 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003265 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3266 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003268 mApp, subId, callingPackage, callingFeatureId,
3269 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003270 return -1;
3271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272
3273 final long identity = Binder.clearCallingIdentity();
3274 try {
3275 final Phone phone = getPhone(subId);
3276 if (phone != null) {
3277 return phone.getCdmaEriIconMode();
3278 } else {
3279 return -1;
3280 }
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003284 }
3285
3286 /**
3287 * Returns the CDMA ERI text,
3288 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003289 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003290 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3291 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3292 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003293 }
3294
Sanket Padawe356d7632015-06-22 14:03:32 -07003295 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003296 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3297 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003299 mApp, subId, callingPackage, callingFeatureId,
3300 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003301 return null;
3302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303
3304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 final Phone phone = getPhone(subId);
3307 if (phone != null) {
3308 return phone.getCdmaEriText();
3309 } else {
3310 return null;
3311 }
3312 } finally {
3313 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003315 }
3316
3317 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003318 * Returns the CDMA MDN.
3319 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003320 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003321 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3323 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003324
3325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003328 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 return phone.getLine1Number();
3330 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003331 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332 return null;
3333 }
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003336 }
3337 }
3338
3339 /**
3340 * Returns the CDMA MIN.
3341 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003342 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003343 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3345 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346
3347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 final Phone phone = getPhone(subId);
3350 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3351 return phone.getCdmaMin();
3352 } else {
3353 return null;
3354 }
3355 } finally {
3356 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003357 }
3358 }
3359
Hall Liud892bec2018-11-30 14:51:45 -08003360 @Override
3361 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3362 INumberVerificationCallback callback, String callingPackage) {
3363 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3364 != PERMISSION_GRANTED) {
3365 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3366 }
3367 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3368
3369 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3370 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003371 throw new SecurityException("Calling package must be configured in the device config: "
3372 + "calling package: " + callingPackage
3373 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003374 }
3375
3376 if (range == null) {
3377 throw new NullPointerException("Range must be non-null");
3378 }
3379
3380 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003381 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003382
3383 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3384 }
3385
Junda Liuca05d5d2014-08-14 22:36:34 -07003386 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003387 * Returns true if CDMA provisioning needs to run.
3388 */
3389 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003390 final long identity = Binder.clearCallingIdentity();
3391 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003392 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003396 }
3397
3398 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003399 * Sets the voice mail number of a given subId.
3400 */
3401 @Override
3402 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003403 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3404 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3409 new Pair<String, String>(alphaTag, number), new Integer(subId));
3410 return success;
3411 } finally {
3412 Binder.restoreCallingIdentity(identity);
3413 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003414 }
3415
Ta-wei Yen87c49842016-05-13 21:19:52 -07003416 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003417 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3418 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003419 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3420 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003421 if (!TextUtils.equals(callingPackage, systemDialer)) {
3422 throw new SecurityException("caller must be system dialer");
3423 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3428 if (phoneAccountHandle == null) {
3429 return null;
3430 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003431 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432 } finally {
3433 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003434 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003435 }
3436
3437 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003438 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3439 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003440 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003442 mApp, subId, callingPackage, callingFeatureId,
3443 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003444 return null;
3445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003447 final long identity = Binder.clearCallingIdentity();
3448 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003449 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003453 }
3454
3455 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003456 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3457 VisualVoicemailSmsFilterSettings settings) {
3458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003459
3460 final long identity = Binder.clearCallingIdentity();
3461 try {
3462 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003463 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464 } finally {
3465 Binder.restoreCallingIdentity(identity);
3466 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003467 }
3468
3469 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003470 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003472
3473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003476 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003477 } finally {
3478 Binder.restoreCallingIdentity(identity);
3479 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003480 }
3481
3482 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003483 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3484 String callingPackage, int subId) {
3485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003486
3487 final long identity = Binder.clearCallingIdentity();
3488 try {
3489 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003490 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491 } finally {
3492 Binder.restoreCallingIdentity(identity);
3493 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003494 }
3495
3496 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003497 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003498 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003499
3500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003503 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003504 } finally {
3505 Binder.restoreCallingIdentity(identity);
3506 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003507 }
3508
3509 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003510 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3511 String callingAttributionTag, int subId, String number, int port, String text,
3512 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003513 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003514 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003515 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003516 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003517 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3518 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003519 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003520
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003521 /**
fionaxu0152e512016-11-14 13:36:14 -08003522 * Sets the voice activation state of a given subId.
3523 */
3524 @Override
3525 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3527 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 final Phone phone = getPhone(subId);
3532 if (phone != null) {
3533 phone.setVoiceActivationState(activationState);
3534 } else {
3535 loge("setVoiceActivationState fails with invalid subId: " + subId);
3536 }
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003539 }
3540 }
3541
3542 /**
3543 * Sets the data activation state of a given subId.
3544 */
3545 @Override
3546 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3548 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 final Phone phone = getPhone(subId);
3553 if (phone != null) {
3554 phone.setDataActivationState(activationState);
3555 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003556 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557 }
3558 } finally {
3559 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003560 }
3561 }
3562
3563 /**
3564 * Returns the voice activation state of a given subId.
3565 */
3566 @Override
3567 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569
fionaxu0152e512016-11-14 13:36:14 -08003570 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 if (phone != null) {
3574 return phone.getVoiceActivationState();
3575 } else {
3576 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3577 }
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003580 }
3581 }
3582
3583 /**
3584 * Returns the data activation state of a given subId.
3585 */
3586 @Override
3587 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589
fionaxu0152e512016-11-14 13:36:14 -08003590 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 if (phone != null) {
3594 return phone.getDataActivationState();
3595 } else {
3596 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3597 }
3598 } finally {
3599 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003600 }
3601 }
3602
3603 /**
Wink Saville36469e72014-06-11 15:17:00 -07003604 * Returns the unread count of voicemails for a subId
3605 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003606 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003607 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3608 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003610 mApp, subId, callingPackage, callingFeatureId,
3611 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003612 return 0;
3613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 final Phone phone = getPhone(subId);
3617 if (phone != null) {
3618 return phone.getVoiceMessageCount();
3619 } else {
3620 return 0;
3621 }
3622 } finally {
3623 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003625 }
3626
3627 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003628 * returns true, if the device is in a state where both voice and data
3629 * are supported simultaneously. This can change based on location or network condition.
3630 */
3631 @Override
3632 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 final Phone phone = getPhone(subId);
3636 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003640 }
3641
3642 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003643 * Send the dialer code if called from the current default dialer or the caller has
3644 * carrier privilege.
3645 * @param inputCode The dialer code to send
3646 */
3647 @Override
3648 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003649 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003650 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003651 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3652 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003653 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003654 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003655 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003660 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
fionaxu235cc5e2017-03-06 22:25:57 -08003664 }
3665
Pengquan Menga1bb6272018-09-06 09:59:22 -07003666 @Override
3667 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003668 TelephonyPermissions
3669 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3670 mApp, subId, "getNetworkSelectionMode");
3671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 if (!isActiveSubscription(subId)) {
3674 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3675 }
3676 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003679 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003680 }
3681
Brad Ebinger35c841c2018-10-01 10:40:55 -07003682 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003683 public boolean isInEmergencySmsMode() {
3684 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 for (Phone phone : PhoneFactory.getPhones()) {
3688 if (phone.isInEmergencySmsMode()) {
3689 return true;
3690 }
3691 }
3692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
3695 return false;
3696 }
3697
shilu366312e2019-12-17 09:28:10 -08003698 /**
3699 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3700 * @param subId The subscription to use to check the configuration.
3701 * @param c The callback that will be used to send the result.
3702 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003703 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003704 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3705 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003706 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3707 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003708
Brad Ebinger77b832e2019-10-17 17:03:22 -07003709 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3710 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3711 "IMS not available on device.");
3712 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 final long token = Binder.clearCallingIdentity();
3714 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003715 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003716 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003718 } catch (ImsException e) {
3719 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 } finally {
3721 Binder.restoreCallingIdentity(token);
3722 }
3723 }
3724
shilu366312e2019-12-17 09:28:10 -08003725 /**
3726 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3727 * @param subId The subscription to use to check the configuration.
3728 * @param c The callback that will be used to send the result.
3729 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003730 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003731 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003732 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3733 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3735 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3736 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003737 final long token = Binder.clearCallingIdentity();
3738 try {
3739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3740 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3741 .removeRegistrationCallbackForSubscription(c, subId);
3742 } catch (ImsException e) {
3743 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3744 + "is inactive, ignoring unregister.");
3745 // If the subscription is no longer active, just return, since the callback
3746 // will already have been removed internally.
3747 } finally {
3748 Binder.restoreCallingIdentity(token);
3749 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 }
3751
Brad Ebinger774ba362019-10-22 17:36:18 -07003752 /**
3753 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3754 */
3755 @Override
3756 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3757 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3758 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3759 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3760 "IMS not available on device.");
3761 }
3762 final long token = Binder.clearCallingIdentity();
3763 try {
3764 Phone phone = getPhone(subId);
3765 if (phone == null) {
3766 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3767 + subId + "'");
3768 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3769 }
3770 phone.getImsRegistrationState(regState -> {
3771 try {
3772 consumer.accept((regState == null)
3773 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3774 } catch (RemoteException e) {
3775 // Ignore if the remote process is no longer available to call back.
3776 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3777 }
3778 });
3779 } finally {
3780 Binder.restoreCallingIdentity(token);
3781 }
3782 }
3783
3784 /**
3785 * Get the transport type for the IMS service registration state.
3786 */
3787 @Override
3788 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003789 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3790 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003791 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3792 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3793 "IMS not available on device.");
3794 }
3795 final long token = Binder.clearCallingIdentity();
3796 try {
3797 Phone phone = getPhone(subId);
3798 if (phone == null) {
3799 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3800 + subId + "'");
3801 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3802 }
3803 phone.getImsRegistrationTech(regTech -> {
3804 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3805 int regTechConverted = (regTech == null)
3806 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3807 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3808 regTechConverted);
3809 try {
3810 consumer.accept(regTechConverted);
3811 } catch (RemoteException e) {
3812 // Ignore if the remote process is no longer available to call back.
3813 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3814 }
3815 });
3816 } finally {
3817 Binder.restoreCallingIdentity(token);
3818 }
3819 }
3820
shilu366312e2019-12-17 09:28:10 -08003821 /**
3822 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3823 * @param subId The subscription to use to check the configuration.
3824 * @param c The callback that will be used to send the result.
3825 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003827 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3828 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003829 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3830 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003831 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3832 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3833 "IMS not available on device.");
3834 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3836 final long token = Binder.clearCallingIdentity();
3837 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003838 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003839 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003840 } catch (ImsException e) {
3841 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003842 } finally {
3843 Binder.restoreCallingIdentity(token);
3844 }
3845 }
3846
shilu366312e2019-12-17 09:28:10 -08003847 /**
3848 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3849 * @param subId The subscription to use to check the configuration.
3850 * @param c The callback that will be used to send the result.
3851 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003853 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003854 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3855 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3857 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3858 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003859
3860 final long token = Binder.clearCallingIdentity();
3861 try {
3862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3863 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003864 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003865 } catch (ImsException e) {
3866 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3867 + "is inactive, ignoring unregister.");
3868 // If the subscription is no longer active, just return, since the callback
3869 // will already have been removed internally.
3870 } finally {
3871 Binder.restoreCallingIdentity(token);
3872 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003873 }
3874
3875 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003876 public boolean isCapable(int subId, int capability, int regTech) {
3877 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3879 final long token = Binder.clearCallingIdentity();
3880 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003881 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003882 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003883 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003884 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3885 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003886 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003887 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3888 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 } finally {
3890 Binder.restoreCallingIdentity(token);
3891 }
3892 }
3893
3894 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003895 public boolean isAvailable(int subId, int capability, int regTech) {
3896 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003897 final long token = Binder.clearCallingIdentity();
3898 try {
3899 Phone phone = getPhone(subId);
3900 if (phone == null) return false;
3901 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003902 } catch (com.android.ims.ImsException e) {
3903 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3904 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 } finally {
3906 Binder.restoreCallingIdentity(token);
3907 }
3908 }
3909
Brad Ebinger77b832e2019-10-17 17:03:22 -07003910 /**
3911 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3912 * subscription.
3913 * @param subId The subscription to use to check the configuration.
3914 * @param callback The callback that will be used to send the result.
3915 * @param capability The MmTelFeature capability that will be used to send the result.
3916 * @param transportType The transport type of the MmTelFeature capability.
3917 */
3918 @Override
3919 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3920 int transportType) {
3921 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3922 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3923 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3924 "IMS not available on device.");
3925 }
3926 final long token = Binder.clearCallingIdentity();
3927 try {
3928 int slotId = getSlotIndex(subId);
3929 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3930 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3931 + subId + "'");
3932 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3933 }
3934 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3935 transportType, aBoolean -> {
3936 try {
3937 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3938 } catch (RemoteException e) {
3939 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3940 + "running. Ignore");
3941 }
3942 });
3943 } finally {
3944 Binder.restoreCallingIdentity(token);
3945 }
3946 }
3947
shilu366312e2019-12-17 09:28:10 -08003948 /**
3949 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3950 * @param subId The subscription to use to check the configuration.
3951 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 @Override
3953 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003954 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3955 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003956
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3958 final long token = Binder.clearCallingIdentity();
3959 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003960 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003962 } catch (ImsException e) {
3963 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 } finally {
3965 Binder.restoreCallingIdentity(token);
3966 }
3967 }
3968
3969 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003970 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003972 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003976 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003978 } catch (ImsException e) {
3979 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 } finally {
3981 Binder.restoreCallingIdentity(identity);
3982 }
3983 }
3984
shilu366312e2019-12-17 09:28:10 -08003985 /**
3986 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3987 * @param subId The subscription to use to check the configuration.
3988 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003990 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003991 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3992 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 final long identity = Binder.clearCallingIdentity();
3994 try {
3995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003996 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3997 } catch (ImsException e) {
3998 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003999 } finally {
4000 Binder.restoreCallingIdentity(identity);
4001 }
4002 }
4003
4004 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004005 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004007 "setVtSettingEnabled");
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.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004011 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004012 } 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
shilu366312e2019-12-17 09:28:10 -08004019 /**
4020 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4021 * @param subId The subscription to use to check the configuration.
4022 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 @Override
4024 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004025 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4026 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004027 final long identity = Binder.clearCallingIdentity();
4028 try {
4029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004030 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004032 } catch (ImsException e) {
4033 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
4037 }
4038
4039 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004040 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004042 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004046 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
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
shilu366312e2019-12-17 09:28:10 -08004054 /**
4055 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4056 * @param subId The subscription to use to check the configuration.
4057 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 @Override
4059 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004060 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4061 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 final long identity = Binder.clearCallingIdentity();
4063 try {
4064 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004065 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004067 } catch (ImsException e) {
4068 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004069 } finally {
4070 Binder.restoreCallingIdentity(identity);
4071 }
4072 }
4073
4074 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004075 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004077 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004081 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004083 } catch (ImsException e) {
4084 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 } finally {
4086 Binder.restoreCallingIdentity(identity);
4087 }
4088 }
4089
4090 @Override
4091 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4093 "setVoWiFiNonPersistent");
4094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004097 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004098 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (ImsException e) {
4100 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
4104 }
4105
shilu366312e2019-12-17 09:28:10 -08004106 /**
4107 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4108 * @param subId The subscription to use to check the configuration.
4109 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 @Override
4111 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004112 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4113 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004117 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004119 } catch (ImsException e) {
4120 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 } finally {
4122 Binder.restoreCallingIdentity(identity);
4123 }
4124 }
4125
4126 @Override
4127 public void setVoWiFiModeSetting(int subId, int mode) {
4128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4129 "setVoWiFiModeSetting");
4130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004135 } catch (ImsException e) {
4136 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
4140 }
4141
4142 @Override
4143 public int getVoWiFiRoamingModeSetting(int subId) {
4144 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 getSlotIndexOrException(subId)).getWfcMode(true /*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 void setVoWiFiRoamingModeSetting(int subId, int mode) {
4159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4160 "setVoWiFiRoamingModeSetting");
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004164 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004166 } catch (ImsException e) {
4167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
4171 }
4172
4173 @Override
4174 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4176 "setRttCapabilityEnabled");
4177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004180 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4181 } 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
shilu366312e2019-12-17 09:28:10 -08004188 /**
4189 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4190 * @param subId The subscription to use to check the configuration.
4191 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 @Override
4193 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004194 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4195 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 final long identity = Binder.clearCallingIdentity();
4197 try {
4198 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004199 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004201 } catch (ImsException e) {
4202 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004203 } finally {
4204 Binder.restoreCallingIdentity(identity);
4205 }
4206 }
4207
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004208 @Override
4209 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4210 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4211 final long identity = Binder.clearCallingIdentity();
4212 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004213 if (!isImsAvailableOnDevice()) {
4214 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4215 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004216 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004217 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004218 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004219 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004220 } catch (ImsException e) {
4221 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004222 } finally {
4223 Binder.restoreCallingIdentity(identity);
4224 }
4225 }
4226
4227 @Override
4228 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4229 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4230 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004231 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4232 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4233 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004234 try {
4235 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004236 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004237 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004238 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004239 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4240 + "is inactive, ignoring unregister.");
4241 // If the subscription is no longer active, just return, since the callback will already
4242 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004243 } finally {
4244 Binder.restoreCallingIdentity(identity);
4245 }
4246 }
4247
allenwtsu99c623b2020-01-03 18:24:23 +08004248
4249 private void checkModifyPhoneStatePermission(int subId, String message) {
4250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4251 message);
4252 }
4253
4254 private boolean isImsProvisioningRequired(int subId, int capability,
4255 boolean isMmtelCapability) {
4256 Phone phone = getPhone(subId);
4257 if (phone == null) {
4258 loge("phone instance null for subid " + subId);
4259 return false;
4260 }
4261 if (isMmtelCapability) {
4262 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4263 return false;
4264 }
4265 } else {
4266 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4267 return false;
4268 }
4269 }
4270 return true;
4271 }
4272
4273 @Override
4274 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4275 boolean isProvisioned) {
4276 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4277
4278 final long identity = Binder.clearCallingIdentity();
4279 try {
4280 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4281 if (!isImsProvisioningRequired(subId, capability, false)) {
4282 return;
4283 }
4284
4285 // this capability requires provisioning, route to the correct API.
4286 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4287 switch (capability) {
4288 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4289 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4290 ims.setEabProvisioned(isProvisioned);
4291 break;
4292 default: {
4293 throw new IllegalArgumentException("Tried to set provisioning for "
4294 + "rcs capability '" + capability + "', which does not require "
4295 + "provisioning.");
4296 }
4297 }
4298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
4301
4302 }
4303
4304
4305 @Override
4306 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4307 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4311 if (!isImsProvisioningRequired(subId, capability, false)) {
4312 return true;
4313 }
4314
4315 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4316 switch (capability) {
4317 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4318 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4319 return ims.isEabProvisionedOnDevice();
4320
4321 default: {
4322 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4323 + "capability '" + capability + "', which does not require "
4324 + "provisioning.");
4325 }
4326 }
4327
4328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
4331 }
4332
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004333 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004334 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4335 boolean isProvisioned) {
4336 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4337 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4338 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4339 }
allenwtsu99c623b2020-01-03 18:24:23 +08004340 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004341 final long identity = Binder.clearCallingIdentity();
4342 try {
4343 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004344 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004345 return;
4346 }
4347
4348 // this capability requires provisioning, route to the correct API.
4349 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4350 switch (capability) {
4351 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4352 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4353 ims.setVolteProvisioned(isProvisioned);
4354 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4355 ims.setWfcProvisioned(isProvisioned);
4356 }
4357 break;
4358 }
4359 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4360 // There is currently no difference in VT provisioning type.
4361 ims.setVtProvisioned(isProvisioned);
4362 break;
4363 }
4364 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4365 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4366 // change the capability of the feature instead if needed.
4367 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4368 == isProvisioned) {
4369 // No change in provisioning.
4370 return;
4371 }
4372 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4373 try {
4374 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004375 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004376 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4377 + ", Exception" + e.getMessage());
4378 }
4379 break;
4380 }
4381 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004382 throw new IllegalArgumentException("Tried to set provisioning for "
4383 + "MmTel capability '" + capability + "', which does not require "
4384 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004385 }
4386 }
4387
4388 } finally {
4389 Binder.restoreCallingIdentity(identity);
4390 }
4391 }
4392
4393 @Override
4394 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4395 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4396 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4397 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4398 }
4399 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4400 final long identity = Binder.clearCallingIdentity();
4401 try {
4402 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004403 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004404 return true;
4405 }
4406
4407 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4408 switch (capability) {
4409 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4410 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4411 return ims.isVolteProvisionedOnDevice();
4412 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4413 return ims.isWfcProvisionedOnDevice();
4414 }
4415 // This should never happen, since we are checking tech above to make sure it
4416 // is either LTE or IWLAN.
4417 throw new IllegalArgumentException("Invalid radio technology for voice "
4418 + "capability.");
4419 }
4420 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4421 // There is currently no difference in VT provisioning type.
4422 return ims.isVtProvisionedOnDevice();
4423 }
4424 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4425 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4426 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4427 }
4428 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004429 throw new IllegalArgumentException(
4430 "Tried to get provisioning for MmTel capability '" + capability
4431 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004432 }
4433 }
4434
4435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
4438 }
4439
4440 @Override
4441 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4442 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4443 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4444 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4445 }
4446 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4447 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4448 return (provisionedBits & capability) > 0;
4449 }
4450
4451 @Override
4452 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4453 boolean isProvisioned) {
4454 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4455 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4456 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4457 }
4458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4459 "setProvisioningStatusForCapability");
4460 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4461 // If the current provisioning status for capability already matches isProvisioned,
4462 // do nothing.
4463 if (((provisionedBits & capability) > 0) == isProvisioned) {
4464 return;
4465 }
4466 if (isProvisioned) {
4467 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4468 } else {
4469 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4470 }
4471 }
4472
4473 /**
4474 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4475 * technology. The bitfield should mirror the bitfield defined by
4476 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4477 */
4478 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4479 String key = getMmTelProvisioningKey(subId, tech);
4480 // Default is no capabilities are provisioned.
4481 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4482 }
4483
4484 /**
4485 * Sets the MmTel capability provisioning bitfield (defined by
4486 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4487 * technology specified.
4488 *
4489 * Note: This is a synchronous command and should not be called on UI thread.
4490 */
4491 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4492 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4493 String key = getMmTelProvisioningKey(subId, tech);
4494 editor.putInt(key, newField);
4495 editor.commit();
4496 }
4497
4498 private static String getMmTelProvisioningKey(int subId, int tech) {
4499 // resulting key is provision_ims_mmtel_{subId}_{tech}
4500 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4501 }
4502
4503 /**
4504 * Query CarrierConfig to see if the specified capability requires provisioning for the
4505 * carrier associated with the subscription id.
4506 */
4507 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4508 int capability) {
4509 CarrierConfigManager configManager = new CarrierConfigManager(context);
4510 PersistableBundle c = configManager.getConfigForSubId(subId);
4511 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004512 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004513 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4514 false);
4515 boolean requireVoiceVtProvisioning = c.getBoolean(
4516 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4517
4518 // First check to make sure that the capability requires provisioning.
4519 switch (capability) {
4520 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4521 // intentional fallthrough
4522 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4523 if (requireVoiceVtProvisioning) {
4524 // Voice and Video requires provisioning
4525 return true;
4526 }
4527 break;
4528 }
4529 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4530 if (requireUtProvisioning) {
4531 // UT requires provisioning
4532 return true;
4533 }
4534 break;
4535 }
4536 }
4537 return false;
4538 }
4539
allenwtsu99c623b2020-01-03 18:24:23 +08004540 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4541 int capability) {
4542 CarrierConfigManager configManager = new CarrierConfigManager(context);
4543 PersistableBundle c = configManager.getConfigForSubId(subId);
4544
4545 boolean requireRcsProvisioning = c.getBoolean(
4546 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4547
4548 // First check to make sure that the capability requires provisioning.
4549 switch (capability) {
4550 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4551 // intentional fallthrough
4552 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4553 if (requireRcsProvisioning) {
4554 // OPTION or PRESENCE requires provisioning
4555 return true;
4556 }
4557 break;
4558 }
4559 }
4560 return false;
4561 }
4562
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004563 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004564 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004565 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4566 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4567 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004568 enforceReadPrivilegedPermission("getImsProvisioningInt");
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004572 int slotId = getSlotIndex(subId);
4573 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4574 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4575 + subId + "' for key:" + key);
4576 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4577 }
4578 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004579 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004580 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4581 + subId + "' for key:" + key);
4582 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
4586 }
4587
4588 @Override
4589 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4591 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4592 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 enforceReadPrivilegedPermission("getImsProvisioningString");
4594 final long identity = Binder.clearCallingIdentity();
4595 try {
4596 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004597 int slotId = getSlotIndex(subId);
4598 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4599 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4600 + subId + "' for key:" + key);
4601 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4602 }
4603 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004604 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004605 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4606 + subId + "' for key:" + key);
4607 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004608 } finally {
4609 Binder.restoreCallingIdentity(identity);
4610 }
4611 }
4612
4613 @Override
4614 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004615 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4616 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4617 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4619 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004620 final long identity = Binder.clearCallingIdentity();
4621 try {
4622 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004623 int slotId = getSlotIndex(subId);
4624 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4625 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4626 + subId + "' for key:" + key);
4627 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4628 }
4629 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004630 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004631 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4632 + "' for key:" + key);
4633 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004634 } finally {
4635 Binder.restoreCallingIdentity(identity);
4636 }
4637 }
4638
4639 @Override
4640 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4642 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4643 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4645 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004646 final long identity = Binder.clearCallingIdentity();
4647 try {
4648 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004649 int slotId = getSlotIndex(subId);
4650 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4651 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4652 + subId + "' for key:" + key);
4653 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4654 }
4655 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004656 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4658 + "' for key:" + key);
4659 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004660 } finally {
4661 Binder.restoreCallingIdentity(identity);
4662 }
4663 }
4664
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004665 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004666 int slotId = SubscriptionManager.getSlotIndex(subId);
4667 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004668 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4669 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004670 }
4671 return slotId;
4672 }
4673
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004674 private int getSlotIndex(int subId) {
4675 int slotId = SubscriptionManager.getSlotIndex(subId);
4676 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4677 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4678 }
4679 return slotId;
4680 }
4681
Wink Saville36469e72014-06-11 15:17:00 -07004682 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004683 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004684 */
4685 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004686 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4687 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004688 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004689 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004690 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004691 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004692 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004693 mApp, subId, callingPackage, callingFeatureId,
4694 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004695 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4696 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 final long identity = Binder.clearCallingIdentity();
4699 try {
4700 final Phone phone = getPhone(subId);
4701 if (phone != null) {
4702 return phone.getServiceState().getDataNetworkType();
4703 } else {
4704 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4705 }
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004708 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004709 }
4710
4711 /**
4712 * Returns the data network type
4713 */
4714 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004715 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4716 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4717 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004718 }
4719
4720 /**
4721 * Returns the data network type for a subId
4722 */
4723 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004724 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4725 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004727 mApp, subId, callingPackage, callingFeatureId,
4728 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004729 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4730 }
4731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732 final long identity = Binder.clearCallingIdentity();
4733 try {
4734 final Phone phone = getPhone(subId);
4735 if (phone != null) {
4736 return phone.getServiceState().getDataNetworkType();
4737 } else {
4738 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4739 }
4740 } finally {
4741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004743 }
4744
4745 /**
Wink Saville36469e72014-06-11 15:17:00 -07004746 * Returns the Voice network type for a subId
4747 */
4748 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004749 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4750 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004751 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004752 mApp, subId, callingPackage, callingFeatureId,
4753 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004754 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4755 }
4756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757 final long identity = Binder.clearCallingIdentity();
4758 try {
4759 final Phone phone = getPhone(subId);
4760 if (phone != null) {
4761 return phone.getServiceState().getVoiceNetworkType();
4762 } else {
4763 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4764 }
4765 } finally {
4766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004768 }
4769
4770 /**
4771 * @return true if a ICC card is present
4772 */
4773 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004774 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004775 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4776 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004777 }
4778
4779 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004780 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004781 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004782 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004783 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 final long identity = Binder.clearCallingIdentity();
4785 try {
4786 final Phone phone = PhoneFactory.getPhone(slotIndex);
4787 if (phone != null) {
4788 return phone.getIccCard().hasIccCard();
4789 } else {
4790 return false;
4791 }
4792 } finally {
4793 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004795 }
4796
4797 /**
4798 * Return if the current radio is LTE on CDMA. This
4799 * is a tri-state return value as for a period of time
4800 * the mode may be unknown.
4801 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004802 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004803 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004804 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004805 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004806 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004807 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4808 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4809 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004810 }
4811
Sanket Padawe356d7632015-06-22 14:03:32 -07004812 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004813 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4814 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004815 try {
4816 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4817 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004818 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4819 }
4820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821 final long identity = Binder.clearCallingIdentity();
4822 try {
4823 final Phone phone = getPhone(subId);
4824 if (phone == null) {
4825 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4826 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004827 return TelephonyProperties.lte_on_cdma_device()
4828 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 }
4830 } finally {
4831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004832 }
Wink Saville36469e72014-06-11 15:17:00 -07004833 }
4834
Wink Saville36469e72014-06-11 15:17:00 -07004835 /**
4836 * {@hide}
4837 * Returns Default subId, 0 in the case of single standby.
4838 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004839 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004840 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004841 }
4842
Shishir Agrawala9f32182016-04-12 12:00:16 -07004843 private int getSlotForDefaultSubscription() {
4844 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4845 }
4846
Wink Savilleb564aae2014-10-23 10:18:09 -07004847 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004848 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004849 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004850
Pengquan Menge92a50d2018-09-21 15:54:48 -07004851 private boolean isActiveSubscription(int subId) {
4852 return mSubscriptionController.isActiveSubId(subId);
4853 }
4854
Ihab Awadf2177b72013-11-25 13:33:23 -08004855 /**
4856 * @see android.telephony.TelephonyManager.WifiCallingChoices
4857 */
4858 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 final long identity = Binder.clearCallingIdentity();
4860 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004861 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4863 getWhenToMakeWifiCallsDefaultPreference());
4864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004867 }
4868
4869 /**
4870 * @see android.telephony.TelephonyManager.WifiCallingChoices
4871 */
4872 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873 final long identity = Binder.clearCallingIdentity();
4874 try {
4875 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004876 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004877 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004881 }
4882
Sailesh Nepald1e68152013-12-12 19:08:02 -08004883 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004884 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004885 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004886 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004887
Jordan Liu4c733742019-02-28 12:03:40 -08004888 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4889 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4890 if (phoneId == -1) {
4891 throw new IllegalArgumentException("Given slot index: " + slotIndex
4892 + " does not correspond to an active phone");
4893 }
4894 return PhoneFactory.getPhone(phoneId);
4895 }
4896
Shishir Agrawal566b7612013-10-28 14:41:00 -07004897 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004898 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4899 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4901 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004903 if (DBG) {
4904 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4905 }
4906 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4907 p2);
4908 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004909
Jordan Liu4c733742019-02-28 12:03:40 -08004910
4911 @Override
4912 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4913 int slotIndex, String callingPackage, String aid, int p2) {
4914 enforceModifyPermission();
4915 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4916 if (DBG) {
4917 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4918 }
4919 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4920 callingPackage, aid, p2);
4921 }
4922
4923 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4924 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925 final long identity = Binder.clearCallingIdentity();
4926 try {
4927 if (TextUtils.equals(ISDR_AID, aid)) {
4928 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004929 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4930 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 if (bestComponent == null
4932 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4933 loge("The calling package is not allowed to access ISD-R.");
4934 throw new SecurityException(
4935 "The calling package is not allowed to access ISD-R.");
4936 }
Derek Tan740e1672017-06-27 14:56:27 -07004937 }
Derek Tan740e1672017-06-27 14:56:27 -07004938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004940 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4941 null /* workSource */);
4942 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 return response;
4944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004947 }
4948
4949 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004950 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4952 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004953 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4954 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4955 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004956
Jordan Liu4c733742019-02-28 12:03:40 -08004957 @Override
4958 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4959 enforceModifyPermission();
4960 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4961 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4962 channel);
4963 }
4964
4965 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 final long identity = Binder.clearCallingIdentity();
4967 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 if (channel < 0) {
4969 return false;
4970 }
Jordan Liu4c733742019-02-28 12:03:40 -08004971 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4972 null /* workSource */);
4973 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 return success;
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004977 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004978 }
4979
4980 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004981 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004982 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4984 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004985 if (DBG) {
4986 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4987 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4988 + p3 + " data=" + data);
4989 }
4990 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4991 command, p1, p2, p3, data);
4992 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004993
Jordan Liu4c733742019-02-28 12:03:40 -08004994 @Override
4995 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4996 int command, int p1, int p2, int p3, String data) {
4997 enforceModifyPermission();
4998 if (DBG) {
4999 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5000 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5001 + p3 + " data=" + data);
5002 }
5003 return iccTransmitApduLogicalChannelWithPermission(
5004 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5005 data);
5006 }
5007
5008 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5009 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 final long identity = Binder.clearCallingIdentity();
5011 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005012 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 return "";
5014 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005017 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5018 null /* workSource */);
5019 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021 // Append the returned status code to the end of the response payload.
5022 String s = Integer.toHexString(
5023 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5024 if (response.payload != null) {
5025 s = IccUtils.bytesToHexString(response.payload) + s;
5026 }
5027 return s;
5028 } finally {
5029 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005030 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005031 }
Jake Hambye994d462014-02-03 13:10:13 -08005032
Evan Charltonc66da362014-05-16 14:06:40 -07005033 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005034 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5035 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5037 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005039 if (DBG) {
5040 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5041 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5042 }
5043 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5044 cla, command, p1, p2, p3, data);
5045 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005046
Jordan Liu4c733742019-02-28 12:03:40 -08005047 @Override
5048 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5049 int command, int p1, int p2, int p3, String data) {
5050 enforceModifyPermission();
5051 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5052 if (DBG) {
5053 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5054 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5055 + " data=" + data);
5056 }
5057
5058 return iccTransmitApduBasicChannelWithPermission(
5059 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5060 p2, p3, data);
5061 }
5062
5063 // open APDU basic channel assuming the caller has sufficient permissions
5064 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5065 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 final long identity = Binder.clearCallingIdentity();
5067 try {
5068 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5069 && TextUtils.equals(ISDR_AID, data)) {
5070 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005071 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5072 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 if (bestComponent == null
5074 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5075 loge("The calling package is not allowed to select ISD-R.");
5076 throw new SecurityException(
5077 "The calling package is not allowed to select ISD-R.");
5078 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005079 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005082 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5083 null /* workSource */);
5084 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 // Append the returned status code to the end of the response payload.
5087 String s = Integer.toHexString(
5088 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5089 if (response.payload != null) {
5090 s = IccUtils.bytesToHexString(response.payload) + s;
5091 }
5092 return s;
5093 } finally {
5094 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005095 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005096 }
5097
5098 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005099 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005100 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5102 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 if (DBG) {
5107 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5108 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5109 }
5110
5111 IccIoResult response =
5112 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5113 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5114 subId);
5115
5116 if (DBG) {
5117 log("Exchange SIM_IO [R]" + response);
5118 }
5119
5120 byte[] result = null;
5121 int length = 2;
5122 if (response.payload != null) {
5123 length = 2 + response.payload.length;
5124 result = new byte[length];
5125 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5126 } else {
5127 result = new byte[length];
5128 }
5129
5130 result[length - 1] = (byte) response.sw2;
5131 result[length - 2] = (byte) response.sw1;
5132 return result;
5133 } finally {
5134 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005135 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005136 }
5137
Nathan Haroldb3014052017-01-25 15:57:32 -08005138 /**
5139 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5140 * on a particular subscription
5141 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005142 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5143 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005145 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005146 return null;
5147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148
5149 final long identity = Binder.clearCallingIdentity();
5150 try {
5151 if (appType != TelephonyManager.APPTYPE_USIM
5152 && appType != TelephonyManager.APPTYPE_SIM) {
5153 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5154 return null;
5155 }
5156 Object response = sendRequest(
5157 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5158 if (response instanceof String[]) {
5159 return (String[]) response;
5160 }
yincheng zhaod698b842019-09-06 17:06:54 -07005161 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005163 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005166 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005167 }
5168
yincheng zhaod698b842019-09-06 17:06:54 -07005169 /**
5170 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5171 * subscription.
5172 *
5173 * @param subId the id of the subscription.
5174 * @param appType the uicc app type, must be USIM or SIM.
5175 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5176 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005177 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005178 * @return number of fplmns that is successfully written to the SIM.
5179 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005180 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5181 String callingFeatureId) {
5182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5183 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005184 if (DBG) logv("no permissions for setForbiddenplmns");
5185 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5186 }
5187 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5188 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5189 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5190 }
5191 if (fplmns == null) {
5192 throw new IllegalArgumentException("Fplmn List provided is null");
5193 }
5194 for (String fplmn : fplmns) {
5195 if (!CellIdentity.isValidPlmn(fplmn)) {
5196 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5197 }
5198 }
5199 final long identity = Binder.clearCallingIdentity();
5200 try {
5201 Object response = sendRequest(
5202 CMD_SET_FORBIDDEN_PLMNS,
5203 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5204 subId);
5205 return (int) response;
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
5208 }
5209 }
5210
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005211 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005212 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5214 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 final long identity = Binder.clearCallingIdentity();
5217 try {
5218 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5219 if (response.payload == null) {
5220 return "";
5221 }
Evan Charltonc66da362014-05-16 14:06:40 -07005222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 // Append the returned status code to the end of the response payload.
5224 String s = Integer.toHexString(
5225 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5226 s = IccUtils.bytesToHexString(response.payload) + s;
5227 return s;
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Evan Charltonc66da362014-05-16 14:06:40 -07005231 }
5232
Jake Hambye994d462014-02-03 13:10:13 -08005233 /**
5234 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5235 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5236 *
5237 * @param itemID the ID of the item to read
5238 * @return the NV item as a String, or null on error.
5239 */
5240 @Override
5241 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005242 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5244 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245
5246 final long identity = Binder.clearCallingIdentity();
5247 try {
5248 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005249 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5251 return value;
5252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
Jake Hambye994d462014-02-03 13:10:13 -08005255 }
5256
5257 /**
5258 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5259 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5260 *
5261 * @param itemID the ID of the item to read
5262 * @param itemValue the value to write, as a String
5263 * @return true on success; false on any failure
5264 */
5265 @Override
5266 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005267 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5269 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270
5271 final long identity = Binder.clearCallingIdentity();
5272 try {
5273 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5274 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005275 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5277 return success;
5278 } finally {
5279 Binder.restoreCallingIdentity(identity);
5280 }
Jake Hambye994d462014-02-03 13:10:13 -08005281 }
5282
5283 /**
5284 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5285 * Used for device configuration by some CDMA operators.
5286 *
5287 * @param preferredRoamingList byte array containing the new PRL
5288 * @return true on success; false on any failure
5289 */
5290 @Override
5291 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5293 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294
5295 final long identity = Binder.clearCallingIdentity();
5296 try {
5297 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5298 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5299 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5300 return success;
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
5303 }
Jake Hambye994d462014-02-03 13:10:13 -08005304 }
5305
5306 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005307 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005308 * Used for device configuration by some CDMA operators.
5309 *
chen xu6dac5ab2018-10-26 17:39:23 -07005310 * @param slotIndex - device slot.
5311 *
Jake Hambye994d462014-02-03 13:10:13 -08005312 * @return true on success; false on any failure
5313 */
5314 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005315 public boolean resetModemConfig(int slotIndex) {
5316 Phone phone = PhoneFactory.getPhone(slotIndex);
5317 if (phone != null) {
5318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5319 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320
chen xu6dac5ab2018-10-26 17:39:23 -07005321 final long identity = Binder.clearCallingIdentity();
5322 try {
5323 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5324 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5325 return success;
5326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 }
chen xu6dac5ab2018-10-26 17:39:23 -07005330 return false;
5331 }
5332
5333 /**
5334 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5335 *
5336 * @param slotIndex - device slot.
5337 *
5338 * @return true on success; false on any failure
5339 */
5340 @Override
5341 public boolean rebootModem(int slotIndex) {
5342 Phone phone = PhoneFactory.getPhone(slotIndex);
5343 if (phone != null) {
5344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5345 mApp, phone.getSubId(), "rebootModem");
5346
5347 final long identity = Binder.clearCallingIdentity();
5348 try {
5349 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5350 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5351 return success;
5352 } finally {
5353 Binder.restoreCallingIdentity(identity);
5354 }
5355 }
5356 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005357 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005358
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005359 public String[] getPcscfAddress(String apnType, String callingPackage,
5360 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005361 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5363 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005364 return new String[0];
5365 }
5366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367 final long identity = Binder.clearCallingIdentity();
5368 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005369 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 } finally {
5371 Binder.restoreCallingIdentity(identity);
5372 }
Wink Saville36469e72014-06-11 15:17:00 -07005373 }
5374
Brad Ebinger51f743a2017-01-23 13:50:20 -08005375 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005376 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5377 * {@link #disableIms(int)}.
5378 * @param slotIndex device slot.
5379 */
5380 public void resetIms(int slotIndex) {
5381 enforceModifyPermission();
5382
5383 final long identity = Binder.clearCallingIdentity();
5384 try {
5385 if (mImsResolver == null) {
5386 // may happen if the does not support IMS.
5387 return;
5388 }
5389 mImsResolver.disableIms(slotIndex);
5390 mImsResolver.enableIms(slotIndex);
5391 } finally {
5392 Binder.restoreCallingIdentity(identity);
5393 }
5394 }
5395
5396 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005397 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5398 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005399 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005400 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005401 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402
5403 final long identity = Binder.clearCallingIdentity();
5404 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005405 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005406 // may happen if the device does not support IMS.
5407 return;
5408 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005409 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 } finally {
5411 Binder.restoreCallingIdentity(identity);
5412 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005413 }
5414
5415 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005416 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5417 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005418 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005419 public void disableIms(int slotId) {
5420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421
5422 final long identity = Binder.clearCallingIdentity();
5423 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005424 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005425 // may happen if the device does not support IMS.
5426 return;
5427 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005428 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 } finally {
5430 Binder.restoreCallingIdentity(identity);
5431 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005432 }
5433
5434 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005435 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5436 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005437 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005438 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005439 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005440 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441
5442 final long identity = Binder.clearCallingIdentity();
5443 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005444 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005445 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5446 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005447 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005448 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005452 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005453 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005454 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5455 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005456 @Override
5457 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005458 enforceModifyPermission();
5459
5460 final long identity = Binder.clearCallingIdentity();
5461 try {
5462 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005463 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005464 } finally {
5465 Binder.restoreCallingIdentity(identity);
5466 }
5467 }
5468
5469 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005470 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005471 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005472 */
5473 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5474 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475
5476 final long identity = Binder.clearCallingIdentity();
5477 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005478 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005479 // may happen if the device does not support IMS.
5480 return null;
5481 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005482 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005486 }
5487
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005488 /**
5489 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005490 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005491 */
5492 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494
5495 final long identity = Binder.clearCallingIdentity();
5496 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005497 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005498 // may happen if the device does not support IMS.
5499 return null;
5500 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005501 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005505 }
5506
Brad Ebinger884c07b2018-02-15 16:17:40 -08005507 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005508 * Sets the ImsService Package Name that Telephony will bind to.
5509 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005510 * @param slotIndex the slot ID that the ImsService should bind for.
5511 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005512 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005513 * @param featureTypes An integer array of feature types associated with a packageName.
5514 * @param packageName The name of the package that the current configuration will be replaced
5515 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005516 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005517 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005518 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5519 int[] featureTypes, String packageName) {
5520 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5521 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5523 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005524 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 final long identity = Binder.clearCallingIdentity();
5527 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005528 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005529 // may happen if the device does not support IMS.
5530 return false;
5531 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005532 Map<Integer, String> featureConfig = new HashMap<>();
5533 for (int featureType : featureTypes) {
5534 featureConfig.put(featureType, packageName);
5535 }
5536 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5537 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 } finally {
5539 Binder.restoreCallingIdentity(identity);
5540 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005541 }
5542
5543 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005544 * Clears any carrier ImsService overrides for the slot index specified that were previously
5545 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5546 *
5547 * This should only be used for testing.
5548 *
5549 * @param slotIndex the slot ID that the ImsService should bind for.
5550 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5551 */
5552 @Override
5553 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5554 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5555 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5556 "clearCarrierImsServiceOverride");
5557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5558 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5559 "clearCarrierImsServiceOverride");
5560
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 if (mImsResolver == null) {
5564 // may happen if the device does not support IMS.
5565 return false;
5566 }
5567 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
5571 }
5572
5573 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005574 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005575 *
5576 * @param slotId The slot that the ImsService is associated with.
5577 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5578 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005579 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005580 * @return the package name of the ImsService configuration.
5581 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005582 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5583 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005584 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005585 TelephonyPermissions
5586 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5587 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5588 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 final long identity = Binder.clearCallingIdentity();
5591 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005592 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005593 // may happen if the device does not support IMS.
5594 return "";
5595 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005596 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005597 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5598 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005602 }
5603
Brad Ebinger77b832e2019-10-17 17:03:22 -07005604 /**
5605 * Get the MmTelFeature state associated with the requested subscription id.
5606 * @param subId The subscription that the MmTelFeature is associated with.
5607 * @param callback A callback with an integer containing the
5608 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5609 */
5610 @Override
5611 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5612 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5613 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5614 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5615 "IMS not available on device.");
5616 }
5617 final long token = Binder.clearCallingIdentity();
5618 try {
5619 int slotId = getSlotIndex(subId);
5620 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5621 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5622 + subId + "'");
5623 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5624 }
5625 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5626 try {
5627 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5628 } catch (RemoteException e) {
5629 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5630 + "Ignore");
5631 }
5632 });
5633 } finally {
5634 Binder.restoreCallingIdentity(token);
5635 }
5636 }
5637
Daniel Brightbb5840b2021-01-12 15:48:18 -08005638 /**
5639 * Sets the ims registration state on all valid {@link Phone}s.
5640 */
5641 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005642 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643
5644 final long identity = Binder.clearCallingIdentity();
5645 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005646 // NOTE: Before S, this method only set the default phone.
5647 for (final Phone phone : PhoneFactory.getPhones()) {
5648 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5649 phone.setImsRegistrationState(registered);
5650 }
5651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652 } finally {
5653 Binder.restoreCallingIdentity(identity);
5654 }
Wink Saville36469e72014-06-11 15:17:00 -07005655 }
5656
5657 /**
Stuart Scott54788802015-03-30 13:18:01 -07005658 * Set the network selection mode to automatic.
5659 *
5660 */
5661 @Override
5662 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5664 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665
5666 final long identity = Binder.clearCallingIdentity();
5667 try {
shilufc958392020-01-20 11:36:01 -08005668 if (!isActiveSubscription(subId)) {
5669 return;
5670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005672 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5673 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
Stuart Scott54788802015-03-30 13:18:01 -07005677 }
5678
Jack Yud10cdd42020-09-28 20:28:01 -07005679 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005680 * Ask the radio to connect to the input network and change selection mode to manual.
5681 *
5682 * @param subId the id of the subscription.
5683 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5684 * the operator to attach to.
5685 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5686 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5687 * normal network selection next time.
5688 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005689 */
5690 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005691 public boolean setNetworkSelectionModeManual(
5692 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5694 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005695
5696 if (!isActiveSubscription(subId)) {
5697 return false;
5698 }
5699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 final long identity = Binder.clearCallingIdentity();
5701 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005702 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005704 if (DBG) {
5705 log("setNetworkSelectionModeManual: subId: " + subId
5706 + " operator: " + operatorInfo);
5707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005712 }
shilu84f6e8b2019-12-19 13:58:01 -08005713 /**
5714 * Get the manual network selection
5715 *
5716 * @param subId the id of the subscription.
5717 *
5718 * @return the previously saved user selected PLMN
5719 */
5720 @Override
5721 public String getManualNetworkSelectionPlmn(int subId) {
5722 TelephonyPermissions
5723 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5724 mApp, subId, "getManualNetworkSelectionPlmn");
5725
5726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 if (!isActiveSubscription(subId)) {
5729 return "";
5730 }
5731
5732 final Phone phone = getPhone(subId);
5733 if (phone == null) {
5734 return "";
5735 }
5736 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5737 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5738 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
5742 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005743
5744 /**
5745 * Scans for available networks.
5746 */
5747 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005748 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5749 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5751 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005752 LocationAccessPolicy.LocationPermissionResult locationResult =
5753 LocationAccessPolicy.checkLocationPermission(mApp,
5754 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5755 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005756 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005757 .setCallingPid(Binder.getCallingPid())
5758 .setCallingUid(Binder.getCallingUid())
5759 .setMethod("getCellNetworkScanResults")
5760 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5761 .build());
5762 switch (locationResult) {
5763 case DENIED_HARD:
5764 throw new SecurityException("Not allowed to access scan results -- location");
5765 case DENIED_SOFT:
5766 return null;
5767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768
Pengquan Menga1bb6272018-09-06 09:59:22 -07005769 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 try {
5771 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005772 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005777 }
5778
5779 /**
sqian80370722020-01-29 15:02:51 -08005780 * Get the call forwarding info, given the call forwarding reason.
5781 */
5782 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005783 public void getCallForwarding(int subId, int callForwardingReason,
5784 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005785 enforceReadPrivilegedPermission("getCallForwarding");
5786 long identity = Binder.clearCallingIdentity();
5787 try {
5788 if (DBG) {
5789 log("getCallForwarding: subId " + subId
5790 + " callForwardingReason" + callForwardingReason);
5791 }
Hall Liua1acea22020-09-18 19:04:59 -07005792
5793 Phone phone = getPhone(subId);
5794 if (phone == null) {
5795 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005796 callback.onError(
5797 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005798 } catch (RemoteException e) {
5799 // ignore
5800 }
5801 return;
5802 }
5803
5804 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5805 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5806 @Override
5807 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5808 try {
5809 callback.onCallForwardingInfoAvailable(info);
5810 } catch (RemoteException e) {
5811 // ignore
5812 }
5813 }
5814
5815 @Override
5816 public void onError(int error) {
5817 try {
5818 callback.onError(error);
5819 } catch (RemoteException e) {
5820 // ignore
5821 }
5822 }
5823 });
5824 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005825 } finally {
5826 Binder.restoreCallingIdentity(identity);
5827 }
5828 }
5829
5830 /**
5831 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5832 * reason, the number to forward, and the timeout before the forwarding is attempted.
5833 */
5834 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005835 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5836 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005837 enforceModifyPermission();
5838 long identity = Binder.clearCallingIdentity();
5839 try {
5840 if (DBG) {
5841 log("setCallForwarding: subId " + subId
5842 + " callForwardingInfo" + callForwardingInfo);
5843 }
Hall Liua1acea22020-09-18 19:04:59 -07005844
5845 Phone phone = getPhone(subId);
5846 if (phone == null) {
5847 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005848 callback.accept(
5849 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005850 } catch (RemoteException e) {
5851 // ignore
5852 }
5853 return;
5854 }
5855
5856 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5857 FunctionalUtils.ignoreRemoteException(callback::accept));
5858
5859 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
5863 }
5864
5865 /**
Hall Liua1acea22020-09-18 19:04:59 -07005866 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005867 */
5868 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005869 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005870 enforceReadPrivilegedPermission("getCallForwarding");
5871 long identity = Binder.clearCallingIdentity();
5872 try {
Hall Liua1acea22020-09-18 19:04:59 -07005873
5874 Phone phone = getPhone(subId);
5875 if (phone == null) {
5876 try {
5877 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5878 } catch (RemoteException e) {
5879 // ignore
5880 }
5881 return;
5882 }
5883
5884 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5885
sqian80370722020-01-29 15:02:51 -08005886 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005887 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005888 } finally {
5889 Binder.restoreCallingIdentity(identity);
5890 }
5891 }
5892
5893 /**
Hall Liua1acea22020-09-18 19:04:59 -07005894 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005895 */
5896 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005897 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005898 enforceModifyPermission();
5899 long identity = Binder.clearCallingIdentity();
5900 try {
Hall Liua1acea22020-09-18 19:04:59 -07005901 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5902
5903 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 }
5912
5913 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5914 FunctionalUtils.ignoreRemoteException(callback::accept));
5915
5916 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005917 } finally {
5918 Binder.restoreCallingIdentity(identity);
5919 }
5920 }
5921
5922 /**
yinxub1bed742017-04-17 11:45:04 -07005923 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005924 *
yinxub1bed742017-04-17 11:45:04 -07005925 * @param subId id of the subscription
5926 * @param request contains the radio access networks with bands/channels to scan
5927 * @param messenger callback messenger for scan results or errors
5928 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005929 * @return the id of the requested scan which can be used to stop the scan.
5930 */
5931 @Override
5932 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005933 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5935 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005936 LocationAccessPolicy.LocationPermissionResult locationResult =
5937 LocationAccessPolicy.checkLocationPermission(mApp,
5938 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5939 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005940 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005941 .setCallingPid(Binder.getCallingPid())
5942 .setCallingUid(Binder.getCallingUid())
5943 .setMethod("requestNetworkScan")
5944 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5945 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005946 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005947 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5948 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005949 if (e != null) {
5950 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5951 throw e;
5952 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005953 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005954 return TelephonyScanManager.INVALID_SCAN_ID;
5955 }
5956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957 }
Hall Liu912dfd32019-04-25 14:02:26 -07005958 int callingUid = Binder.getCallingUid();
5959 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005960 final long identity = Binder.clearCallingIdentity();
5961 try {
5962 return mNetworkScanRequestTracker.startNetworkScan(
5963 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005964 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
5967 }
yinxu504e1392017-04-12 16:03:22 -07005968 }
5969
Hall Liub2ac8ef2019-02-28 15:56:23 -08005970 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005971 NetworkScanRequest request, int subId, String callingPackage) {
5972 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005973 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5974 boolean hasNetworkScanPermission =
5975 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5976 == PERMISSION_GRANTED;
5977
5978 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5979 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5980 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005981 }
5982
5983 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5984 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005985 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5986 return new SecurityException("Specific channels must not be"
5987 + " scanned without location access.");
5988 }
5989 }
5990 }
5991
Hall Liub2ac8ef2019-02-28 15:56:23 -08005992 return null;
5993 }
5994
yinxu504e1392017-04-12 16:03:22 -07005995 /**
5996 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005997 *
5998 * @param subId id of the subscription
5999 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006000 */
6001 @Override
6002 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6004 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005
Hall Liu912dfd32019-04-25 14:02:26 -07006006 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 final long identity = Binder.clearCallingIdentity();
6008 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006009 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
yinxu504e1392017-04-12 16:03:22 -07006013 }
6014
6015 /**
Junda Liu84d15a22014-07-02 11:21:04 -07006016 * Get the calculated preferred network type.
6017 * Used for debugging incorrect network type.
6018 *
6019 * @return the preferred network type, defined in RILConstants.java.
6020 */
6021 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006022 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006023 final Phone defaultPhone = getDefaultPhone();
6024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006025 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006026 return RILConstants.PREFERRED_NETWORK_MODE;
6027 }
6028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 final long identity = Binder.clearCallingIdentity();
6030 try {
6031 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006032 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 } finally {
6034 Binder.restoreCallingIdentity(identity);
6035 }
Junda Liu84d15a22014-07-02 11:21:04 -07006036 }
6037
6038 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08006039 * Get the preferred network type.
6040 * Used for device configuration by some CDMA operators.
6041 *
6042 * @return the preferred network type, defined in RILConstants.java.
6043 */
6044 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006045 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006046 TelephonyPermissions
6047 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6048 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049
6050 final long identity = Binder.clearCallingIdentity();
6051 try {
6052 if (DBG) log("getPreferredNetworkType");
6053 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
6054 int networkType = (result != null ? result[0] : -1);
6055 if (DBG) log("getPreferredNetworkType: " + networkType);
6056 return networkType;
6057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006060 }
6061
6062 /**
6063 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08006064 *
6065 * @param networkType the preferred network type, defined in RILConstants.java.
6066 * @return true on success; false on any failure.
6067 */
6068 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006069 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6071 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072
6073 final long identity = Binder.clearCallingIdentity();
6074 try {
calvinpan089c2a62020-03-12 14:17:55 +08006075 Boolean success = (Boolean) sendRequest(
6076 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08006077
6078 if (success) {
6079 Settings.Global.putInt(mApp.getContentResolver(),
6080 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
6081 }
calvinpan089c2a62020-03-12 14:17:55 +08006082 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
6083 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 } finally {
6085 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07006086 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006087 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006088
6089 /**
calvinpan677fc2b2020-01-14 20:42:55 +08006090 * Get the allowed network types that store in the telephony provider.
6091 *
6092 * @param subId the id of the subscription.
6093 * @return allowedNetworkTypes the allowed network types.
6094 */
6095 @Override
6096 public long getAllowedNetworkTypes(int subId) {
6097 TelephonyPermissions
6098 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6099 mApp, subId, "getAllowedNetworkTypes");
6100
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
6103 return SubscriptionManager.getLongSubscriptionProperty(
6104 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6105 } finally {
6106 Binder.restoreCallingIdentity(identity);
6107 }
6108 }
6109
6110 /**
6111 * Set the allowed network types.
6112 *
6113 * @param subId the id of the subscription.
6114 * @param allowedNetworkTypes the allowed network types.
6115 * @return true on success; false on any failure.
6116 */
6117 @Override
6118 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6120 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08006121
calvinpan089c2a62020-03-12 14:17:55 +08006122 SubscriptionManager.setSubscriptionProperty(subId,
6123 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6124 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08006125
calvinpan089c2a62020-03-12 14:17:55 +08006126 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6127 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6128 RILConstants.PREFERRED_NETWORK_MODE);
6129 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08006130 }
6131
6132 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006133 * Get the allowed network types for certain reason.
6134 *
6135 * @param subId the id of the subscription.
6136 * @param reason the reason the allowed network type change is taking place
6137 * @return the allowed network types.
6138 */
6139 @Override
6140 public long getAllowedNetworkTypesForReason(int subId,
6141 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6142 TelephonyPermissions
6143 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6144 mApp, subId, "getAllowedNetworkTypesForReason");
6145 final long identity = Binder.clearCallingIdentity();
6146 try {
6147 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6148 } finally {
6149 Binder.restoreCallingIdentity(identity);
6150 }
6151 }
6152
6153 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006154 * Enable/Disable E-UTRA-NR Dual Connectivity
6155 * @param subId subscription id of the sim card
6156 * @param nrDualConnectivityState expected NR dual connectivity state
6157 * This can be passed following states
6158 * <ol>
6159 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6160 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6161 * <li>Disable NR dual connectivity and force secondary cell to be released
6162 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6163 * </ol>
6164 * @return operation result.
6165 */
6166 @Override
6167 public int setNrDualConnectivityState(int subId,
6168 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6170 mApp, subId, "enableNRDualConnectivity");
6171 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6172 final long identity = Binder.clearCallingIdentity();
6173 try {
6174 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6175 nrDualConnectivityState, subId,
6176 workSource);
6177 if (DBG) log("enableNRDualConnectivity result: " + result);
6178 return result;
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
6181 }
6182 }
6183
6184 /**
6185 * Is E-UTRA-NR Dual Connectivity enabled
6186 * @return true if dual connectivity is enabled else false
6187 */
6188 @Override
6189 public boolean isNrDualConnectivityEnabled(int subId) {
6190 TelephonyPermissions
6191 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6192 mApp, subId, "isNRDualConnectivityEnabled");
6193 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6194 final long identity = Binder.clearCallingIdentity();
6195 try {
6196 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6197 null, subId, workSource);
6198 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6199 return isEnabled;
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
6202 }
6203 }
6204
6205 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006206 * get carrier bandwidth per primary and secondary carrier
6207 * @param subId subscription id of the sim card
6208 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6209 */
6210 @Override
6211 public CarrierBandwidth getCarrierBandwidth(int subId) {
6212 TelephonyPermissions
6213 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6214 mApp, subId, "isNRDualConnectivityEnabled");
6215 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6216 final long identity = Binder.clearCallingIdentity();
6217 try {
6218 CarrierBandwidth carrierBandwidth =
6219 getPhoneFromSubId(subId).getCarrierBandwidth();
6220 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6221 return carrierBandwidth;
6222 } finally {
6223 Binder.restoreCallingIdentity(identity);
6224 }
6225 }
6226
6227 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006228 * Get the effective allowed network types on the device.
6229 * This API will return an intersection of allowed network types for all reasons,
6230 * including the configuration done through setAllowedNetworkTypes
6231 *
6232 * @param subId the id of the subscription.
6233 * @return the allowed network types
6234 */
6235 @Override
6236 public long getEffectiveAllowedNetworkTypes(int subId) {
6237 TelephonyPermissions
6238 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6239 mApp, subId, "getEffectiveAllowedNetworkTypes");
6240 final long identity = Binder.clearCallingIdentity();
6241 try {
6242 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6243 } finally {
6244 Binder.restoreCallingIdentity(identity);
6245 }
6246 }
6247
6248 /**
6249 * Set the allowed network types of the device and
6250 * provide the reason triggering the allowed network change.
6251 *
6252 * @param subId the id of the subscription.
6253 * @param reason the reason the allowed network type change is taking place
6254 * @param allowedNetworkTypes the allowed network types.
6255 * @return true on success; false on any failure.
6256 */
6257 @Override
6258 public boolean setAllowedNetworkTypesForReason(int subId,
6259 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6261 mApp, subId, "setAllowedNetworkTypesForReason");
6262 final long identity = Binder.clearCallingIdentity();
6263 try {
6264 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6265 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6266 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6267 RILConstants.PREFERRED_NETWORK_MODE);
6268 return setPreferredNetworkType(subId, preferredNetworkMode);
6269 } finally {
6270 Binder.restoreCallingIdentity(identity);
6271 }
6272 }
6273
6274 /**
Miaoa84611c2019-03-15 09:21:10 +08006275 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006276 *
Miaoa84611c2019-03-15 09:21:10 +08006277 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006278 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006279 * @hide
6280 */
6281 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006282 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006283 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006285 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286 try {
Miaoa84611c2019-03-15 09:21:10 +08006287 if (phone != null) {
6288 return phone.hasMatchedTetherApnSetting();
6289 } else {
6290 return false;
6291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 } finally {
6293 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006294 }
Junda Liu475951f2014-11-07 16:45:03 -08006295 }
6296
6297 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006298 * Enable or disable always reporting signal strength changes from radio.
6299 *
6300 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6301 */
6302 @Override
6303 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6304 enforceModifyPermission();
6305 enforceSystemCaller();
6306
6307 final long identity = Binder.clearCallingIdentity();
6308 final Phone phone = getPhone(subId);
6309 try {
6310 if (phone != null) {
6311 if (DBG) {
6312 log("setAlwaysReportSignalStrength: subId=" + subId
6313 + " isEnable=" + isEnable);
6314 }
6315 phone.setAlwaysReportSignalStrength(isEnable);
6316 } else {
6317 loge("setAlwaysReportSignalStrength: no phone found for subId="
6318 + subId);
6319 }
6320 } finally {
6321 Binder.restoreCallingIdentity(identity);
6322 }
6323 }
6324
6325 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006326 * Get the user enabled state of Mobile Data.
6327 *
6328 * TODO: remove and use isUserDataEnabled.
6329 * This can't be removed now because some vendor codes
6330 * calls through ITelephony directly while they should
6331 * use TelephonyManager.
6332 *
6333 * @return true on enabled
6334 */
6335 @Override
6336 public boolean getDataEnabled(int subId) {
6337 return isUserDataEnabled(subId);
6338 }
6339
6340 /**
6341 * Get whether mobile data is enabled per user setting.
6342 *
6343 * There are other factors deciding whether mobile data is actually enabled, but they are
6344 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006345 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006346 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006347 *
6348 * @return {@code true} if data is enabled else {@code false}
6349 */
6350 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006351 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006352 try {
6353 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6354 null);
6355 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6357 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359
6360 final long identity = Binder.clearCallingIdentity();
6361 try {
6362 int phoneId = mSubscriptionController.getPhoneId(subId);
6363 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6364 Phone phone = PhoneFactory.getPhone(phoneId);
6365 if (phone != null) {
6366 boolean retVal = phone.isUserDataEnabled();
6367 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6368 return retVal;
6369 } else {
6370 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6371 return false;
6372 }
6373 } finally {
6374 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006375 }
6376 }
6377
6378 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006379 * Checks if the device is capable of mobile data by considering whether whether the
6380 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6381 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006382 *
Shuo Qian985d1232020-01-08 14:30:06 -08006383 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006384 */
6385 @Override
6386 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006387 try {
6388 try {
6389 mApp.enforceCallingOrSelfPermission(
6390 android.Manifest.permission.ACCESS_NETWORK_STATE,
6391 null);
6392 } catch (Exception e) {
6393 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6394 "isDataEnabled");
6395 }
6396 } catch (Exception e) {
6397 enforceReadPrivilegedPermission("isDataEnabled");
6398 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
6402 int phoneId = mSubscriptionController.getPhoneId(subId);
6403 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6404 Phone phone = PhoneFactory.getPhone(phoneId);
6405 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006406 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6408 return retVal;
6409 } else {
6410 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6411 return false;
6412 }
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006415 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006416 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006417
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006418 /**
6419 * Check if data is enabled for a specific reason
6420 * @param subId Subscription index
6421 * @param reason the reason the data enable change is taking place
6422 * @return {@code true} if the overall data is enabled; {@code false} if not.
6423 */
6424 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006425 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006426 @TelephonyManager.DataEnabledReason int reason) {
6427 try {
6428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6429 null);
6430 } catch (Exception e) {
6431 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006432 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006433 }
6434
6435
6436 final long identity = Binder.clearCallingIdentity();
6437 try {
6438 int phoneId = mSubscriptionController.getPhoneId(subId);
6439 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006440 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006441 + " reason=" + reason);
6442 }
6443 Phone phone = PhoneFactory.getPhone(phoneId);
6444 if (phone != null) {
6445 boolean retVal;
6446 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6447 retVal = phone.isUserDataEnabled();
6448 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006449 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006450 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006451 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006452 return retVal;
6453 } else {
6454 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006455 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006456 + subId + " retVal=false");
6457 }
6458 return false;
6459 }
6460 } finally {
6461 Binder.restoreCallingIdentity(identity);
6462 }
6463 }
6464
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006465 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006466 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006467 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6468 // Skip the check if it's one of these special uids
6469 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6470 }
6471
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006472 //load access rules from carrier configs, and check those as well: b/139133814
6473 SubscriptionController subController = SubscriptionController.getInstance();
6474 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6475 || subController == null) return privilegeFromSim;
6476
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006477 PackageManager pkgMgr = phone.getContext().getPackageManager();
6478 String[] packages = pkgMgr.getPackagesForUid(uid);
6479
6480 final long identity = Binder.clearCallingIdentity();
6481 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006482 int subId = phone.getSubId();
6483 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6484 // A test override is in place for the privileges for this subId, so don't try to
6485 // read the subscription privileges.
6486 return privilegeFromSim;
6487 }
6488 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006489 SubscriptionManager subManager = (SubscriptionManager)
6490 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6491 for (String pkg : packages) {
6492 if (subManager.canManageSubscription(subInfo, pkg)) {
6493 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6494 }
6495 }
6496 return privilegeFromSim;
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
6500 }
6501
6502 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6503 String pkgName) {
6504 //load access rules from carrier configs, and check those as well: b/139133814
6505 SubscriptionController subController = SubscriptionController.getInstance();
6506 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6507 || subController == null) return privilegeFromSim;
6508
6509 final long identity = Binder.clearCallingIdentity();
6510 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006511 int subId = phone.getSubId();
6512 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6513 // A test override is in place for the privileges for this subId, so don't try to
6514 // read the subscription privileges.
6515 return privilegeFromSim;
6516 }
6517 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006518 SubscriptionManager subManager = (SubscriptionManager)
6519 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6520 return subManager.canManageSubscription(subInfo, pkgName)
6521 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
6525 }
6526
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006527 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006528 public int getCarrierPrivilegeStatus(int subId) {
6529 final Phone phone = getPhone(subId);
6530 if (phone == null) {
6531 loge("getCarrierPrivilegeStatus: Invalid subId");
6532 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6533 }
6534 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006535 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006536 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006537 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6538 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006539
6540 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6541 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006542 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006543 }
Junda Liu29340342014-07-10 15:23:27 -07006544
6545 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006546 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006547 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006548 final Phone phone = getPhone(subId);
6549 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006550 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006551 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6552 }
6553 UiccProfile profile =
6554 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6555 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006556 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006557 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6558 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006559 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006560 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006561 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006562 }
6563
6564 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006565 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6566 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006567 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006568 }
6569
6570 int phoneId = SubscriptionManager.getPhoneId(subId);
6571 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006572 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006573 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006574 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6575 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006576 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6577 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6578 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006579 }
6580
6581 @Override
6582 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006583 if (TextUtils.isEmpty(pkgName))
6584 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006585 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6586 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6587 UiccCard card = UiccController.getInstance().getUiccCard(i);
6588 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006589 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006590 continue;
6591 }
6592
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006593 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6594 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6595 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006596 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6597 break;
6598 }
6599 }
6600
6601 return result;
Junda Liu29340342014-07-10 15:23:27 -07006602 }
Derek Tan89e89d42014-07-08 17:00:10 -07006603
6604 @Override
Junda Liue64de782015-04-16 17:19:16 -07006605 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6606 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6607 loge("phoneId " + phoneId + " is not valid.");
6608 return null;
6609 }
6610 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006611 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006612 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006613 return null ;
6614 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006615 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006616 }
6617
Amith Yamasani6e118872016-02-19 12:53:51 -08006618 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006619 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006620 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006621 List<String> privilegedPackages = new ArrayList<>();
6622 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006623 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6624 // has UICC in that slot.
6625 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006626 if (card.hasCarrierPrivilegeRules()) {
6627 if (packages == null) {
6628 // Only check packages in user 0 for now
6629 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006630 PackageManager.MATCH_DISABLED_COMPONENTS
6631 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006632 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006633 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006634 }
6635 for (int p = packages.size() - 1; p >= 0; p--) {
6636 PackageInfo pkgInfo = packages.get(p);
6637 if (pkgInfo != null && pkgInfo.packageName != null
6638 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006639 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006640 privilegedPackages.add(pkgInfo.packageName);
6641 }
6642 }
6643 }
6644 }
6645 return privilegedPackages;
6646 }
6647
chen xuf7e9fe82019-05-09 19:31:02 -07006648 @Override
6649 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006650 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6651
6652 final long identity = Binder.clearCallingIdentity();
6653
chen xuf7e9fe82019-05-09 19:31:02 -07006654 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006655 try {
6656 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6657 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6658 }
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006661 }
6662 return privilegedPackages;
6663 }
6664
Wink Savilleb564aae2014-10-23 10:18:09 -07006665 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006666 final Phone phone = getPhone(subId);
6667 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006668 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006669 return null;
6670 }
6671 String iccId = card.getIccId();
6672 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006673 return null;
6674 }
6675 return iccId;
6676 }
6677
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006678 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006679 public void setCallComposerStatus(int subId, int status) {
6680 enforceModifyPermission();
6681
6682 final long identity = Binder.clearCallingIdentity();
6683 try {
6684 Phone phone = getPhone(subId);
6685 if (phone != null) {
6686 Phone defaultPhone = phone.getImsPhone();
6687 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6688 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6689 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006690 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6691 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006692 }
6693 }
Shuo Qiand8782462020-12-22 19:10:14 -08006694 } catch (ImsException e) {
6695 throw new ServiceSpecificException(e.getCode());
6696 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006697 Binder.restoreCallingIdentity(identity);
6698 }
6699 }
6700
6701 @Override
6702 public int getCallComposerStatus(int subId) {
6703 enforceReadPrivilegedPermission("getCallComposerStatus");
6704
6705 final long identity = Binder.clearCallingIdentity();
6706 try {
6707 Phone phone = getPhone(subId);
6708 if (phone != null) {
6709 Phone defaultPhone = phone.getImsPhone();
6710 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6711 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6712 return imsPhone.getCallComposerStatus();
6713 }
6714 }
6715 } finally {
6716 Binder.restoreCallingIdentity(identity);
6717 }
6718 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6719 }
6720
6721 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006722 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6723 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006724 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006725 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727 final long identity = Binder.clearCallingIdentity();
6728 try {
6729 final String iccId = getIccId(subId);
6730 final Phone phone = getPhone(subId);
6731 if (phone == null) {
6732 return false;
6733 }
6734 final String subscriberId = phone.getSubscriberId();
6735
6736 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006737 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 + subscriberId + " to " + number);
6739 }
6740
6741 if (TextUtils.isEmpty(iccId)) {
6742 return false;
6743 }
6744
6745 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6746
6747 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6748 if (alphaTag == null) {
6749 editor.remove(alphaTagPrefKey);
6750 } else {
6751 editor.putString(alphaTagPrefKey, alphaTag);
6752 }
6753
6754 // Record both the line number and IMSI for this ICCID, since we need to
6755 // track all merged IMSIs based on line number
6756 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6757 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6758 if (number == null) {
6759 editor.remove(numberPrefKey);
6760 editor.remove(subscriberPrefKey);
6761 } else {
6762 editor.putString(numberPrefKey, number);
6763 editor.putString(subscriberPrefKey, subscriberId);
6764 }
6765
6766 editor.commit();
6767 return true;
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006770 }
Derek Tan7226c842014-07-02 17:42:23 -07006771 }
6772
6773 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006774 public String getLine1NumberForDisplay(int subId, String callingPackage,
6775 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006776 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006777 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006778 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006779 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006780 return null;
6781 }
Derek Tan97ebb422014-09-05 16:55:38 -07006782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783 final long identity = Binder.clearCallingIdentity();
6784 try {
6785 String iccId = getIccId(subId);
6786 if (iccId != null) {
6787 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6788 if (DBG_MERGE) {
6789 log("getLine1NumberForDisplay returning "
6790 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6791 }
6792 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6795 return null;
6796 } finally {
6797 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006798 }
Derek Tan7226c842014-07-02 17:42:23 -07006799 }
6800
6801 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006802 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6803 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006804 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006805 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006806 return null;
6807 }
Derek Tan97ebb422014-09-05 16:55:38 -07006808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 final long identity = Binder.clearCallingIdentity();
6810 try {
6811 String iccId = getIccId(subId);
6812 if (iccId != null) {
6813 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6814 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6815 }
6816 return null;
6817 } finally {
6818 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006819 }
Derek Tan7226c842014-07-02 17:42:23 -07006820 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006821
6822 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006823 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6824 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006825 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6826 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006828 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006829 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006830 return null;
6831 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006832
Jordan Liub49b04b2019-05-06 14:45:15 -07006833 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6834 // the process, where TelephonyManager was instantiated.
6835 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006836 final long identity = Binder.clearCallingIdentity();
6837 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006838 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006839 final TelephonyManager tele = TelephonyManager.from(context);
6840 final SubscriptionManager sub = SubscriptionManager.from(context);
6841
6842 // Figure out what subscribers are currently active
6843 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844
Jordan Liub49b04b2019-05-06 14:45:15 -07006845 // Only consider subs which match the current subId
6846 // This logic can be simplified. See b/131189269 for progress.
6847 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006848 activeSubscriberIds.add(tele.getSubscriberId(subId));
6849 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006850
6851 // First pass, find a number override for an active subscriber
6852 String mergeNumber = null;
6853 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6854 for (String key : prefs.keySet()) {
6855 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6856 final String subscriberId = (String) prefs.get(key);
6857 if (activeSubscriberIds.contains(subscriberId)) {
6858 final String iccId = key.substring(
6859 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6860 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6861 mergeNumber = (String) prefs.get(numberKey);
6862 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006863 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006864 + " for active subscriber " + subscriberId);
6865 }
6866 if (!TextUtils.isEmpty(mergeNumber)) {
6867 break;
6868 }
6869 }
6870 }
6871 }
6872
6873 // Shortcut when no active merged subscribers
6874 if (TextUtils.isEmpty(mergeNumber)) {
6875 return null;
6876 }
6877
6878 // Second pass, find all subscribers under that line override
6879 final ArraySet<String> result = new ArraySet<>();
6880 for (String key : prefs.keySet()) {
6881 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6882 final String number = (String) prefs.get(key);
6883 if (mergeNumber.equals(number)) {
6884 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6885 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6886 final String subscriberId = (String) prefs.get(subscriberKey);
6887 if (!TextUtils.isEmpty(subscriberId)) {
6888 result.add(subscriberId);
6889 }
6890 }
6891 }
6892 }
6893
6894 final String[] resultArray = result.toArray(new String[result.size()]);
6895 Arrays.sort(resultArray);
6896 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006897 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6899 }
6900 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006901 } finally {
6902 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006903 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006904 }
6905
6906 @Override
zoey chen38003472019-12-13 17:16:31 +08006907 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6908 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006909
6910 final long identity = Binder.clearCallingIdentity();
6911 try {
6912 final TelephonyManager telephonyManager = mApp.getSystemService(
6913 TelephonyManager.class);
6914 String subscriberId = telephonyManager.getSubscriberId(subId);
6915 if (subscriberId == null) {
6916 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006917 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006918 + subId);
6919 }
6920 return null;
6921 }
6922
6923 final SubscriptionInfo info = SubscriptionController.getInstance()
6924 .getSubscriptionInfo(subId);
6925 final ParcelUuid groupUuid = info.getGroupUuid();
6926 // If it doesn't belong to any group, return just subscriberId of itself.
6927 if (groupUuid == null) {
6928 return new String[]{subscriberId};
6929 }
6930
6931 // Get all subscriberIds from the group.
6932 final List<String> mergedSubscriberIds = new ArrayList<>();
6933 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006934 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006935 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006936 for (SubscriptionInfo subInfo : groupInfos) {
6937 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6938 if (subscriberId != null) {
6939 mergedSubscriberIds.add(subscriberId);
6940 }
6941 }
6942
6943 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6944 } finally {
6945 Binder.restoreCallingIdentity(identity);
6946
6947 }
6948 }
6949
6950 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006951 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006952 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006953 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954
6955 final long identity = Binder.clearCallingIdentity();
6956 try {
6957 final Phone phone = getPhone(subId);
6958 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6959 } finally {
6960 Binder.restoreCallingIdentity(identity);
6961 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006962 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006963
6964 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006965 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006966 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6967 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006968 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6969 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970
6971 final long identity = Binder.clearCallingIdentity();
6972 try {
6973 final Phone phone = getPhone(subId);
6974 if (phone == null) {
6975 return false;
6976 }
6977 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6978 cdmaNonRoamingList);
6979 } finally {
6980 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006981 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006982 }
6983
6984 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006985 @Deprecated
6986 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6987 enforceModifyPermission();
6988
6989 int returnValue = 0;
6990 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006991 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006992 if(result.exception == null) {
6993 if (result.result != null) {
6994 byte[] responseData = (byte[])(result.result);
6995 if(responseData.length > oemResp.length) {
6996 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6997 responseData.length + "bytes. Buffer Size is " +
6998 oemResp.length + "bytes.");
6999 }
7000 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7001 returnValue = responseData.length;
7002 }
7003 } else {
7004 CommandException ex = (CommandException) result.exception;
7005 returnValue = ex.getCommandError().ordinal();
7006 if(returnValue > 0) returnValue *= -1;
7007 }
7008 } catch (RuntimeException e) {
7009 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7010 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7011 if(returnValue > 0) returnValue *= -1;
7012 }
7013
7014 return returnValue;
7015 }
7016
7017 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07007018 public void setRadioCapability(RadioAccessFamily[] rafs) {
7019 try {
7020 ProxyController.getInstance().setRadioCapability(rafs);
7021 } catch (RuntimeException e) {
7022 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
7023 }
7024 }
7025
7026 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007027 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007028 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007029 try {
7030 TelephonyPermissions
7031 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7032 mApp, phone.getSubId(), "getRadioAccessFamily");
7033 } catch (SecurityException e) {
7034 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7035 throw e;
7036 }
chen xub97461a2018-10-26 14:17:57 -07007037 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007038 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007039 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 final long identity = Binder.clearCallingIdentity();
7042 try {
chen xub97461a2018-10-26 14:17:57 -07007043 TelephonyPermissions
7044 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7045 mApp, phone.getSubId(), "getRadioAccessFamily");
7046 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047 } finally {
7048 Binder.restoreCallingIdentity(identity);
7049 }
chen xub97461a2018-10-26 14:17:57 -07007050 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007051 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007052
7053 @Override
7054 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007055 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007056 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057
7058 final long identity = Binder.clearCallingIdentity();
7059 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007060 ImsManager.getInstance(defaultPhone.getContext(),
7061 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 } finally {
7063 Binder.restoreCallingIdentity(identity);
7064 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007065 }
7066
7067 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007068 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007069 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7071 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007072 return false;
7073 }
Svet Ganovb320e182015-04-16 12:30:10 -07007074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 final long identity = Binder.clearCallingIdentity();
7076 try {
7077 // Check the user preference and the system-level IMS setting. Even if the user has
7078 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7079 // In the long run, we may instead need to check if there exists a connection service
7080 // which can support video calling.
7081 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007082 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083 return imsManager.isVtEnabledByPlatform()
7084 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7085 && imsManager.isVtEnabledByUser();
7086 } finally {
7087 Binder.restoreCallingIdentity(identity);
7088 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007089 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007090
Andrew Leea1239f22015-03-02 17:44:07 -08007091 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007092 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7093 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007095 mApp, subId, callingPackage, callingFeatureId,
7096 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 return false;
7098 }
7099
7100 final long identity = Binder.clearCallingIdentity();
7101 try {
7102 CarrierConfigManager configManager =
7103 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007104 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7106 } finally {
7107 Binder.restoreCallingIdentity(identity);
7108 }
Andrew Leea1239f22015-03-02 17:44:07 -08007109 }
7110
7111 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007112 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007114 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007115 return false;
7116 }
7117
7118 final long identity = Binder.clearCallingIdentity();
7119 try {
7120 CarrierConfigManager configManager =
7121 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007122 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7124 } finally {
7125 Binder.restoreCallingIdentity(identity);
7126 }
Andrew Leea1239f22015-03-02 17:44:07 -08007127 }
7128
Andrew Lee9431b832015-03-09 18:46:45 -07007129 @Override
7130 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007131 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007132 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007133 }
7134
7135 @Override
7136 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 final long identity = Binder.clearCallingIdentity();
7138 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007139 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 } finally {
7141 Binder.restoreCallingIdentity(identity);
7142 }
Andrew Lee9431b832015-03-09 18:46:45 -07007143 }
7144
Hall Liuf6668912018-10-31 17:05:23 -07007145 /**
7146 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7147 * support for the feature and device firmware support.
7148 *
7149 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7150 */
7151 @Override
7152 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007154 final Phone phone = getPhone(subscriptionId);
7155 if (phone == null) {
7156 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7157 return false;
7158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007160 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7162 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007163 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164 return isCarrierSupported && isDeviceSupported;
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167 }
Hall Liu98187582018-01-22 19:15:32 -08007168 }
7169
Hall Liuf6668912018-10-31 17:05:23 -07007170 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007171 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7172 * RTT setting, will return true if the device and carrier both support RTT.
7173 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007174 */
7175 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176 final long identity = Binder.clearCallingIdentity();
7177 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007178 boolean isRttSupported = isRttSupported(subscriptionId);
7179 boolean isUserRttSettingOn = Settings.Secure.getInt(
7180 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7181 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7182 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7183 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007187 }
7188
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007189 @Deprecated
7190 @Override
7191 public String getDeviceId(String callingPackage) {
7192 return getDeviceIdWithFeature(callingPackage, null);
7193 }
7194
Sanket Padawe7310cc72015-01-14 09:53:20 -08007195 /**
7196 * Returns the unique device ID of phone, for example, the IMEI for
7197 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7198 *
7199 * <p>Requires Permission:
7200 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7201 */
7202 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007203 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007204 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007205 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007206 return null;
7207 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007208 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007209 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007210 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007211 return null;
7212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007213
7214 final long identity = Binder.clearCallingIdentity();
7215 try {
7216 return phone.getDeviceId();
7217 } finally {
7218 Binder.restoreCallingIdentity(identity);
7219 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007220 }
7221
Ping Sunc67b7c22016-03-02 19:16:45 +08007222 /**
7223 * {@hide}
7224 * Returns the IMS Registration Status on a particular subid
7225 *
7226 * @param subId
7227 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007228 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007229 Phone phone = getPhone(subId);
7230 if (phone != null) {
7231 return phone.isImsRegistered();
7232 } else {
7233 return false;
7234 }
7235 }
7236
Santos Cordon7a1885b2015-02-03 11:15:19 -08007237 @Override
7238 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 final long identity = Binder.clearCallingIdentity();
7240 try {
7241 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7242 } finally {
7243 Binder.restoreCallingIdentity(identity);
7244 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007245 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007246
Tyler Gunnf70ed162019-04-03 15:28:53 -07007247 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007248 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007249 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007250 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007251 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007252 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7253 }
7254 final long identity = Binder.clearCallingIdentity();
7255 try {
7256 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7257 } finally {
7258 Binder.restoreCallingIdentity(identity);
7259 }
7260 }
7261
7262 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007263 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007264 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7265 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007266 final long identity = Binder.clearCallingIdentity();
7267 try {
7268 Phone phone = getPhone(subscriptionId);
7269 if (phone == null) {
7270 return null;
7271 }
7272 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7273 } finally {
7274 Binder.restoreCallingIdentity(identity);
7275 }
7276 }
7277
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007278 /**
7279 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007280 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007281 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 final long identity = Binder.clearCallingIdentity();
7283 try {
7284 Phone phone = getPhone(subId);
7285 if (phone != null) {
7286 return phone.isWifiCallingEnabled();
7287 } else {
7288 return false;
7289 }
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007292 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007293 }
7294
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007295 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007296 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007297 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007298 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007299 final long identity = Binder.clearCallingIdentity();
7300 try {
7301 Phone phone = getPhone(subId);
7302 if (phone != null) {
7303 return phone.isVideoEnabled();
7304 } else {
7305 return false;
7306 }
7307 } finally {
7308 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007309 }
7310 }
7311
7312 /**
7313 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7314 * defined in {@link ImsRegistrationImplBase}.
7315 */
7316 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317 final long identity = Binder.clearCallingIdentity();
7318 try {
7319 Phone phone = getPhone(subId);
7320 if (phone != null) {
7321 return phone.getImsRegistrationTech();
7322 } else {
7323 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7324 }
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007327 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007328 }
7329
Stuart Scott8eef64f2015-04-08 15:13:54 -07007330 @Override
7331 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007332 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007333 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7334 return;
7335 }
7336
Svet Ganovcc087f82015-05-12 20:35:54 -07007337 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007338
Svet Ganovcc087f82015-05-12 20:35:54 -07007339 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007340 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7341 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007342 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007343 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007344 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007345 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007346 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7347 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007348 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007349 // There has been issues when Sms raw table somehow stores orphan
7350 // fragments. They lead to garbled message when new fragments come
7351 // in and combined with those stale ones. In case this happens again,
7352 // user can reset all network settings which will clean up this table.
7353 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007354 // Clean up IMS settings as well here.
7355 int slotId = getSlotIndex(subId);
7356 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7357 ImsManager.getInstance(mApp, slotId).factoryReset();
7358 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007359
7360 // Erase modem config if erase modem on network setting is enabled.
7361 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7362 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7363 if (configValue != null && Boolean.parseBoolean(configValue)) {
7364 sendEraseModemConfig(getDefaultPhone());
7365 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007366 } finally {
7367 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007368 }
7369 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007370
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007371 private void cleanUpSmsRawTable(Context context) {
7372 ContentResolver resolver = context.getContentResolver();
7373 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7374 resolver.delete(uri, null, null);
7375 }
7376
Narayan Kamath1c496c22015-04-16 14:40:19 +01007377 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007378 public String getSimLocaleForSubscriber(int subId) {
7379 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7380 final Phone phone = getPhone(subId);
7381 if (phone == null) {
7382 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007383 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007384 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 final long identity = Binder.clearCallingIdentity();
7386 try {
chen xu5d3637b2019-01-21 23:31:38 -08007387 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007388 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007389 if (info == null) {
7390 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7391 return null;
7392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393 // Try and fetch the locale from the carrier properties or from the SIM language
7394 // preferences (EF-PL and EF-LI)...
7395 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007397 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7398 if (localeFromDefaultSim != null) {
7399 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7400 if (DBG) log("Using locale from subId: " + subId + " locale: "
7401 + localeFromDefaultSim);
7402 return localeFromDefaultSim.toLanguageTag();
7403 } else {
7404 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 }
7406 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007408 // The SIM language preferences only store a language (e.g. fr = French), not an
7409 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7410 // the SIM and carrier preferences does not include a country we add the country
7411 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007412 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007414 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 return mccLocale.toLanguageTag();
7416 }
7417
7418 if (DBG) log("No locale found - returning null");
7419 return null;
7420 } finally {
7421 Binder.restoreCallingIdentity(identity);
7422 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007423 }
7424
7425 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007426 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007427 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007428 }
7429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430 /**
7431 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7432 */
7433 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007434 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007435 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007436 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007437
Chenjie Yu1ba97252018-01-11 18:16:20 -08007438 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007439 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007440
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007441 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007442 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7443 * representing the state of the modem.
7444 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007445 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7446 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007447 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007448 */
7449 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007450 public void requestModemActivityInfo(ResultReceiver result) {
7451 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007452 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453
7454 final long identity = Binder.clearCallingIdentity();
7455 try {
sqian1a1be542020-03-05 11:37:28 -08007456 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 } finally {
7458 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007459 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007460 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007461
Siddharth Rayb8114062018-06-17 15:02:38 -07007462 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7463 // less than total activity duration.
7464 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7465 if (info == null) {
7466 return false;
7467 }
7468 int activityDurationMs =
7469 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7470 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007471 int[] txTimeMs = info.getTransmitTimeMillis();
7472 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7473 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007474 }
7475 return (info.isValid()
7476 && (info.getSleepTimeMillis() <= activityDurationMs)
7477 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007478 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007479 && (totalTxTimeMs <= activityDurationMs));
7480 }
7481
Jack Yu85bd38a2015-11-09 11:34:32 -08007482 /**
7483 * {@hide}
7484 * Returns the service state information on specified subscription.
7485 */
7486 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007487 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7488 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007490 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007491 return null;
7492 }
7493
Hall Liuf19c44f2018-11-27 14:38:17 -08007494 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7495 LocationAccessPolicy.checkLocationPermission(mApp,
7496 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7497 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007498 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007499 .setCallingPid(Binder.getCallingPid())
7500 .setCallingUid(Binder.getCallingUid())
7501 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007502 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007503 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7504 .build());
7505
7506 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7507 LocationAccessPolicy.checkLocationPermission(mApp,
7508 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7509 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007510 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007511 .setCallingPid(Binder.getCallingPid())
7512 .setCallingUid(Binder.getCallingUid())
7513 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007514 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007515 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7516 .build());
7517 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7518 boolean hasFinePermission =
7519 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7520 boolean hasCoarsePermission =
7521 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 final long identity = Binder.clearCallingIdentity();
7524 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007525 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7526 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7527 Rlog.d(LOG_TAG,
7528 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7529 return null;
7530 }
7531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 final Phone phone = getPhone(subId);
7533 if (phone == null) {
7534 return null;
7535 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007536
Hall Liuf19c44f2018-11-27 14:38:17 -08007537 ServiceState ss = phone.getServiceState();
7538
7539 // Scrub out the location info in ServiceState depending on what level of access
7540 // the caller has.
7541 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007542 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7543 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007547 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007548
7549 /**
7550 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7551 *
7552 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7553 * voicemail ringtone.
7554 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7555 * PhoneAccount.
7556 */
7557 @Override
7558 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007559 final long identity = Binder.clearCallingIdentity();
7560 try {
7561 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7562 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007563 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007570 }
7571
7572 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007573 * Sets the per-account voicemail ringtone.
7574 *
7575 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7576 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7577 *
7578 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7579 * voicemail ringtone.
7580 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7581 * PhoneAccount.
7582 */
7583 @Override
7584 public void setVoicemailRingtoneUri(String callingPackage,
7585 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007586 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007588 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7589 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7591 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7592 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007594
7595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7598 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007599 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 }
7601 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7602 } finally {
7603 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007604 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007605 }
7606
7607 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007608 * Returns whether vibration is set for voicemail notification in Phone settings.
7609 *
7610 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7611 * voicemail vibration setting.
7612 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7613 */
7614 @Override
7615 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007616 final long identity = Binder.clearCallingIdentity();
7617 try {
7618 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7619 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007620 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7624 } finally {
7625 Binder.restoreCallingIdentity(identity);
7626 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007627 }
7628
Youhan Wange64578a2016-05-02 15:32:42 -07007629 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007630 * Sets the per-account voicemail vibration.
7631 *
7632 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7633 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7634 *
7635 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7636 * voicemail vibration setting.
7637 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7638 * specific PhoneAccount.
7639 */
7640 @Override
7641 public void setVoicemailVibrationEnabled(String callingPackage,
7642 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007643 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007644 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007645 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7646 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7648 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7649 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007650 }
7651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7655 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007656 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 }
7658 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7659 } finally {
7660 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007661 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007662 }
7663
7664 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007665 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7666 *
7667 * @throws SecurityException if the caller does not have the required permission
7668 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007669 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007670 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007671 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007672 }
7673
7674 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007675 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7676 * permission.
7677 *
7678 * @throws SecurityException if the caller does not have the required permission
7679 */
7680 private void enforceSendSmsPermission() {
7681 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7682 }
7683
7684 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007685 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007686 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007687 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007688 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007689 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007690 final long identity = Binder.clearCallingIdentity();
7691 try {
7692 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007693 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 if (componentName == null) {
7695 throw new SecurityException(
7696 "Caller not current active visual voicemail package[null]");
7697 }
7698 String vvmPackage = componentName.getPackageName();
7699 if (!callingPackage.equals(vvmPackage)) {
7700 throw new SecurityException("Caller not current active visual voicemail package["
7701 + vvmPackage + "]");
7702 }
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007705 }
7706 }
7707
7708 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007709 * Return the application ID for the app type.
7710 *
7711 * @param subId the subscription ID that this request applies to.
7712 * @param appType the uicc app type.
7713 * @return Application ID for specificied app type, or null if no uicc.
7714 */
7715 @Override
7716 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007717 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007718 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719
7720 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007721 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 if (phone == null) {
7723 return null;
7724 }
7725 String aid = null;
7726 try {
7727 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7728 .getApplicationByType(appType).getAid();
7729 } catch (Exception e) {
7730 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7731 }
7732 return aid;
7733 } finally {
7734 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007735 }
Youhan Wange64578a2016-05-02 15:32:42 -07007736 }
7737
Youhan Wang4001d252016-05-11 10:29:41 -07007738 /**
7739 * Return the Electronic Serial Number.
7740 *
7741 * @param subId the subscription ID that this request applies to.
7742 * @return ESN or null if error.
7743 */
7744 @Override
7745 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007746 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007747 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748
7749 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007750 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007751 if (phone == null) {
7752 return null;
7753 }
7754 String esn = null;
7755 try {
7756 esn = phone.getEsn();
7757 } catch (Exception e) {
7758 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7759 }
7760 return esn;
7761 } finally {
7762 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007763 }
Youhan Wang4001d252016-05-11 10:29:41 -07007764 }
7765
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007766 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007767 * Return the Preferred Roaming List Version.
7768 *
7769 * @param subId the subscription ID that this request applies to.
7770 * @return PRLVersion or null if error.
7771 */
7772 @Override
7773 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007774 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007775 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776
7777 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007778 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 if (phone == null) {
7780 return null;
7781 }
7782 String cdmaPrlVersion = null;
7783 try {
7784 cdmaPrlVersion = phone.getCdmaPrlVersion();
7785 } catch (Exception e) {
7786 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7787 }
7788 return cdmaPrlVersion;
7789 } finally {
7790 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007791 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007792 }
7793
7794 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007795 * Get snapshot of Telephony histograms
7796 * @return List of Telephony histograms
7797 * @hide
7798 */
7799 @Override
7800 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7802 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803
7804 final long identity = Binder.clearCallingIdentity();
7805 try {
7806 return RIL.getTelephonyRILTimingHistograms();
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
7809 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007810 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007811
7812 /**
7813 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007814 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7815 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007816 * Require system privileges. In the future we may add this to carrier APIs.
7817 *
Michele Berionne482f8202018-11-27 18:57:59 -08007818 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007819 */
7820 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007821 @TelephonyManager.SetCarrierRestrictionResult
7822 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007823 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007824 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007825
Michele Berionne482f8202018-11-27 18:57:59 -08007826 if (carrierRestrictionRules == null) {
7827 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007828 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007829
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830 final long identity = Binder.clearCallingIdentity();
7831 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007832 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007833 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834 } finally {
7835 Binder.restoreCallingIdentity(identity);
7836 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007837 }
7838
7839 /**
7840 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007841 * Get the allowed carrier list and the excluded carrier list, including the priority between
7842 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007843 * Require system privileges. In the future we may add this to carrier APIs.
7844 *
Michele Berionne482f8202018-11-27 18:57:59 -08007845 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007846 */
7847 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007848 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007849 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007850 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851
7852 final long identity = Binder.clearCallingIdentity();
7853 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007854 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7855 if (response instanceof CarrierRestrictionRules) {
7856 return (CarrierRestrictionRules) response;
7857 }
7858 // Response is an Exception of some kind,
7859 // which is signalled to the user as a NULL retval
7860 return null;
7861 } catch (Exception e) {
7862 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7863 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 } finally {
7865 Binder.restoreCallingIdentity(identity);
7866 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007867 }
7868
fionaxu59545b42016-05-25 15:53:37 -07007869 /**
fionaxu59545b42016-05-25 15:53:37 -07007870 * Action set from carrier signalling broadcast receivers to enable/disable radio
7871 * @param subId the subscription ID that this action applies to.
7872 * @param enabled control enable or disable radio.
7873 * {@hide}
7874 */
7875 @Override
7876 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7877 enforceModifyPermission();
7878 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007879
7880 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007881 if (phone == null) {
7882 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7883 return;
7884 }
7885 try {
7886 phone.carrierActionSetRadioEnabled(enabled);
7887 } catch (Exception e) {
7888 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007889 } finally {
7890 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007891 }
7892 }
7893
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007894 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007895 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7896 * network status based on which carrier apps could apply actions accordingly,
7897 * enable/disable default url handler for example.
7898 *
7899 * @param subId the subscription ID that this action applies to.
7900 * @param report control start/stop reporting the default network status.
7901 * {@hide}
7902 */
7903 @Override
7904 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7905 enforceModifyPermission();
7906 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907
7908 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007909 if (phone == null) {
7910 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7911 return;
7912 }
7913 try {
7914 phone.carrierActionReportDefaultNetworkStatus(report);
7915 } catch (Exception e) {
7916 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917 } finally {
7918 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007919 }
7920 }
7921
7922 /**
fionaxud9622282017-07-17 17:51:30 -07007923 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7924 * @param subId the subscription ID that this action applies to.
7925 * {@hide}
7926 */
7927 @Override
7928 public void carrierActionResetAll(int subId) {
7929 enforceModifyPermission();
7930 final Phone phone = getPhone(subId);
7931 if (phone == null) {
7932 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7933 return;
7934 }
7935 try {
7936 phone.carrierActionResetAll();
7937 } catch (Exception e) {
7938 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7939 }
7940 }
7941
7942 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007943 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7944 * bug report is being generated.
7945 */
7946 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007947 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007948 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7949 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007950 writer.println("Permission Denial: can't dump Phone from pid="
7951 + Binder.getCallingPid()
7952 + ", uid=" + Binder.getCallingUid()
7953 + "without permission "
7954 + android.Manifest.permission.DUMP);
7955 return;
7956 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007957 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007958 }
Jack Yueb89b242016-06-22 13:27:47 -07007959
Brad Ebingerdac2f002018-04-03 15:17:52 -07007960 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007961 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7962 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7963 @NonNull String[] args) {
7964 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7965 this, in.getFileDescriptor(), out.getFileDescriptor(),
7966 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007967 }
7968
Jack Yueb89b242016-06-22 13:27:47 -07007969 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007970 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007971 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007972 * @param reason the reason the data enable change is taking place
7973 * @param enabled True if enabling the data, otherwise disabling.
7974 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007975 */
7976 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007977 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007978 boolean enabled) {
7979 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7980 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7981 try {
7982 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007983 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007984 } catch (SecurityException se) {
7985 enforceModifyPermission();
7986 }
7987 } else {
7988 enforceModifyPermission();
7989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990
7991 final long identity = Binder.clearCallingIdentity();
7992 try {
7993 Phone phone = getPhone(subId);
7994 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007995 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7996 phone.carrierActionSetMeteredApnsEnabled(enabled);
7997 } else {
7998 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008000 }
8001 } finally {
8002 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008003 }
8004 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008005
8006 /**
8007 * Get Client request stats
8008 * @return List of Client Request Stats
8009 * @hide
8010 */
8011 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008012 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8013 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008015 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008016 return null;
8017 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008018 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 final long identity = Binder.clearCallingIdentity();
8021 try {
8022 if (phone != null) {
8023 return phone.getClientRequestStats();
8024 }
8025
8026 return null;
8027 } finally {
8028 Binder.restoreCallingIdentity(identity);
8029 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008030 }
8031
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008032 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008033 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008034 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008035 }
Jack Yueb4124c2017-02-16 15:32:43 -08008036
8037 /**
Grace Chen70990072017-03-24 17:21:30 -07008038 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008039 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008040 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008041 * @param state State of SIM (power down, power up, pass through)
8042 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8043 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8044 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008045 *
8046 **/
8047 @Override
Grace Chen70990072017-03-24 17:21:30 -07008048 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008049 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008050 Phone phone = PhoneFactory.getPhone(slotIndex);
8051
vagdeviaf9a5b92018-08-15 16:01:53 -07008052 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008057 phone.setSimPowerState(state, null, workSource);
8058 }
8059 } finally {
8060 Binder.restoreCallingIdentity(identity);
8061 }
8062 }
8063
8064 /**
8065 * Set SIM card power state.
8066 *
8067 * @param slotIndex SIM slot id.
8068 * @param state State of SIM (power down, power up, pass through)
8069 * @param callback callback to trigger after success or failure
8070 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8071 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8072 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8073 *
8074 **/
8075 @Override
8076 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8077 IIntegerConsumer callback) {
8078 enforceModifyPermission();
8079 Phone phone = PhoneFactory.getPhone(slotIndex);
8080
8081 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8082
8083 final long identity = Binder.clearCallingIdentity();
8084 try {
8085 if (phone != null) {
8086 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8087 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088 }
8089 } finally {
8090 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008091 }
8092 }
Shuo Qiandd210312017-04-12 22:11:33 +00008093
Tyler Gunn65d45c22017-06-05 11:22:26 -07008094 private boolean isUssdApiAllowed(int subId) {
8095 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008096 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008097 if (configManager == null) {
8098 return false;
8099 }
8100 PersistableBundle pb = configManager.getConfigForSubId(subId);
8101 if (pb == null) {
8102 return false;
8103 }
8104 return pb.getBoolean(
8105 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8106 }
8107
Shuo Qiandd210312017-04-12 22:11:33 +00008108 /**
8109 * Check if phone is in emergency callback mode
8110 * @return true if phone is in emergency callback mode
8111 * @param subId sub id
8112 */
goneil9c5f4872017-12-05 14:07:56 -08008113 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008114 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008115 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008116 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117
8118 final long identity = Binder.clearCallingIdentity();
8119 try {
8120 if (phone != null) {
8121 return phone.isInEcm();
8122 } else {
8123 return false;
8124 }
8125 } finally {
8126 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008127 }
8128 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008129
8130 /**
8131 * Get the current signal strength information for the given subscription.
8132 * Because this information is not updated when the device is in a low power state
8133 * it should not be relied-upon to be current.
8134 * @param subId Subscription index
8135 * @return the most recent cached signal strength info from the modem
8136 */
8137 @Override
8138 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 final long identity = Binder.clearCallingIdentity();
8140 try {
8141 Phone p = getPhone(subId);
8142 if (p == null) {
8143 return null;
8144 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008146 return p.getSignalStrength();
8147 } finally {
8148 Binder.restoreCallingIdentity(identity);
8149 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008150 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008151
Pengquan Meng77b7f132018-08-22 14:49:57 -07008152 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008153 * Get the current modem radio state for the given slot.
8154 * @param slotIndex slot index.
8155 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008156 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008157 * @return the current radio power state from the modem
8158 */
8159 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008160 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008161 Phone phone = PhoneFactory.getPhone(slotIndex);
8162 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008163 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8164 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008165 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8166 }
8167
8168 final long identity = Binder.clearCallingIdentity();
8169 try {
8170 return phone.getRadioPowerState();
8171 } finally {
8172 Binder.restoreCallingIdentity(identity);
8173 }
8174 }
8175 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8176 }
8177
8178 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008179 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8180 *
8181 * <p>Requires one of the following permissions:
8182 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8183 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8184 * privileges.
8185 *
8186 * @param subId subscription id
8187 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8188 * {@code false}.
8189 */
8190 @Override
8191 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008192 try {
8193 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8194 null);
8195 } catch (Exception e) {
8196 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8197 mApp, subId, "isDataRoamingEnabled");
8198 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008199
Pengquan Menga1bb6272018-09-06 09:59:22 -07008200 boolean isEnabled = false;
8201 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008202 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008203 Phone phone = getPhone(subId);
8204 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008205 } finally {
8206 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008207 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008208 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008209 }
8210
8211
8212 /**
8213 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8214 *
8215 * <p> Requires permission:
8216 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8217 * privileges.
8218 *
8219 * @param subId subscription id
8220 * @param isEnabled {@code true} means enable, {@code false} means disable.
8221 */
8222 @Override
8223 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8225 mApp, subId, "setDataRoamingEnabled");
8226
Pengquan Menga1bb6272018-09-06 09:59:22 -07008227 final long identity = Binder.clearCallingIdentity();
8228 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008229 Phone phone = getPhone(subId);
8230 if (phone != null) {
8231 phone.setDataRoamingEnabled(isEnabled);
8232 }
8233 } finally {
8234 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008235 }
8236 }
8237
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008238 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008239 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008240 TelephonyPermissions
8241 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008242 mApp, subId, "isManualNetworkSelectionAllowed");
8243
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008244 boolean isAllowed = true;
8245 final long identity = Binder.clearCallingIdentity();
8246 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008247 Phone phone = getPhone(subId);
8248 if (phone != null) {
8249 isAllowed = phone.isCspPlmnEnabled();
8250 }
8251 } finally {
8252 Binder.restoreCallingIdentity(identity);
8253 }
8254 return isAllowed;
8255 }
8256
8257 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008258 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008259 // Verify that tha callingPackage belongs to the calling UID
8260 mApp.getSystemService(AppOpsManager.class)
8261 .checkPackage(Binder.getCallingUid(), callingPackage);
8262
Jordan Liu1e142fc2019-04-22 15:10:43 -07008263 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008264 try {
8265 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008266 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008267 } catch (SecurityException e) {
8268 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8269 // has carrier privileges on an active UICC
8270 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8271 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008272 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008273 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008274 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008275
8276 final long identity = Binder.clearCallingIdentity();
8277 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008278 UiccController uiccController = UiccController.getInstance();
8279 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008280 if (hasReadPermission) {
8281 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008282 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008283
8284 // Remove private info if the caller doesn't have access
8285 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8286 for (UiccCardInfo cardInfo : cardInfos) {
8287 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8288 // is available
8289 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8290 if (card == null || card.getUiccProfile() == null) {
8291 // assume no access if the card or profile is unavailable
8292 filteredInfos.add(cardInfo.getUnprivileged());
8293 continue;
8294 }
8295 UiccProfile profile = card.getUiccProfile();
8296 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8297 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8298 filteredInfos.add(cardInfo);
8299 } else {
8300 filteredInfos.add(cardInfo.getUnprivileged());
8301 }
8302 }
8303 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008304 } finally {
8305 Binder.restoreCallingIdentity(identity);
8306 }
8307 }
8308
8309 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008310 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008311 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008313 final long identity = Binder.clearCallingIdentity();
8314 try {
8315 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8316 if (slots == null) {
8317 Rlog.i(LOG_TAG, "slots is null.");
8318 return null;
8319 }
8320
8321 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8322 for (int i = 0; i < slots.length; i++) {
8323 UiccSlot slot = slots[i];
8324 if (slot == null) {
8325 continue;
8326 }
8327
Jordan Liu7be7e652019-05-06 18:55:02 +00008328 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 UiccCard card = slot.getUiccCard();
8330 if (card != null) {
8331 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008332 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008333 cardId = slot.getEid();
8334 if (TextUtils.isEmpty(cardId)) {
8335 cardId = slot.getIccId();
8336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008337 }
8338
Jordan Liu857451f2019-05-09 16:35:35 -07008339 if (cardId != null) {
8340 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8341 // if cardId is an EID, it's all digits so this is fine
8342 cardId = IccUtils.stripTrailingFs(cardId);
8343 }
8344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008345 int cardState = 0;
8346 switch (slot.getCardState()) {
8347 case CARDSTATE_ABSENT:
8348 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8349 break;
8350 case CARDSTATE_PRESENT:
8351 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8352 break;
8353 case CARDSTATE_ERROR:
8354 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8355 break;
8356 case CARDSTATE_RESTRICTED:
8357 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8358 break;
8359 default:
8360 break;
8361
8362 }
8363
8364 infos[i] = new UiccSlotInfo(
8365 slot.isActive(),
8366 slot.isEuicc(),
8367 cardId,
8368 cardState,
8369 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008370 slot.isExtendedApduSupported(),
8371 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 }
8373 return infos;
8374 } finally {
8375 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008376 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008377 }
8378
8379 @Override
8380 public boolean switchSlots(int[] physicalSlots) {
8381 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008382
8383 final long identity = Binder.clearCallingIdentity();
8384 try {
8385 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8386 } finally {
8387 Binder.restoreCallingIdentity(identity);
8388 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008389 }
Jack Yu4c988042018-02-27 15:30:01 -08008390
8391 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008392 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008393 final long identity = Binder.clearCallingIdentity();
8394 try {
8395 return UiccController.getInstance().getCardIdForDefaultEuicc();
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
8398 }
8399 }
8400
Pengquan Meng85728fb2018-03-12 16:31:21 -07008401 /**
goneil47ffb6e2018-04-06 15:40:58 -07008402 * A test API to reload the UICC profile.
8403 *
8404 * <p>Requires that the calling app has permission
8405 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8406 * @hide
8407 */
8408 @Override
8409 public void refreshUiccProfile(int subId) {
8410 enforceModifyPermission();
8411
8412 final long identity = Binder.clearCallingIdentity();
8413 try {
8414 Phone phone = getPhone(subId);
8415 if (phone == null) {
8416 return;
8417 }
8418 UiccCard uiccCard = phone.getUiccCard();
8419 if (uiccCard == null) {
8420 return;
8421 }
8422 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8423 if (uiccProfile == null) {
8424 return;
8425 }
8426 uiccProfile.refresh();
8427 } finally {
8428 Binder.restoreCallingIdentity(identity);
8429 }
8430 }
8431
8432 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008433 * Returns false if the mobile data is disabled by default, otherwise return true.
8434 */
8435 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008436 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008437 }
8438
8439 /**
8440 * Returns true if the data roaming is enabled by default, i.e the system property
8441 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8442 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8443 */
8444 private boolean getDefaultDataRoamingEnabled(int subId) {
8445 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008446 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008447 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008448 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8449 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8450 return isDataRoamingEnabled;
8451 }
8452
8453 /**
8454 * Returns the default network type for the given {@code subId}, if the default network type is
8455 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8456 */
8457 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008458 List<Integer> list = TelephonyProperties.default_network();
8459 int phoneId = mSubscriptionController.getPhoneId(subId);
8460 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8461 return list.get(phoneId);
8462 }
8463 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008464 }
fionaxua13278b2018-03-21 00:08:13 -07008465
8466 @Override
8467 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008468 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008469 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470
8471 final long identity = Binder.clearCallingIdentity();
8472 try {
8473 final Phone phone = getPhone(subId);
8474 if (phone == null) {
8475 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8476 return;
8477 }
chen xueaba88a2019-03-15 13:15:10 -07008478 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8479 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008480 if (carrierPrivilegeRules == null) {
8481 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8482 } else {
8483 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008485 } finally {
8486 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008487 }
fionaxua13278b2018-03-21 00:08:13 -07008488 }
8489
8490 @Override
8491 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008492 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008493
8494 final long identity = Binder.clearCallingIdentity();
8495 try {
8496 final Phone phone = getPhone(subId);
8497 if (phone == null) {
8498 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8499 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8500 }
8501 return phone.getCarrierIdListVersion();
8502 } finally {
8503 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008504 }
fionaxua13278b2018-03-21 00:08:13 -07008505 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008506
8507 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008508 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8509 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008511 mApp, subId, callingPackage, callingFeatureId,
8512 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008513 return -1;
8514 }
8515
8516 final long identity = Binder.clearCallingIdentity();
8517 try {
8518 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8519 } finally {
8520 Binder.restoreCallingIdentity(identity);
8521 }
8522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008523
8524 @Override
8525 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008526 TelephonyPermissions
8527 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008528 mApp, subId, "getCdmaRoamingMode");
8529
8530 final long identity = Binder.clearCallingIdentity();
8531 try {
8532 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8533 } finally {
8534 Binder.restoreCallingIdentity(identity);
8535 }
8536 }
8537
8538 @Override
8539 public boolean setCdmaRoamingMode(int subId, int mode) {
8540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8541 mApp, subId, "setCdmaRoamingMode");
8542
8543 final long identity = Binder.clearCallingIdentity();
8544 try {
8545 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8546 } finally {
8547 Binder.restoreCallingIdentity(identity);
8548 }
8549 }
8550
8551 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008552 public int getCdmaSubscriptionMode(int subId) {
8553 TelephonyPermissions
8554 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8555 mApp, subId, "getCdmaSubscriptionMode");
8556
8557 final long identity = Binder.clearCallingIdentity();
8558 try {
8559 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8560 } finally {
8561 Binder.restoreCallingIdentity(identity);
8562 }
8563 }
8564
8565 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008566 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8568 mApp, subId, "setCdmaSubscriptionMode");
8569
8570 final long identity = Binder.clearCallingIdentity();
8571 try {
8572 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8573 } finally {
8574 Binder.restoreCallingIdentity(identity);
8575 }
8576 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008577
sqianc5eccab2018-10-19 18:46:41 -07008578 @Override
sqian8c685422019-02-22 15:55:18 -08008579 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008580 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008582 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8583 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008584 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8585 }
8586 final long identity = Binder.clearCallingIdentity();
8587 try {
sqian854d44b2018-12-12 16:48:18 -08008588 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8589 for (Phone phone: PhoneFactory.getPhones()) {
8590 if (phone.getEmergencyNumberTracker() != null
8591 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8592 emergencyNumberListInternal.put(
8593 phone.getSubId(),
8594 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8595 }
sqian11b7a0e2018-12-05 18:48:28 -08008596 }
sqian854d44b2018-12-12 16:48:18 -08008597 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008598 } finally {
8599 Binder.restoreCallingIdentity(identity);
8600 }
sqianc5eccab2018-10-19 18:46:41 -07008601 }
8602
8603 @Override
sqian8c685422019-02-22 15:55:18 -08008604 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008605 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008606 if (!exactMatch) {
8607 TelephonyPermissions
8608 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008609 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008610 }
8611 final long identity = Binder.clearCallingIdentity();
8612 try {
sqian854d44b2018-12-12 16:48:18 -08008613 for (Phone phone: PhoneFactory.getPhones()) {
8614 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008615 && phone.getEmergencyNumberTracker()
8616 .isEmergencyNumber(number, exactMatch)) {
8617 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008618 }
sqian11b7a0e2018-12-05 18:48:28 -08008619 }
8620 return false;
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
8624 }
8625
sqianf4ca7ed2019-01-15 18:32:07 -08008626 /**
Shuo Qian479dd9e2021-02-22 18:32:21 -08008627 * Start emergency callback mode for GsmCdmaPhone for testing.
8628 */
8629 @Override
8630 public void startEmergencyCallbackMode() {
8631 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8632 "startEmergencyCallbackMode");
8633 enforceModifyPermission();
8634 final long identity = Binder.clearCallingIdentity();
8635 try {
8636 for (Phone phone : PhoneFactory.getPhones()) {
8637 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8638 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8639 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8640 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8641 gsmCdmaPhone.obtainMessage(
8642 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8643 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8644 }
8645 }
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
8649 }
8650
8651 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008652 * Update emergency number list for test mode.
8653 */
8654 @Override
8655 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8656 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8657 "updateEmergencyNumberListTestMode");
8658
8659 final long identity = Binder.clearCallingIdentity();
8660 try {
8661 for (Phone phone: PhoneFactory.getPhones()) {
8662 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8663 if (tracker != null) {
8664 tracker.executeEmergencyNumberTestModeCommand(action, num);
8665 }
8666 }
8667 } finally {
8668 Binder.restoreCallingIdentity(identity);
8669 }
8670 }
8671
8672 /**
8673 * Get the full emergency number list for test mode.
8674 */
8675 @Override
8676 public List<String> getEmergencyNumberListTestMode() {
8677 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8678 "getEmergencyNumberListTestMode");
8679
8680 final long identity = Binder.clearCallingIdentity();
8681 try {
8682 Set<String> emergencyNumbers = new HashSet<>();
8683 for (Phone phone: PhoneFactory.getPhones()) {
8684 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8685 if (tracker != null) {
8686 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8687 emergencyNumbers.add(num.getNumber());
8688 }
8689 }
8690 }
8691 return new ArrayList<>(emergencyNumbers);
8692 } finally {
8693 Binder.restoreCallingIdentity(identity);
8694 }
8695 }
8696
chen xud6b45bd2018-10-30 22:27:10 -07008697 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008698 public int getEmergencyNumberDbVersion(int subId) {
8699 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8700
8701 final long identity = Binder.clearCallingIdentity();
8702 try {
8703 final Phone phone = getPhone(subId);
8704 if (phone == null) {
8705 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8706 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8707 }
8708 return phone.getEmergencyNumberDbVersion();
8709 } finally {
8710 Binder.restoreCallingIdentity(identity);
8711 }
8712 }
8713
8714 @Override
8715 public void notifyOtaEmergencyNumberDbInstalled() {
8716 enforceModifyPermission();
8717
8718 final long identity = Binder.clearCallingIdentity();
8719 try {
8720 for (Phone phone: PhoneFactory.getPhones()) {
8721 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8722 if (tracker != null) {
8723 tracker.updateOtaEmergencyNumberDatabase();
8724 }
8725 }
8726 } finally {
8727 Binder.restoreCallingIdentity(identity);
8728 }
8729 }
8730
8731 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008732 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008733 enforceActiveEmergencySessionPermission();
8734
8735 final long identity = Binder.clearCallingIdentity();
8736 try {
8737 for (Phone phone: PhoneFactory.getPhones()) {
8738 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8739 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008740 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8741 }
8742 }
8743 } finally {
8744 Binder.restoreCallingIdentity(identity);
8745 }
8746 }
8747
8748 @Override
8749 public void resetOtaEmergencyNumberDbFilePath() {
8750 enforceActiveEmergencySessionPermission();
8751
8752 final long identity = Binder.clearCallingIdentity();
8753 try {
8754 for (Phone phone: PhoneFactory.getPhones()) {
8755 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8756 if (tracker != null) {
8757 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008758 }
8759 }
8760 } finally {
8761 Binder.restoreCallingIdentity(identity);
8762 }
8763 }
8764
8765 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008766 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8767 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8768 Phone phone = getPhone(subId);
8769 if (phone == null) {
8770 return null;
8771 }
8772 final long identity = Binder.clearCallingIdentity();
8773 try {
8774 UiccProfile profile = UiccController.getInstance()
8775 .getUiccProfileForPhone(phone.getPhoneId());
8776 if (profile != null) {
8777 return profile.getCertsFromCarrierPrivilegeAccessRules();
8778 }
8779 } finally {
8780 Binder.restoreCallingIdentity(identity);
8781 }
8782 return null;
8783 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008784
8785 /**
8786 * Enable or disable a modem stack.
8787 */
8788 @Override
8789 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8790 enforceModifyPermission();
8791
8792 final long identity = Binder.clearCallingIdentity();
8793 try {
8794 Phone phone = PhoneFactory.getPhone(slotIndex);
8795 if (phone == null) {
8796 return false;
8797 } else {
8798 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8799 }
8800 } finally {
8801 Binder.restoreCallingIdentity(identity);
8802 }
8803 }
Michelecea4cf22018-12-21 15:00:11 -08008804
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008805 /**
8806 * Whether a modem stack is enabled or not.
8807 */
8808 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008809 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8810 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008811 Phone phone = PhoneFactory.getPhone(slotIndex);
8812 if (phone == null) return false;
8813
8814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008815 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8816 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008817 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8818 }
8819
8820 final long identity = Binder.clearCallingIdentity();
8821 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008822 try {
8823 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8824 } catch (NoSuchElementException ex) {
8825 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8826 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008827 } finally {
8828 Binder.restoreCallingIdentity(identity);
8829 }
8830 }
8831
Michelecea4cf22018-12-21 15:00:11 -08008832 @Override
Michele0ea7d782019-03-19 14:58:42 -07008833 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008834 enforceModifyPermission();
8835
8836 final long identity = Binder.clearCallingIdentity();
8837 try {
8838 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008839 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008840 .commit();
8841 } finally {
8842 Binder.restoreCallingIdentity(identity);
8843 }
8844 }
8845
8846 @Override
Michele0ea7d782019-03-19 14:58:42 -07008847 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008848 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008850 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8851 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008852 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008853 }
Michelecea4cf22018-12-21 15:00:11 -08008854
8855 final long identity = Binder.clearCallingIdentity();
8856 try {
Michele0ea7d782019-03-19 14:58:42 -07008857 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008858 } finally {
8859 Binder.restoreCallingIdentity(identity);
8860 }
8861 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008862
Michele0ea7d782019-03-19 14:58:42 -07008863 @TelephonyManager.IsMultiSimSupportedResult
8864 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008865 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8866 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8867 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008868 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8869 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008870 }
8871 // Check if the hardware supports multisim functionality. If usage of multisim is not
8872 // supported by the modem, indicate that it is restricted.
8873 PhoneCapability staticCapability =
8874 mPhoneConfigurationManager.getStaticPhoneCapability();
8875 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008876 loge("isMultiSimSupportedInternal: no static configuration available");
8877 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008878 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008879 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008880 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8881 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008882 }
8883 // Check if support of multiple SIMs is restricted by carrier
8884 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008885 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008886 }
8887
Michele0ea7d782019-03-19 14:58:42 -07008888 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008889 }
8890
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008891 /**
8892 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008893 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8894 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8895 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008896 * @param numOfSims number of active sims we want to switch to
8897 */
8898 @Override
8899 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008900 if (numOfSims == 1) {
8901 enforceModifyPermission();
8902 } else {
8903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8904 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8905 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008906 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008907
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008908 try {
Michele30b57b22019-03-01 12:01:14 -08008909 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008910 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008911 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8912 return;
8913 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008914 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8915 } finally {
8916 Binder.restoreCallingIdentity(identity);
8917 }
8918 }
8919
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008920 @Override
8921 public boolean isApplicationOnUicc(int subId, int appType) {
8922 enforceReadPrivilegedPermission("isApplicationOnUicc");
8923 Phone phone = getPhone(subId);
8924 if (phone == null) {
8925 return false;
8926 }
8927 final long identity = Binder.clearCallingIdentity();
8928 try {
8929 UiccCard uiccCard = phone.getUiccCard();
8930 if (uiccCard == null) {
8931 return false;
8932 }
8933 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8934 if (uiccProfile == null) {
8935 return false;
8936 }
8937 if (TelephonyManager.APPTYPE_SIM <= appType
8938 && appType <= TelephonyManager.APPTYPE_ISIM) {
8939 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8940 }
8941 return false;
8942 } finally {
8943 Binder.restoreCallingIdentity(identity);
8944 }
8945 }
8946
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008947 /**
chen xub4baa772019-04-03 10:23:41 -07008948 * Get whether making changes to modem configurations will trigger reboot.
8949 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008950 */
8951 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008952 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8953 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008954 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008955 mApp, subId, callingPackage, callingFeatureId,
8956 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008957 return false;
8958 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008959 final long identity = Binder.clearCallingIdentity();
8960 try {
8961 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8962 } finally {
8963 Binder.restoreCallingIdentity(identity);
8964 }
8965 }
8966
Nathan Harold29f5f052019-02-15 13:41:57 -08008967 private void updateModemStateMetrics() {
8968 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8969 // TODO: check the state for each modem if the api is ready.
8970 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8971 }
8972
Pengquan Meng3889a572019-01-23 11:16:29 -08008973 @Override
8974 public int[] getSlotsMapping() {
8975 enforceReadPrivilegedPermission("getSlotsMapping");
8976
8977 final long identity = Binder.clearCallingIdentity();
8978 try {
8979 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8980 // All logical slots should have a mapping to a physical slot.
8981 int[] logicalSlotsMapping = new int[phoneCount];
8982 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8983 for (int i = 0; i < slotInfos.length; i++) {
8984 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8985 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8986 }
8987 }
8988 return logicalSlotsMapping;
8989 } finally {
8990 Binder.restoreCallingIdentity(identity);
8991 }
8992 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008993
8994 /**
8995 * Get the IRadio HAL Version
8996 */
8997 @Override
8998 public int getRadioHalVersion() {
8999 Phone phone = getDefaultPhone();
9000 if (phone == null) return -1;
9001 HalVersion hv = phone.getHalVersion();
9002 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9003 return hv.major * 100 + hv.minor;
9004 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009005
9006 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08009007 * Get the current calling package name.
9008 * @return the current calling package name
9009 */
9010 @Override
9011 public String getCurrentPackageName() {
9012 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9013 }
9014
9015 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009016 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9017 * corresponding network requests on a subId.
9018 *
9019 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009020 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009021 * 2) APN is un-metered for this subscription, or
9022 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07009023 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009024 *
9025 * @return whether data is allowed for a apn type.
9026 *
9027 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009028 */
9029 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009030 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009031 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9032 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009033
9034 // Now that all security checks passes, perform the operation as ourselves.
9035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 Phone phone = getPhone(subId);
9038 if (phone == null) return false;
9039
Jack Yu41407ee2019-05-13 16:54:09 -07009040 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009041 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9042 } finally {
9043 Binder.restoreCallingIdentity(identity);
9044 }
9045 }
9046
9047 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009048 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009049 enforceReadPrivilegedPermission("isApnMetered");
9050
9051 // Now that all security checks passes, perform the operation as ourselves.
9052 final long identity = Binder.clearCallingIdentity();
9053 try {
9054 Phone phone = getPhone(subId);
9055 if (phone == null) return true; // By default return true.
9056
Jack Yu41407ee2019-05-13 16:54:09 -07009057 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009058 } finally {
9059 Binder.restoreCallingIdentity(identity);
9060 }
9061 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009062
9063 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009064 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9065 int subscriptionId, IBooleanConsumer resultCallback) {
9066 enforceModifyPermission();
9067 long token = Binder.clearCallingIdentity();
9068 try {
9069 Phone phone = getPhone(subscriptionId);
9070 if (phone == null) {
9071 try {
9072 if (resultCallback != null) {
9073 resultCallback.accept(false);
9074 }
9075 } catch (RemoteException e) {
9076 // ignore
9077 }
9078 return;
9079 }
9080 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9081 Pair.create(specifiers, (x) -> {
9082 try {
9083 if (resultCallback != null) {
9084 resultCallback.accept(x);
9085 }
9086 } catch (RemoteException e) {
9087 // ignore
9088 }
9089 });
9090 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9091 } finally {
9092 Binder.restoreCallingIdentity(token);
9093 }
9094 }
9095
9096 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009097 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9098 TelephonyPermissions
9099 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9100 mApp, subId, "getSystemSelectionChannels");
9101 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9102 final long identity = Binder.clearCallingIdentity();
9103 try {
9104 List<RadioAccessSpecifier> specifiers =
9105 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9106 null, subId, workSource);
9107 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9108 return specifiers;
9109 } finally {
9110 Binder.restoreCallingIdentity(identity);
9111 }
9112 }
9113
9114 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009115 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009116 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009117 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9118 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9119 if (iccRecords == null) {
9120 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9121 return false;
9122 }
9123 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9124 }
9125
9126 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009127 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9128 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009129 if (callingPackage == null) {
9130 callingPackage = getCurrentPackageName();
9131 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009132 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9133 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009134 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9135 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009136 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9137 }
9138 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9139 Intent intent = new Intent();
9140 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9141 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9142 // Bring up choose default SMS subscription dialog right now
9143 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9144 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9145 mApp.startActivity(intent);
9146 }
chen xud5ca2d52019-05-28 15:20:57 -07009147
9148 @Override
9149 public String getMmsUAProfUrl(int subId) {
9150 //TODO investigate if this API should require proper permission check in R b/133791609
9151 final long identity = Binder.clearCallingIdentity();
9152 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009153 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9154 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9155 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9156 return carrierUAProfUrl;
9157 }
chen xud5ca2d52019-05-28 15:20:57 -07009158 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9159 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9160 } finally {
9161 Binder.restoreCallingIdentity(identity);
9162 }
9163 }
9164
9165 @Override
9166 public String getMmsUserAgent(int subId) {
9167 //TODO investigate if this API should require proper permission check in R b/133791609
9168 final long identity = Binder.clearCallingIdentity();
9169 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009170 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9171 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9172 if (!TextUtils.isEmpty(carrierUserAgent)) {
9173 return carrierUserAgent;
9174 }
chen xud5ca2d52019-05-28 15:20:57 -07009175 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9176 .getString(com.android.internal.R.string.config_mms_user_agent);
9177 } finally {
9178 Binder.restoreCallingIdentity(identity);
9179 }
9180 }
Jack Yub07d4972019-05-28 16:12:25 -07009181
9182 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009183 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9184 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9185
9186 final long identity = Binder.clearCallingIdentity();
9187 try {
9188 Phone phone = getPhone(subscriptionId);
9189 if (phone == null) return false;
9190
9191 switch (policy) {
9192 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9193 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9194 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9195 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9196 default:
9197 throw new IllegalArgumentException(policy + " is not a valid policy");
9198 }
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
9201 }
9202 }
9203
9204 @Override
9205 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9206 boolean enabled) {
9207 enforceModifyPermission();
9208
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
9211 Phone phone = getPhone(subscriptionId);
9212 if (phone == null) return;
9213
9214 switch (policy) {
9215 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9216 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9217 break;
9218 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9219 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9220 break;
9221 default:
9222 throw new IllegalArgumentException(policy + " is not a valid policy");
9223 }
9224 } finally {
9225 Binder.restoreCallingIdentity(identity);
9226 }
9227 }
9228
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009229 /**
Hall Liub48cf452020-09-25 11:13:49 -07009230 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009231 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9232 * otherwise.
9233 */
9234 @Override
9235 public void setCepEnabled(boolean isCepEnabled) {
9236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9237
9238 final long identity = Binder.clearCallingIdentity();
9239 try {
9240 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9241 for (Phone phone : PhoneFactory.getPhones()) {
9242 Phone defaultPhone = phone.getImsPhone();
9243 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9244 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9245 ImsPhoneCallTracker imsPhoneCallTracker =
9246 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9247 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9248 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9249 + imsPhone.getMsisdn());
9250 }
9251 }
9252 } finally {
9253 Binder.restoreCallingIdentity(identity);
9254 }
9255 }
allenwtsu46dcc572020-01-08 18:24:03 +08009256
9257 /**
9258 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9259 *
9260 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9261 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9262 * before being read.
9263 */
9264 @Override
9265 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9266 isCompressed) {
9267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9268 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009269 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9270 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9271 }
9272 if (!isImsAvailableOnDevice()) {
9273 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9274 "IMS not available on device.");
9275 }
9276
9277 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009278 try {
Hui Wang068ab862020-10-31 05:12:53 +00009279 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9280 } finally {
9281 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009282 }
9283 }
zoey chenf95ca592019-12-30 16:11:23 +08009284
9285 @Override
9286 public boolean isIccLockEnabled(int subId) {
9287 enforceReadPrivilegedPermission("isIccLockEnabled");
9288
9289 // Now that all security checks passes, perform the operation as ourselves.
9290 final long identity = Binder.clearCallingIdentity();
9291 try {
9292 Phone phone = getPhone(subId);
9293 if (phone != null && phone.getIccCard() != null) {
9294 return phone.getIccCard().getIccLockEnabled();
9295 } else {
9296 return false;
9297 }
9298 } finally {
9299 Binder.restoreCallingIdentity(identity);
9300 }
9301 }
9302
9303 /**
zoey chene02881a2019-12-30 16:11:23 +08009304 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009305 *
zoey chene02881a2019-12-30 16:11:23 +08009306 * @return an integer representing the status of IccLock enabled or disabled in the following
9307 * three cases:
9308 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9309 * successfully.
9310 * - Positive number and zero for remaining password attempts.
9311 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009312 *
9313 */
9314 @Override
9315 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9316 enforceModifyPermission();
9317
9318 Phone phone = getPhone(subId);
9319 if (phone == null) {
9320 return 0;
9321 }
9322 // Now that all security checks passes, perform the operation as ourselves.
9323 final long identity = Binder.clearCallingIdentity();
9324 try {
9325 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9326 new Pair<Boolean, String>(enabled, password), phone, null);
9327 return attemptsRemaining;
9328
9329 } catch (Exception e) {
9330 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9331 } finally {
9332 Binder.restoreCallingIdentity(identity);
9333 }
9334 return 0;
9335 }
9336
9337 /**
9338 * Change the ICC password used in ICC pin lock.
9339 *
zoey chene02881a2019-12-30 16:11:23 +08009340 * @return an integer representing the status of IccLock changed in the following three cases:
9341 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9342 * - Positive number and zero for remaining password attempts.
9343 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009344 *
9345 */
9346 @Override
9347 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9348 enforceModifyPermission();
9349
9350 Phone phone = getPhone(subId);
9351 if (phone == null) {
9352 return 0;
9353 }
9354 // Now that all security checks passes, perform the operation as ourselves.
9355 final long identity = Binder.clearCallingIdentity();
9356 try {
9357 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9358 new Pair<String, String>(oldPassword, newPassword), phone, null);
9359 return attemptsRemaining;
9360
9361 } catch (Exception e) {
9362 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9363 } finally {
9364 Binder.restoreCallingIdentity(identity);
9365 }
9366 return 0;
9367 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009368
Peter Wangdafb9ac2020-01-15 14:13:38 -08009369 /**
9370 * Request for receiving user activity notification
9371 */
9372 @Override
9373 public void requestUserActivityNotification() {
9374 if (!mNotifyUserActivity.get()
9375 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9376 mNotifyUserActivity.set(true);
9377 }
9378 }
9379
9380 /**
9381 * Called when userActivity is signalled in the power manager.
9382 * This is safe to call from any thread, with any window manager locks held or not.
9383 */
9384 @Override
9385 public void userActivity() {
9386 // ***************************************
9387 // * Inherited from PhoneWindowManager *
9388 // ***************************************
9389 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9390 // WITH ITS LOCKS HELD.
9391 //
9392 // This code must be VERY careful about the locks
9393 // it acquires.
9394 // In fact, the current code acquires way too many,
9395 // and probably has lurking deadlocks.
9396
9397 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9398 throw new SecurityException("Only the OS may call notifyUserActivity()");
9399 }
9400
9401 if (mNotifyUserActivity.getAndSet(false)) {
9402 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9403 USER_ACTIVITY_NOTIFICATION_DELAY);
9404 }
9405 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009406
Malcolm Chen884180b2020-04-13 11:59:40 -07009407 @Override
9408 public boolean canConnectTo5GInDsdsMode() {
9409 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9410 }
Jack Yud10cdd42020-09-28 20:28:01 -07009411
9412 @Override
9413 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9414 String callingFeatureId) {
9415 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9416 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9417 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9418 }
9419
9420 Phone phone = getPhone(subId);
9421 if (phone == null) {
9422 throw new RuntimeException("phone is not available");
9423 }
9424 // Now that all security checks passes, perform the operation as ourselves.
9425 final long identity = Binder.clearCallingIdentity();
9426 try {
9427 return phone.getEquivalentHomePlmns();
9428 } finally {
9429 Binder.restoreCallingIdentity(identity);
9430 }
9431 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009432
Hui Wang0866fcc2020-10-12 12:14:23 -07009433 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009434 public boolean isRadioInterfaceCapabilitySupported(
9435 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright52006302021-02-24 19:51:22 +00009436 RadioInterfaceCapabilities radioInterfaceCapabilities =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009437 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9438 if (radioInterfaceCapabilities == null) {
9439 throw new RuntimeException("radio interface capabilities are not available");
9440 } else {
Daniel Bright52006302021-02-24 19:51:22 +00009441 return radioInterfaceCapabilities.isSupported(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009442 }
9443 }
9444
9445 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009446 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9447 UaSecurityProtocolIdentifier securityProtocol,
9448 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9449 throws RemoteException {
9450 enforceModifyPermission();
9451 if (DBG) {
9452 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9453 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9454 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9455 }
9456
9457 if (!SubscriptionManager.isValidSubscriptionId(subId)
9458 || appType < TelephonyManager.APPTYPE_UNKNOWN
9459 || appType > TelephonyManager.APPTYPE_ISIM
9460 || nafUrl == null || securityProtocol == null || callback == null) {
9461 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9462 if (callback != null) {
9463 try {
9464 callback.onAuthenticationFailure(
9465 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9466 } catch (RemoteException exception) {
9467 log("Fail to notify onAuthenticationFailure due to " + exception);
9468 }
9469 return;
9470 }
9471 }
9472
9473 final long token = Binder.clearCallingIdentity();
9474 try {
9475 getGbaManager(subId).bootstrapAuthenticationRequest(
9476 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9477 forceBootStrapping, callback));
9478 } finally {
9479 Binder.restoreCallingIdentity(token);
9480 }
9481 }
9482
Jack Nudelman24d51a52020-11-24 12:08:04 -08009483 /**
9484 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9485 * requested radio power state will actually be set. See {@link
9486 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9487 *
9488 * @param subId the subscription ID of the phone requesting to set the radio power state.
9489 * @param enable {@code true} if trying to turn radio on.
9490 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9491 * false}.
9492 */
9493 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9494 Phone phone = getPhone(subId);
9495 if (phone != null) {
9496 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9497 return true;
9498 }
9499 return false;
9500 }
9501
9502 private int handleDataThrottlingRequest(int subId,
9503 DataThrottlingRequest dataThrottlingRequest) {
9504 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9505 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9506 if (!setRadioPowerForThermal(subId, true)) {
9507 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9508 }
9509
9510 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9511
9512 int thermalMitigationResult =
9513 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9514 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9515 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9516 }
9517 return thermalMitigationResult;
9518 }
9519
9520 /**
9521 * Thermal mitigation request to control functionalities at modem.
9522 *
9523 * @param subId the id of the subscription.
9524 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9525 *
9526 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9527 */
9528 @Override
9529 @ThermalMitigationResult
9530 public int sendThermalMitigationRequest(
9531 int subId,
9532 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9533 enforceModifyPermission();
9534
9535 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9536 final long identity = Binder.clearCallingIdentity();
9537
9538 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9539 try {
9540 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9541 switch (thermalMitigationAction) {
9542 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9543 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009544 handleDataThrottlingRequest(subId,
9545 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009546 break;
9547 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9548 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9549 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9550 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9551 }
9552
9553 // Ensure that radio is on. If not able to power on due to phone being
9554 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9555 if (!setRadioPowerForThermal(subId, true)) {
9556 thermalMitigationResult =
9557 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9558 break;
9559 }
9560
9561 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9562 false);
9563 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9564 break;
9565 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9566 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9567 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9568 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9569 }
9570
9571 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9572 if (registry != null) {
9573 TelephonyConnectionService service =
9574 registry.getTelephonyConnectionService();
9575 Phone phone = getPhone(subId);
9576 if (phone == null) {
9577 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009578 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009579 break;
9580 }
9581
9582 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009583 != TelephonyManager.CALL_STATE_IDLE
9584 || phone.isInEmergencySmsMode() || phone.isInEcm()
9585 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009586 String errorMessage = "Phone state is not valid. call state = "
9587 + PhoneConstantConversions.convertCallState(phone.getState())
9588 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9589 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9590 errorMessage += service == null
9591 ? " TelephonyConnectionService is null"
9592 : " isEmergencyCallPending = "
9593 + service.isEmergencyCallPending();
9594 Log.e(LOG_TAG, errorMessage);
9595 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009596 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009597 break;
9598 }
9599 } else {
9600 thermalMitigationResult =
9601 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9602 break;
9603 }
9604
9605 // Turn radio off. If not able to power off due to phone being unavailable,
9606 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9607 if (!setRadioPowerForThermal(subId, false)) {
9608 thermalMitigationResult =
9609 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9610 break;
9611 }
9612 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009613 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009614 break;
9615 default:
9616 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9617 + "not exist. Requested action: " + thermalMitigationAction);
9618 }
9619 } catch (IllegalArgumentException e) {
9620 throw e;
9621 } catch (Exception e) {
9622 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9623 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9624 } finally {
9625 Binder.restoreCallingIdentity(identity);
9626 }
9627
9628 if (DBG) {
9629 log("thermalMitigationRequest returning with thermalMitigationResult: "
9630 + thermalMitigationResult);
9631 }
9632
9633 return thermalMitigationResult;
9634 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009635
9636 /**
9637 * Set the GbaService Package Name that Telephony will bind to.
9638 *
9639 * @param subId The sim that the GbaService is associated with.
9640 * @param packageName The name of the package to be replaced with.
9641 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9642 */
9643 @Override
9644 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9645 enforceModifyPermission();
9646
9647 final long identity = Binder.clearCallingIdentity();
9648 try {
9649 return getGbaManager(subId).overrideServicePackage(packageName);
9650 } finally {
9651 Binder.restoreCallingIdentity(identity);
9652 }
9653 }
9654
9655 /**
9656 * Return the package name of the currently bound GbaService.
9657 *
9658 * @param subId The sim that the GbaService is associated with.
9659 * @return the package name of the GbaService configuration, null if GBA is not supported.
9660 */
9661 @Override
9662 public String getBoundGbaService(int subId) {
9663 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9664
9665 final long identity = Binder.clearCallingIdentity();
9666 try {
9667 return getGbaManager(subId).getServicePackage();
9668 } finally {
9669 Binder.restoreCallingIdentity(identity);
9670 }
9671 }
9672
9673 /**
9674 * Set the release time for telephony to unbind GbaService.
9675 *
9676 * @param subId The sim that the GbaService is associated with.
9677 * @param interval The release time to unbind GbaService by millisecond.
9678 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9679 */
9680 @Override
9681 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9682 enforceModifyPermission();
9683
9684 final long identity = Binder.clearCallingIdentity();
9685 try {
9686 return getGbaManager(subId).overrideReleaseTime(interval);
9687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690 }
9691
9692 /**
9693 * Return the release time for telephony to unbind GbaService.
9694 *
9695 * @param subId The sim that the GbaService is associated with.
9696 * @return The release time to unbind GbaService by millisecond.
9697 */
9698 @Override
9699 public int getGbaReleaseTime(int subId) {
9700 enforceReadPrivilegedPermission("getGbaReleaseTime");
9701
9702 final long identity = Binder.clearCallingIdentity();
9703 try {
9704 return getGbaManager(subId).getReleaseTime();
9705 } finally {
9706 Binder.restoreCallingIdentity(identity);
9707 }
9708 }
9709
9710 private GbaManager getGbaManager(int subId) {
9711 GbaManager instance = GbaManager.getInstance(subId);
9712 if (instance == null) {
9713 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9714 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9715 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9716 }
9717 return instance;
9718 }
Hui Wang068ab862020-10-31 05:12:53 +00009719
9720 /**
9721 * indicate whether the device and the carrier can support
9722 * RCS VoLTE single registration.
9723 */
9724 @Override
9725 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9726 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9727
9728 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9729 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9730 }
9731
9732 final long identity = Binder.clearCallingIdentity();
9733 try {
9734 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9735 if (rpm != null) {
9736 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9737 }
9738 return false;
9739 } finally {
9740 Binder.restoreCallingIdentity(identity);
9741 }
9742 }
9743
9744 /**
9745 * Register RCS provisioning callback.
9746 */
9747 @Override
9748 public void registerRcsProvisioningChangedCallback(int subId,
9749 IRcsConfigCallback callback) {
9750 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9751
9752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9753 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9754 }
9755 if (!isImsAvailableOnDevice()) {
9756 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9757 "IMS not available on device.");
9758 }
9759
9760 final long identity = Binder.clearCallingIdentity();
9761 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009762 if (!RcsProvisioningMonitor.getInstance()
9763 .registerRcsProvisioningChangedCallback(subId, callback)) {
9764 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9765 "Service not available for the subscription.");
9766 }
Hui Wang068ab862020-10-31 05:12:53 +00009767 } finally {
9768 Binder.restoreCallingIdentity(identity);
9769 }
9770 }
9771
9772 /**
9773 * Unregister RCS provisioning callback.
9774 */
9775 @Override
9776 public void unregisterRcsProvisioningChangedCallback(int subId,
9777 IRcsConfigCallback callback) {
9778 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9779
9780 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9781 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9782 }
9783 if (!isImsAvailableOnDevice()) {
9784 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9785 "IMS not available on device.");
9786 }
9787
9788 final long identity = Binder.clearCallingIdentity();
9789 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009790 RcsProvisioningMonitor.getInstance()
9791 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009792 } finally {
9793 Binder.restoreCallingIdentity(identity);
9794 }
9795 }
9796
9797 /**
9798 * trigger RCS reconfiguration.
9799 */
9800 public void triggerRcsReconfiguration(int subId) {
9801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9802 mApp, subId, "triggerRcsReconfiguration");
9803
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 {
9814 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9815 } finally {
9816 Binder.restoreCallingIdentity(identity);
9817 }
9818 }
9819
9820 /**
9821 * Provide the client configuration parameters of the RCS application.
9822 */
9823 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9825 mApp, subId, "setRcsClientConfiguration");
9826
9827 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9828 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9829 }
9830 if (!isImsAvailableOnDevice()) {
9831 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9832 "IMS not available on device.");
9833 }
9834
9835 final long identity = Binder.clearCallingIdentity();
9836
9837 try {
9838 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9839 if (configBinder == null) {
9840 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9841 } else {
9842 configBinder.setRcsClientConfiguration(rcc);
9843 }
9844 } catch (RemoteException e) {
9845 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9846 } finally {
9847 Binder.restoreCallingIdentity(identity);
9848 }
9849 }
9850
9851 /**
9852 * Overrides the config of RCS VoLTE single registration enabled for the device.
9853 */
9854 @Override
9855 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9857 "setDeviceSingleRegistrationEnabledOverride");
9858 enforceModifyPermission();
9859
9860 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9861 : Boolean.parseBoolean(enabledStr);
9862 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009863 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009864 }
9865
9866 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009867 * Sends a device to device communication message. Only usable via shell.
9868 * @param message message to send.
9869 * @param value message value.
9870 */
9871 @Override
9872 public void sendDeviceToDeviceMessage(int message, int value) {
9873 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9874 "setCarrierSingleRegistrationEnabledOverride");
9875 enforceModifyPermission();
9876
9877 final long identity = Binder.clearCallingIdentity();
9878 try {
9879 TelephonyConnectionService service =
9880 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9881 if (service == null) {
9882 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9883 return;
9884 }
9885 service.sendTestDeviceToDeviceMessage(message, value);
9886 } finally {
9887 Binder.restoreCallingIdentity(identity);
9888 }
9889 }
9890
9891
9892 /**
Hui Wang068ab862020-10-31 05:12:53 +00009893 * Gets the config of RCS VoLTE single registration enabled for the device.
9894 */
9895 @Override
9896 public boolean getDeviceSingleRegistrationEnabled() {
9897 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9898 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9899 }
9900
9901 /**
9902 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9903 */
9904 @Override
9905 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9906 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9907 "setCarrierSingleRegistrationEnabledOverride");
9908 enforceModifyPermission();
9909
9910 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9911 : Boolean.parseBoolean(enabledStr);
9912 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9913 subId, enabled);
9914 }
9915
9916 /**
9917 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9918 */
9919 @Override
9920 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9921 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9922 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9923 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009924
9925 /**
9926 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9927 * their mobile plan.
9928 */
9929 @Override
9930 public String getMobileProvisioningUrl() {
9931 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9932 final long identity = Binder.clearCallingIdentity();
9933 try {
9934 return getDefaultPhone().getMobileProvisioningUrl();
9935 } finally {
9936 Binder.restoreCallingIdentity(identity);
9937 }
9938 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009939
James.cf Linbcdf8b32021-01-14 16:44:13 +08009940 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009941 * Get the EAB contact from the EAB database.
9942 */
9943 @Override
9944 public String getContactFromEab(String contact) {
9945 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9946 enforceModifyPermission();
9947 final long identity = Binder.clearCallingIdentity();
9948 try {
9949 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9950 } finally {
9951 Binder.restoreCallingIdentity(identity);
9952 }
9953 }
9954
9955 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009956 * Remove the EAB contacts from the EAB database.
9957 */
9958 @Override
9959 public int removeContactFromEab(int subId, String contacts) {
9960 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9961 enforceModifyPermission();
9962 final long identity = Binder.clearCallingIdentity();
9963 try {
9964 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9965 } finally {
9966 Binder.restoreCallingIdentity(identity);
9967 }
9968 }
9969
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009970 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009971 public boolean getDeviceUceEnabled() {
9972 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9973 final long identity = Binder.clearCallingIdentity();
9974 try {
9975 return mApp.getDeviceUceEnabled();
9976 } finally {
9977 Binder.restoreCallingIdentity(identity);
9978 }
9979 }
9980
9981 @Override
9982 public void setDeviceUceEnabled(boolean isEnabled) {
9983 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9984 final long identity = Binder.clearCallingIdentity();
9985 try {
9986 mApp.setDeviceUceEnabled(isEnabled);
9987 } finally {
9988 Binder.restoreCallingIdentity(identity);
9989 }
9990 }
9991
9992 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009993 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9994 String callingPackage) {
9995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9996 mApp, subId, "setSignalStrengthUpdateRequest");
9997
9998 final int callingUid = Binder.getCallingUid();
9999 // Verify that tha callingPackage belongs to the calling UID
10000 mApp.getSystemService(AppOpsManager.class)
10001 .checkPackage(callingUid, callingPackage);
10002
10003 validateSignalStrengthUpdateRequest(request, callingUid);
10004
10005 final long identity = Binder.clearCallingIdentity();
10006 try {
10007 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10008 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10009
10010 if (result instanceof IllegalStateException) {
10011 throw (IllegalStateException) result;
10012 }
10013 } finally {
10014 Binder.restoreCallingIdentity(identity);
10015 }
10016 }
10017
10018 @Override
10019 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10020 String callingPackage) {
10021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10022 mApp, subId, "clearSignalStrengthUpdateRequest");
10023
10024 final int callingUid = Binder.getCallingUid();
10025 // Verify that tha callingPackage belongs to the calling UID
10026 mApp.getSystemService(AppOpsManager.class)
10027 .checkPackage(callingUid, callingPackage);
10028
10029 final long identity = Binder.clearCallingIdentity();
10030 try {
10031 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10032 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10033
10034 if (result instanceof IllegalStateException) {
10035 throw (IllegalStateException) result;
10036 }
10037 } finally {
10038 Binder.restoreCallingIdentity(identity);
10039 }
10040 }
10041
10042 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10043 int callingUid) {
10044 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10045 // phone/system process do not have further restriction on request
10046 return;
10047 }
10048
10049 // Applications has restrictions on how to use the request:
10050 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10051 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10052 // This is not system caller which has been checked above
10053 throw new IllegalArgumentException(
10054 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10055 }
10056
10057 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10058 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10059 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10060 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10061 || info.isEnabled()) {
10062 throw new IllegalArgumentException(
10063 "Only system can set hide fields in SignalThresholdInfo");
10064 }
10065
10066 // Thresholds length for each RAN need in range. This has been validated in
10067 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10068 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10069 final int[] thresholds = info.getThresholds();
10070 Objects.requireNonNull(thresholds);
10071 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10072 || thresholds.length
10073 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10074 throw new IllegalArgumentException(
10075 "thresholds length is out of range: " + thresholds.length);
10076 }
10077 }
10078 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010079
10080 /**
10081 * Prepare TelephonyManager for an unattended reboot. The reboot is
10082 * required to be done shortly after the API is invoked.
10083 */
10084 @Override
10085 @TelephonyManager.PrepareUnattendedRebootResult
10086 public int prepareForUnattendedReboot() {
10087 enforceRebootPermission();
10088
10089 final long identity = Binder.clearCallingIdentity();
10090 try {
10091 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10092 } finally {
10093 Binder.restoreCallingIdentity(identity);
10094 }
10095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010096}