blob: f0a6a69c548f6ba7f586c4dc8ee7162cbe57bbd6 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qian479dd9e2021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger4df7e242021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070032import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070033import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034import android.content.Context;
35import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070036import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070037import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080038import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070039import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.net.Uri;
41import android.os.AsyncResult;
42import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080043import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Bundle;
45import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.Looper;
48import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070049import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080050import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070051import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070052import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080053import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080054import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070055import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070056import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080057import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070058import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070059import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070060import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070061import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070062import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080063import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070064import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090065import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080066import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080067import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070068import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070069import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080070import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080071import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070072import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080073import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070074import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080075import android.telephony.CellIdentityCdma;
76import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070078import android.telephony.CellInfoGsm;
79import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070080import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080081import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070082import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070083import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070084import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080085import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070086import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080087import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070088import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080089import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080090import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070091import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080092import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080094import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080095import android.telephony.SignalStrengthUpdateRequest;
96import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080097import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080098import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080099import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700100import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700101import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800102import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800103import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800104import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000105import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700106import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700107import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800108import android.telephony.data.ApnSetting;
Hongbo Zengd31d3a32021-02-08 21:50:28 +0800109import android.telephony.data.SlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700111import android.telephony.gba.GbaAuthRequest;
112import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700113import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000115import android.telephony.ims.RcsClientConfiguration;
Brad Ebingerd4c5bde2021-02-12 06:18:28 +0000116import android.telephony.ims.RcsContactUceCapability;
Brad Ebinger774ba362019-10-22 17:36:18 -0700117import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700118import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800119import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700120import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700122import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000123import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700124import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800126import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800128import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700131import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800133import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800134
Andrew Lee312e8172014-10-23 17:01:36 -0700135import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800136import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800137import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWang51ee2b12021-05-27 22:44:54 +0800138import com.android.internal.annotations.VisibleForTesting;
sqian80370722020-01-29 15:02:51 -0800139import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700141import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700142import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800143import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700144import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800146import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700148import com.android.internal.telephony.GbaManager;
Shuo Qian479dd9e2021-02-22 18:32:21 -0800149import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800150import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800151import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700152import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800154import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800156import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700157import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700158import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700159import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700161import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800162import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700163import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700164import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700165import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700166import com.android.internal.telephony.RIL;
SongFerngWang522637d2021-03-02 22:09:29 +0800167import com.android.internal.telephony.RILConstants;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800168import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700170import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800172import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800173import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800174import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700175import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800176import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700177import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800178import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700179import com.android.internal.telephony.imsphone.ImsPhone;
180import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800181import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900182import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800184import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800186import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700187import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800190import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000191import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800192import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700193import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700194import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800195import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700196import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700197import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800198import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700199import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700200import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800201import com.android.services.telephony.TelecomAccountRegistry;
202import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800203import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800204
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700205import java.io.FileDescriptor;
206import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800208import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800209import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800211import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100212import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800213import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700214import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800215import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800216import java.util.Set;
SongFerngWangc63cf522021-03-31 22:08:45 +0800217import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800218import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800219import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220
221/**
222 * Implementation of the ITelephony interface.
223 */
Santos Cordon117fee72014-05-16 17:56:12 -0700224public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225 private static final String LOG_TAG = "PhoneInterfaceManager";
226 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
227 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800228 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229
230 // Message codes used with mMainThreadHandler
231 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700232 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
233 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700234 private static final int CMD_OPEN_CHANNEL = 9;
235 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
236 private static final int CMD_CLOSE_CHANNEL = 11;
237 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800238 private static final int CMD_NV_READ_ITEM = 13;
239 private static final int EVENT_NV_READ_ITEM_DONE = 14;
240 private static final int CMD_NV_WRITE_ITEM = 15;
241 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
242 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
243 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700244 private static final int CMD_RESET_MODEM_CONFIG = 19;
245 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800246 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
247 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800248 private static final int CMD_SEND_ENVELOPE = 25;
249 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000250 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
251 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700252 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
253 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
254 private static final int CMD_EXCHANGE_SIM_IO = 31;
255 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800256 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
257 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700258 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
259 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700260 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
261 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700262 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
263 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
264 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
265 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700266 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
267 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
268 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
269 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700270 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800271 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
272 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000273 private static final int CMD_SWITCH_SLOTS = 50;
274 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700275 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
276 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
277 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
278 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
279 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
280 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
281 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
282 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700283 private static final int CMD_GET_ALL_CELL_INFO = 60;
284 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
285 private static final int CMD_GET_CELL_LOCATION = 62;
286 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700287 private static final int CMD_MODEM_REBOOT = 64;
288 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700289 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
290 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800291 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
292 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700293 private static final int CMD_GET_MODEM_STATUS = 70;
294 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700295 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
296 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700297 private static final int CMD_ERASE_MODEM_CONFIG = 74;
298 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800299 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
300 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
301 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
302 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800303 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
304 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800305 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800306 private static final int CMD_GET_CALL_FORWARDING = 83;
307 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
308 private static final int CMD_SET_CALL_FORWARDING = 85;
309 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
310 private static final int CMD_GET_CALL_WAITING = 87;
311 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
312 private static final int CMD_SET_CALL_WAITING = 89;
313 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700314 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
315 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
316 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
317 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700318 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
319 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800320 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
321 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800322 private static final int CMD_SET_DATA_THROTTLING = 99;
323 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800324 private static final int CMD_SET_SIM_POWER = 101;
325 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800326 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
327 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
328 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
329 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800330 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
331 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000332 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zengd31d3a32021-02-08 21:50:28 +0800333 private static final int CMD_GET_SLICING_CONFIG = 110;
334 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800336 // Parameters of select command.
337 private static final int SELECT_COMMAND = 0xA4;
338 private static final int SELECT_P1 = 0x04;
339 private static final int SELECT_P2 = 0;
340 private static final int SELECT_P3 = 0x10;
341
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 /** The singleton instance. */
343 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800344 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345
Wink Saville3ab207e2014-11-20 13:07:20 -0800346 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800347 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800348 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700349 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800350 private AppOpsManager mAppOps;
351 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800352 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800353 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700354 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Brightfe1e6ac2021-03-12 10:25:03 -0800355 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
Peter Wangdafb9ac2020-01-15 14:13:38 -0800357 /** User Activity */
358 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800359 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
360
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700361 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
362
Derek Tan97ebb422014-09-05 16:55:38 -0700363 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
364 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800365 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800366 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700367
Michelecea4cf22018-12-21 15:00:11 -0800368 // String to store multi SIM allowed
369 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
370
Derek Tan740e1672017-06-27 14:56:27 -0700371 // The AID of ISD-R.
372 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
373
yinxub1bed742017-04-17 11:45:04 -0700374 private NetworkScanRequestTracker mNetworkScanRequestTracker;
375
David Kelly5e06a7f2018-03-12 14:10:59 +0000376 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
377 private static final int MANUFACTURER_CODE_LENGTH = 8;
378
Jack Nudelman24d51a52020-11-24 12:08:04 -0800379 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800380 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800381
Derek Tan89e89d42014-07-08 17:00:10 -0700382 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700383 * Experiment flag to enable erase modem config on reset network, default value is false
384 */
385 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
386 "reset_network_erase_modem_config_enabled";
387
Rambo Wang0f050d82021-02-12 11:43:36 -0800388 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
389
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700390 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700391 * A request object to use for transmitting data to an ICC.
392 */
393 private static final class IccAPDUArgument {
394 public int channel, cla, command, p1, p2, p3;
395 public String data;
396
397 public IccAPDUArgument(int channel, int cla, int command,
398 int p1, int p2, int p3, String data) {
399 this.channel = channel;
400 this.cla = cla;
401 this.command = command;
402 this.p1 = p1;
403 this.p2 = p2;
404 this.p3 = p3;
405 this.data = data;
406 }
407 }
408
409 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700410 * A request object to use for transmitting data to an ICC.
411 */
412 private static final class ManualNetworkSelectionArgument {
413 public OperatorInfo operatorInfo;
414 public boolean persistSelection;
415
416 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
417 this.operatorInfo = operatorInfo;
418 this.persistSelection = persistSelection;
419 }
420 }
421
422 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
424 * request after sending. The main thread will notify the request when it is complete.
425 */
426 private static final class MainThreadRequest {
427 /** The argument to use for the request */
428 public Object argument;
429 /** The result of the request that is run on the main thread */
430 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800431 // The subscriber id that this request applies to. Defaults to
432 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
433 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434
Nathan Harold92bed182018-10-12 18:16:49 -0700435 // In cases where subId is unavailable, the caller needs to specify the phone.
436 public Phone phone;
437
vagdeviaf9a5b92018-08-15 16:01:53 -0700438 public WorkSource workSource;
439
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440 public MainThreadRequest(Object argument) {
441 this.argument = argument;
442 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800443
Nathan Harold92bed182018-10-12 18:16:49 -0700444 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
445 this.argument = argument;
446 if (phone != null) {
447 this.phone = phone;
448 }
449 this.workSource = workSource;
450 }
451
vagdeviaf9a5b92018-08-15 16:01:53 -0700452 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800453 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800454 if (subId != null) {
455 this.subId = subId;
456 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700457 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700459 }
460
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800461 private static final class IncomingThirdPartyCallArgs {
462 public final ComponentName component;
463 public final String callId;
464 public final String callerDisplayName;
465
466 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
467 String callerDisplayName) {
468 this.component = component;
469 this.callId = callId;
470 this.callerDisplayName = callerDisplayName;
471 }
472 }
473
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 /**
475 * A handler that processes messages on the main thread in the phone process. Since many
476 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
477 * inbound binder threads to the main thread in the phone process. The Binder thread
478 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
479 * on, which will be notified when the operation completes and will contain the result of the
480 * request.
481 *
482 * <p>If a MainThreadRequest object is provided in the msg.obj field,
483 * note that request.result must be set to something non-null for the calling thread to
484 * unblock.
485 */
486 private final class MainThreadHandler extends Handler {
487 @Override
488 public void handleMessage(Message msg) {
489 MainThreadRequest request;
490 Message onCompleted;
491 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800494 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700495
496 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 case CMD_HANDLE_USSD_REQUEST: {
498 request = (MainThreadRequest) msg.obj;
499 final Phone phone = getPhoneFromRequest(request);
500 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
501 String ussdRequest = ussdObject.first;
502 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700503
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 if (!isUssdApiAllowed(request.subId)) {
505 // Carrier does not support use of this API, return failure.
506 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
507 UssdResponse response = new UssdResponse(ussdRequest, null);
508 Bundle returnData = new Bundle();
509 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
510 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700511
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 request.result = true;
513 notifyRequester(request);
514 return;
515 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700516
Pengquan Menga1bb6272018-09-06 09:59:22 -0700517 try {
518 request.result = phone != null
519 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
520 } catch (CallStateException cse) {
521 request.result = false;
522 }
523 // Wake up the requesting thread
524 notifyRequester(request);
525 break;
pkanwar32d516d2016-10-14 19:37:38 -0700526 }
527
Yorke Lee716f67e2015-06-17 15:39:16 -0700528 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700529 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700530 final Phone phone = getPhoneFromRequest(request);
531 request.result = phone != null ?
532 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
533 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700537 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700541 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800542 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 if (uiccCard == null) {
544 loge("iccTransmitApduLogicalChannel: No UICC");
545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
549 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 iccArgument.channel, iccArgument.cla, iccArgument.command,
552 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 break;
556
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 ar = (AsyncResult) msg.obj;
559 request = (MainThreadRequest) ar.userObj;
560 if (ar.exception == null && ar.result != null) {
561 request.result = ar.result;
562 } else {
563 request.result = new IccIoResult(0x6F, 0, (byte[])null);
564 if (ar.result == null) {
565 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800566 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800568 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 } else {
570 loge("iccTransmitApduLogicalChannel: Unknown exception");
571 }
572 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 break;
575
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
577 request = (MainThreadRequest) msg.obj;
578 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800579 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 if (uiccCard == null) {
581 loge("iccTransmitApduBasicChannel: No UICC");
582 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 } else {
585 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
586 request);
587 uiccCard.iccTransmitApduBasicChannel(
588 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
589 iccArgument.p3, iccArgument.data, onCompleted);
590 }
591 break;
592
593 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
594 ar = (AsyncResult) msg.obj;
595 request = (MainThreadRequest) ar.userObj;
596 if (ar.exception == null && ar.result != null) {
597 request.result = ar.result;
598 } else {
599 request.result = new IccIoResult(0x6F, 0, (byte[])null);
600 if (ar.result == null) {
601 loge("iccTransmitApduBasicChannel: Empty response");
602 } else if (ar.exception instanceof CommandException) {
603 loge("iccTransmitApduBasicChannel: CommandException: " +
604 ar.exception);
605 } else {
606 loge("iccTransmitApduBasicChannel: Unknown exception");
607 }
608 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700609 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 break;
611
612 case CMD_EXCHANGE_SIM_IO:
613 request = (MainThreadRequest) msg.obj;
614 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800615 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 if (uiccCard == null) {
617 loge("iccExchangeSimIO: No UICC");
618 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 } else {
621 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
622 request);
623 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
624 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
625 iccArgument.data, onCompleted);
626 }
627 break;
628
629 case EVENT_EXCHANGE_SIM_IO_DONE:
630 ar = (AsyncResult) msg.obj;
631 request = (MainThreadRequest) ar.userObj;
632 if (ar.exception == null && ar.result != null) {
633 request.result = ar.result;
634 } else {
635 request.result = new IccIoResult(0x6f, 0, (byte[])null);
636 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700637 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700638 break;
639
Derek Tan4d5e5c12014-02-04 11:54:58 -0800640 case CMD_SEND_ENVELOPE:
641 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800642 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 if (uiccCard == null) {
644 loge("sendEnvelopeWithStatus: No UICC");
645 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 } else {
648 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
649 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
650 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800651 break;
652
653 case EVENT_SEND_ENVELOPE_DONE:
654 ar = (AsyncResult) msg.obj;
655 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700656 if (ar.exception == null && ar.result != null) {
657 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800658 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700659 request.result = new IccIoResult(0x6F, 0, (byte[])null);
660 if (ar.result == null) {
661 loge("sendEnvelopeWithStatus: Empty response");
662 } else if (ar.exception instanceof CommandException) {
663 loge("sendEnvelopeWithStatus: CommandException: " +
664 ar.exception);
665 } else {
666 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
667 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800670 break;
671
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 case CMD_OPEN_CHANNEL:
673 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800674 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800675 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700676 if (uiccCard == null) {
677 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800678 request.result = new IccOpenLogicalChannelResponse(-1,
679 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700680 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 } else {
682 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800683 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
684 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 break;
687
688 case EVENT_OPEN_CHANNEL_DONE:
689 ar = (AsyncResult) msg.obj;
690 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700691 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700693 int[] result = (int[]) ar.result;
694 int channelId = result[0];
695 byte[] selectResponse = null;
696 if (result.length > 1) {
697 selectResponse = new byte[result.length - 1];
698 for (int i = 1; i < result.length; ++i) {
699 selectResponse[i - 1] = (byte) result[i];
700 }
701 }
702 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700703 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 if (ar.result == null) {
706 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 if (ar.exception != null) {
709 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
710 }
711
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700712 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700713 if (ar.exception instanceof CommandException) {
714 CommandException.Error error =
715 ((CommandException) (ar.exception)).getCommandError();
716 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700717 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700718 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700719 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700720 }
721 }
722 openChannelResp = new IccOpenLogicalChannelResponse(
723 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700724 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700725 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700726 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 break;
728
729 case CMD_CLOSE_CHANNEL:
730 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800731 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700732 if (uiccCard == null) {
733 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900734 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700736 } else {
737 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
738 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
739 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 break;
741
742 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800743 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
744 break;
745
746 case CMD_NV_READ_ITEM:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800749 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
750 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800751 break;
752
753 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 ar = (AsyncResult) msg.obj;
755 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800756 if (ar.exception == null && ar.result != null) {
757 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800759 request.result = "";
760 if (ar.result == null) {
761 loge("nvReadItem: Empty response");
762 } else if (ar.exception instanceof CommandException) {
763 loge("nvReadItem: CommandException: " +
764 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800766 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 }
768 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 break;
771
Jake Hambye994d462014-02-03 13:10:13 -0800772 case CMD_NV_WRITE_ITEM:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
775 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800776 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700777 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800778 break;
779
780 case EVENT_NV_WRITE_ITEM_DONE:
781 handleNullReturnEvent(msg, "nvWriteItem");
782 break;
783
784 case CMD_NV_WRITE_CDMA_PRL:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800787 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
790 case EVENT_NV_WRITE_CDMA_PRL_DONE:
791 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
792 break;
793
chen xu6dac5ab2018-10-26 17:39:23 -0700794 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800795 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700796 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800797 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800798 break;
799
chen xu6dac5ab2018-10-26 17:39:23 -0700800 case EVENT_RESET_MODEM_CONFIG_DONE:
801 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800802 break;
803
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700804 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
805 request = (MainThreadRequest) msg.obj;
806 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
807 request);
808 Phone phone = getPhoneFromRequest(request);
809 if (phone != null) {
810 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
811 } else {
812 loge("isNRDualConnectivityEnabled: No phone object");
813 request.result = false;
814 notifyRequester(request);
815 }
816 break;
817 }
818
819 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null && ar.result != null) {
823 request.result = ar.result;
824 } else {
825 // request.result must be set to something non-null
826 // for the calling thread to unblock
827 if (request.result != null) {
828 request.result = ar.result;
829 } else {
830 request.result = false;
831 }
832 if (ar.result == null) {
833 loge("isNRDualConnectivityEnabled: Empty response");
834 } else if (ar.exception instanceof CommandException) {
835 loge("isNRDualConnectivityEnabled: CommandException: "
836 + ar.exception);
837 } else {
838 loge("isNRDualConnectivityEnabled: Unknown exception");
839 }
840 }
841 notifyRequester(request);
842 break;
843
844 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
847 Phone phone = getPhoneFromRequest(request);
848 if (phone != null) {
849 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
850 request.workSource);
851 } else {
852 loge("enableNrDualConnectivity: No phone object");
853 request.result =
854 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
855 notifyRequester(request);
856 }
857 break;
858 }
859
860 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
861 ar = (AsyncResult) msg.obj;
862 request = (MainThreadRequest) ar.userObj;
863 if (ar.exception == null) {
864 request.result =
865 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
866 } else {
867 request.result =
868 TelephonyManager
869 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
870 if (ar.exception instanceof CommandException) {
871 CommandException.Error error =
872 ((CommandException) (ar.exception)).getCommandError();
873 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
874 request.result =
875 TelephonyManager
876 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000877 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
878 request.result =
879 TelephonyManager
880 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700881 }
882 loge("enableNrDualConnectivity" + ": CommandException: "
883 + ar.exception);
884 } else {
885 loge("enableNrDualConnectivity" + ": Unknown exception");
886 }
887 }
888 notifyRequester(request);
889 break;
890 }
891
SongFerngWang9e060372020-12-21 16:41:52 +0800892 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800893 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800894 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
895 request);
896 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 break;
898
SongFerngWang9e060372020-12-21 16:41:52 +0800899 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 ar = (AsyncResult) msg.obj;
901 request = (MainThreadRequest) ar.userObj;
902 if (ar.exception == null && ar.result != null) {
903 request.result = ar.result; // Integer
904 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530905 // request.result must be set to something non-null
906 // for the calling thread to unblock
907 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800909 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800911 loge("getAllowedNetworkTypesBitmask: CommandException: "
912 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800913 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800914 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800915 }
916 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700917 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 break;
919
SongFerngWang9e060372020-12-21 16:41:52 +0800920 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800921 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800922 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
923 request);
924 Pair<Integer, Long> reasonWithNetworkTypes =
925 (Pair<Integer, Long>) request.argument;
926 getPhoneFromRequest(request).setAllowedNetworkTypes(
927 reasonWithNetworkTypes.first,
928 reasonWithNetworkTypes.second,
929 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800930 break;
931
SongFerngWang9e060372020-12-21 16:41:52 +0800932 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
933 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800934 break;
935
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000936 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
937 request = (MainThreadRequest)msg.obj;
938 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800939 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000940 break;
941
942 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
943 ar = (AsyncResult)msg.obj;
944 request = (MainThreadRequest)ar.userObj;
945 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700946 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000947 break;
948
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800949 case CMD_SET_VOICEMAIL_NUMBER:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
952 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800953 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
954 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800955 break;
956
957 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
958 handleNullReturnEvent(msg, "setVoicemailNumber");
959 break;
960
Stuart Scott54788802015-03-30 13:18:01 -0700961 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
964 request);
965 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
966 break;
967
968 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
969 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
970 break;
971
Shishir Agrawal302c8692015-06-19 13:49:39 -0700972 case CMD_PERFORM_NETWORK_SCAN:
973 request = (MainThreadRequest) msg.obj;
974 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
975 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
976 break;
977
Hall Liua1acea22020-09-18 19:04:59 -0700978 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800979 request = (MainThreadRequest) msg.obj;
980 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700981 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
982 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
983 request.argument;
984 int callForwardingReason = args.first;
985 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800986 break;
Hall Liua1acea22020-09-18 19:04:59 -0700987 }
988 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800989 ar = (AsyncResult) msg.obj;
990 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700991 TelephonyManager.CallForwardingInfoCallback callback =
992 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
993 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800994 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700995 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800996 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
997 for (CallForwardInfo callForwardInfo : callForwardInfos) {
998 // Service Class is a bit mask per 3gpp 27.007. Search for
999 // any service for voice call.
1000 if ((callForwardInfo.serviceClass
1001 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -07001002 callForwardingInfo = new CallForwardingInfo(true,
1003 callForwardInfo.reason,
1004 callForwardInfo.number,
1005 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -08001006 break;
1007 }
1008 }
1009 // Didn't find a call forward info for voice call.
1010 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -07001011 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1012 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001013 }
Hall Liua1acea22020-09-18 19:04:59 -07001014 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001015 } else {
1016 if (ar.result == null) {
1017 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1018 }
1019 if (ar.exception != null) {
1020 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1021 }
Hall Liuae527aa2020-09-29 17:10:18 -07001022 int errorCode = TelephonyManager
1023 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001024 if (ar.exception instanceof CommandException) {
1025 CommandException.Error error =
1026 ((CommandException) (ar.exception)).getCommandError();
1027 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001028 errorCode = TelephonyManager
1029 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001030 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001031 errorCode = TelephonyManager
1032 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001033 }
1034 }
Hall Liua1acea22020-09-18 19:04:59 -07001035 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001036 }
sqian80370722020-01-29 15:02:51 -08001037 break;
Hall Liua1acea22020-09-18 19:04:59 -07001038 }
sqian80370722020-01-29 15:02:51 -08001039
Hall Liua1acea22020-09-18 19:04:59 -07001040 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001041 request = (MainThreadRequest) msg.obj;
1042 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001043 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001044 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001045 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1046 request.argument).first;
1047 request.phone.setCallForwardingOption(
1048 callForwardingInfoToSet.isEnabled()
1049 ? CommandsInterface.CF_ACTION_ENABLE
1050 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001051 callForwardingInfoToSet.getReason(),
1052 callForwardingInfoToSet.getNumber(),
1053 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1054 break;
Hall Liua1acea22020-09-18 19:04:59 -07001055 }
sqian80370722020-01-29 15:02:51 -08001056
Hall Liua1acea22020-09-18 19:04:59 -07001057 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001060 Consumer<Integer> callback =
1061 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1062 request.argument).second;
1063 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001064 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001065 int errorCode = TelephonyManager.CallForwardingInfoCallback
1066 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001067 if (ar.exception instanceof CommandException) {
1068 CommandException.Error error =
1069 ((CommandException) (ar.exception)).getCommandError();
1070 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001071 errorCode = TelephonyManager.CallForwardingInfoCallback
1072 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001073 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001074 errorCode = TelephonyManager.CallForwardingInfoCallback
1075 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001076 }
1077 }
1078 callback.accept(errorCode);
1079 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001080 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001081 }
sqian80370722020-01-29 15:02:51 -08001082 break;
Hall Liua1acea22020-09-18 19:04:59 -07001083 }
sqian80370722020-01-29 15:02:51 -08001084
Hall Liua1acea22020-09-18 19:04:59 -07001085 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001086 request = (MainThreadRequest) msg.obj;
1087 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1088 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1089 break;
Hall Liua1acea22020-09-18 19:04:59 -07001090 }
sqian80370722020-01-29 15:02:51 -08001091
Hall Liua1acea22020-09-18 19:04:59 -07001092 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001095 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001096 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1097 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001098 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001099 // Service Class is a bit mask per 3gpp 27.007.
1100 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001101 if (callForwardResults.length > 1
1102 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001103 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001104 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001105 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1106 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001107 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001108 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001109 }
1110 } else {
1111 if (ar.result == null) {
1112 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1113 }
1114 if (ar.exception != null) {
1115 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1116 }
1117 if (ar.exception instanceof CommandException) {
1118 CommandException.Error error =
1119 ((CommandException) (ar.exception)).getCommandError();
1120 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1121 callForwardingStatus =
1122 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1123 }
1124 }
1125 }
Hall Liua1acea22020-09-18 19:04:59 -07001126 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001127 break;
Hall Liua1acea22020-09-18 19:04:59 -07001128 }
sqian80370722020-01-29 15:02:51 -08001129
Hall Liua1acea22020-09-18 19:04:59 -07001130 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001131 request = (MainThreadRequest) msg.obj;
1132 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001133 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1134 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001135 break;
Hall Liua1acea22020-09-18 19:04:59 -07001136 }
sqian80370722020-01-29 15:02:51 -08001137
Hall Liua1acea22020-09-18 19:04:59 -07001138 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001139 ar = (AsyncResult) msg.obj;
1140 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001141 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1142 Consumer<Integer> callback =
1143 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1144 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001145 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001146 if (ar.exception instanceof CommandException) {
1147 CommandException.Error error =
1148 ((CommandException) (ar.exception)).getCommandError();
1149 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1150 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1151 } else {
1152 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1153 }
1154 } else {
1155 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1156 }
1157 } else {
1158 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1159 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001160 }
sqian80370722020-01-29 15:02:51 -08001161 break;
Hall Liua1acea22020-09-18 19:04:59 -07001162 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001163 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1164 ar = (AsyncResult) msg.obj;
1165 request = (MainThreadRequest) ar.userObj;
1166 CellNetworkScanResult cellScanResult;
1167 if (ar.exception == null && ar.result != null) {
1168 cellScanResult = new CellNetworkScanResult(
1169 CellNetworkScanResult.STATUS_SUCCESS,
1170 (List<OperatorInfo>) ar.result);
1171 } else {
1172 if (ar.result == null) {
1173 loge("getCellNetworkScanResults: Empty response");
1174 }
1175 if (ar.exception != null) {
1176 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1177 }
1178 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1179 if (ar.exception instanceof CommandException) {
1180 CommandException.Error error =
1181 ((CommandException) (ar.exception)).getCommandError();
1182 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1183 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1184 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1185 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1186 }
1187 }
1188 cellScanResult = new CellNetworkScanResult(errorCode, null);
1189 }
1190 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001191 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001192 break;
1193
1194 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1195 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001196 ManualNetworkSelectionArgument selArg =
1197 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001198 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1199 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001200 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1201 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001202 break;
1203
1204 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001205 ar = (AsyncResult) msg.obj;
1206 request = (MainThreadRequest) ar.userObj;
1207 if (ar.exception == null) {
1208 request.result = true;
1209 } else {
1210 request.result = false;
1211 loge("setNetworkSelectionModeManual " + ar.exception);
1212 }
1213 notifyRequester(request);
1214 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001215 break;
1216
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001217 case CMD_GET_MODEM_ACTIVITY_INFO:
1218 request = (MainThreadRequest) msg.obj;
1219 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001220 if (defaultPhone != null) {
1221 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001222 } else {
1223 ResultReceiver result = (ResultReceiver) request.argument;
1224 Bundle bundle = new Bundle();
1225 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liue8315982020-10-09 19:00:11 -07001226 new ModemActivityInfo(0, 0, 0,
1227 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
sqian1a1be542020-03-05 11:37:28 -08001228 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001229 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001230 break;
1231
Hall Liudf4171d2020-10-14 16:54:44 -07001232 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001233 ar = (AsyncResult) msg.obj;
1234 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001235 ResultReceiver result = (ResultReceiver) request.argument;
1236
Hall Liudf4171d2020-10-14 16:54:44 -07001237 ModemActivityInfo ret = null;
1238 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001239 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001240 // Update the last modem activity info and the result of the request.
1241 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1242 if (isModemActivityInfoValid(info)) {
Hall Liue8315982020-10-09 19:00:11 -07001243 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
sqian1a1be542020-03-05 11:37:28 -08001244 int[] txTimeMs = info.getTransmitTimeMillis();
1245 int[] lastModemTxTimeMs = mLastModemActivityInfo
1246 .getTransmitTimeMillis();
1247 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1248 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1249 }
Hall Liue8315982020-10-09 19:00:11 -07001250 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
sqian1a1be542020-03-05 11:37:28 -08001251 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1252 + mLastModemActivityInfo.getSleepTimeMillis());
1253 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1254 + mLastModemActivityInfo.getIdleTimeMillis());
1255 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1256 mLastModemActivityInfo.setReceiveTimeMillis(
1257 info.getReceiveTimeMillis()
1258 + mLastModemActivityInfo.getReceiveTimeMillis());
1259 }
Hall Liue8315982020-10-09 19:00:11 -07001260 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
sqian1a1be542020-03-05 11:37:28 -08001261 mLastModemActivityInfo.getSleepTimeMillis(),
1262 mLastModemActivityInfo.getIdleTimeMillis(),
1263 mLastModemActivityInfo.getTransmitTimeMillis(),
1264 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001265 } else {
1266 if (ar.result == null) {
1267 loge("queryModemActivityInfo: Empty response");
Hall Liudf4171d2020-10-14 16:54:44 -07001268 error = TelephonyManager.ModemActivityInfoException
1269 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001270 } else if (ar.exception instanceof CommandException) {
1271 loge("queryModemActivityInfo: CommandException: " +
1272 ar.exception);
Hall Liudf4171d2020-10-14 16:54:44 -07001273 error = TelephonyManager.ModemActivityInfoException
1274 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001275 } else {
1276 loge("queryModemActivityInfo: Unknown exception");
Hall Liudf4171d2020-10-14 16:54:44 -07001277 error = TelephonyManager.ModemActivityInfoException
1278 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001279 }
1280 }
sqian1a1be542020-03-05 11:37:28 -08001281 Bundle bundle = new Bundle();
Hall Liudf4171d2020-10-14 16:54:44 -07001282 if (ret != null) {
1283 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1284 } else {
1285 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1286 }
sqian1a1be542020-03-05 11:37:28 -08001287 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001288 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001289 break;
Hall Liudf4171d2020-10-14 16:54:44 -07001290 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001291
Meng Wang1a7c35a2016-05-05 20:56:15 -07001292 case CMD_SET_ALLOWED_CARRIERS:
1293 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001294 CarrierRestrictionRules argument =
1295 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001296 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001297 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001298 break;
1299
1300 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1301 ar = (AsyncResult) msg.obj;
1302 request = (MainThreadRequest) ar.userObj;
1303 if (ar.exception == null && ar.result != null) {
1304 request.result = ar.result;
1305 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001306 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1307 if (ar.exception instanceof CommandException) {
1308 loge("setAllowedCarriers: CommandException: " + ar.exception);
1309 CommandException.Error error =
1310 ((CommandException) (ar.exception)).getCommandError();
1311 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1312 request.result =
1313 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1314 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001315 } else {
1316 loge("setAllowedCarriers: Unknown exception");
1317 }
1318 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001319 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001320 break;
1321
1322 case CMD_GET_ALLOWED_CARRIERS:
1323 request = (MainThreadRequest) msg.obj;
1324 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001325 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001326 break;
1327
1328 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1329 ar = (AsyncResult) msg.obj;
1330 request = (MainThreadRequest) ar.userObj;
1331 if (ar.exception == null && ar.result != null) {
1332 request.result = ar.result;
1333 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001334 request.result = new IllegalStateException(
1335 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001336 if (ar.result == null) {
1337 loge("getAllowedCarriers: Empty response");
1338 } else if (ar.exception instanceof CommandException) {
1339 loge("getAllowedCarriers: CommandException: " +
1340 ar.exception);
1341 } else {
1342 loge("getAllowedCarriers: Unknown exception");
1343 }
1344 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001345 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001346 break;
1347
Nathan Haroldb3014052017-01-25 15:57:32 -08001348 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1349 ar = (AsyncResult) msg.obj;
1350 request = (MainThreadRequest) ar.userObj;
1351 if (ar.exception == null && ar.result != null) {
1352 request.result = ar.result;
1353 } else {
1354 request.result = new IllegalArgumentException(
1355 "Failed to retrieve Forbidden Plmns");
1356 if (ar.result == null) {
1357 loge("getForbiddenPlmns: Empty response");
1358 } else {
1359 loge("getForbiddenPlmns: Unknown exception");
1360 }
1361 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001362 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001363 break;
1364
1365 case CMD_GET_FORBIDDEN_PLMNS:
1366 request = (MainThreadRequest) msg.obj;
1367 uiccCard = getUiccCardFromRequest(request);
1368 if (uiccCard == null) {
1369 loge("getForbiddenPlmns() UiccCard is null");
1370 request.result = new IllegalArgumentException(
1371 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001372 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001373 break;
1374 }
1375 Integer appType = (Integer) request.argument;
1376 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1377 if (uiccApp == null) {
1378 loge("getForbiddenPlmns() no app with specified type -- "
1379 + appType);
1380 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001381 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001382 break;
1383 } else {
1384 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1385 + " specified type -- " + appType);
1386 }
1387 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1388 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1389 onCompleted);
1390 break;
1391
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001392 case CMD_SWITCH_SLOTS:
1393 request = (MainThreadRequest) msg.obj;
1394 int[] physicalSlots = (int[]) request.argument;
1395 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1396 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1397 break;
1398
1399 case EVENT_SWITCH_SLOTS_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001403 notifyRequester(request);
1404 break;
1405 case CMD_GET_NETWORK_SELECTION_MODE:
1406 request = (MainThreadRequest) msg.obj;
1407 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1408 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1409 break;
1410
1411 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 if (ar.exception != null) {
1415 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1416 } else {
1417 int mode = ((int[]) ar.result)[0];
1418 if (mode == 0) {
1419 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1420 } else {
1421 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1422 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001423 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001424 notifyRequester(request);
1425 break;
1426 case CMD_GET_CDMA_ROAMING_MODE:
1427 request = (MainThreadRequest) msg.obj;
1428 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1429 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1430 break;
1431 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1432 ar = (AsyncResult) msg.obj;
1433 request = (MainThreadRequest) ar.userObj;
1434 if (ar.exception != null) {
1435 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1436 } else {
1437 request.result = ((int[]) ar.result)[0];
1438 }
1439 notifyRequester(request);
1440 break;
1441 case CMD_SET_CDMA_ROAMING_MODE:
1442 request = (MainThreadRequest) msg.obj;
1443 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1444 int mode = (int) request.argument;
1445 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1446 break;
1447 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1448 ar = (AsyncResult) msg.obj;
1449 request = (MainThreadRequest) ar.userObj;
1450 request.result = ar.exception == null;
1451 notifyRequester(request);
1452 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001453 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1454 request = (MainThreadRequest) msg.obj;
1455 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1456 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1457 break;
1458 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1459 ar = (AsyncResult) msg.obj;
1460 request = (MainThreadRequest) ar.userObj;
1461 if (ar.exception != null) {
1462 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1463 } else {
1464 request.result = ((int[]) ar.result)[0];
1465 }
1466 notifyRequester(request);
1467 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001468 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1469 request = (MainThreadRequest) msg.obj;
1470 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1471 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001472 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1473 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001474 break;
1475 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1476 ar = (AsyncResult) msg.obj;
1477 request = (MainThreadRequest) ar.userObj;
1478 request.result = ar.exception == null;
1479 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001480 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001481 case CMD_GET_ALL_CELL_INFO:
1482 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001483 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001484 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001485 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001486 case EVENT_GET_ALL_CELL_INFO_DONE:
1487 ar = (AsyncResult) msg.obj;
1488 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001489 // If a timeout occurs, the response will be null
1490 request.result = (ar.exception == null && ar.result != null)
1491 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 synchronized (request) {
1493 request.notifyAll();
1494 }
1495 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001496 case CMD_REQUEST_CELL_INFO_UPDATE:
1497 request = (MainThreadRequest) msg.obj;
1498 request.phone.requestCellInfoUpdate(request.workSource,
1499 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1500 break;
1501 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1502 ar = (AsyncResult) msg.obj;
1503 request = (MainThreadRequest) ar.userObj;
1504 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1505 try {
1506 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001507 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001508 cb.onError(
1509 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1510 ar.exception.getClass().getName(),
1511 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001512 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001513 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001514 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001515 } else {
1516 // use the result as returned
1517 cb.onCellInfo((List<CellInfo>) ar.result);
1518 }
1519 } catch (RemoteException re) {
1520 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1521 }
1522 break;
Sarah Chincc055732020-11-18 13:39:35 -08001523 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001524 request = (MainThreadRequest) msg.obj;
1525 WorkSource ws = (WorkSource) request.argument;
1526 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001527 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001528 break;
Sarah Chincc055732020-11-18 13:39:35 -08001529 }
1530 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001531 ar = (AsyncResult) msg.obj;
1532 request = (MainThreadRequest) ar.userObj;
1533 if (ar.exception == null) {
1534 request.result = ar.result;
1535 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001536 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001537 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001538 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001539 }
1540
1541 synchronized (request) {
1542 request.notifyAll();
1543 }
1544 break;
Sarah Chincc055732020-11-18 13:39:35 -08001545 }
chen xu6dac5ab2018-10-26 17:39:23 -07001546 case CMD_MODEM_REBOOT:
1547 request = (MainThreadRequest) msg.obj;
1548 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001549 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001550 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001551 case EVENT_CMD_MODEM_REBOOT_DONE:
1552 handleNullReturnEvent(msg, "rebootModem");
1553 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001554 case CMD_REQUEST_ENABLE_MODEM:
1555 request = (MainThreadRequest) msg.obj;
1556 boolean enable = (boolean) request.argument;
1557 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001558 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001559 PhoneConfigurationManager.getInstance()
1560 .enablePhone(request.phone, enable, onCompleted);
1561 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001562 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001563 ar = (AsyncResult) msg.obj;
1564 request = (MainThreadRequest) ar.userObj;
1565 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001566 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001567 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001568 if ((boolean) request.result) {
1569 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1570 updateModemStateMetrics();
1571 } else {
1572 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1573 + ar.exception);
1574 }
1575 notifyRequester(request);
1576 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001577 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001578 case CMD_GET_MODEM_STATUS:
1579 request = (MainThreadRequest) msg.obj;
1580 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1581 PhoneConfigurationManager.getInstance()
1582 .getPhoneStatusFromModem(request.phone, onCompleted);
1583 break;
1584 case EVENT_GET_MODEM_STATUS_DONE:
1585 ar = (AsyncResult) msg.obj;
1586 request = (MainThreadRequest) ar.userObj;
1587 int id = request.phone.getPhoneId();
1588 if (ar.exception == null && ar.result != null) {
1589 request.result = ar.result;
1590 //update the cache as modem status has changed
1591 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1592 (boolean) request.result);
1593 } else {
1594 // Return true if modem status cannot be retrieved. For most cases,
1595 // modem status is on. And for older version modems, GET_MODEM_STATUS
1596 // and disable modem are not supported. Modem is always on.
1597 // TODO: this should be fixed in R to support a third
1598 // status UNKNOWN b/131631629
1599 request.result = true;
1600 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1601 + ar.exception);
1602 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001603 notifyRequester(request);
1604 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001605 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1606 request = (MainThreadRequest) msg.obj;
1607 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1608 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1609 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1610 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1611 break;
1612 }
1613 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1614 ar = (AsyncResult) msg.obj;
1615 request = (MainThreadRequest) ar.userObj;
1616 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1617 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1618 args.second.accept(ar.exception == null);
1619 notifyRequester(request);
1620 break;
1621 }
Sarah Chincc055732020-11-18 13:39:35 -08001622 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1623 request = (MainThreadRequest) msg.obj;
1624 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1625 Phone phone = getPhoneFromRequest(request);
1626 if (phone != null) {
1627 phone.getSystemSelectionChannels(onCompleted);
1628 } else {
1629 loge("getSystemSelectionChannels: No phone object");
1630 request.result = new ArrayList<RadioAccessSpecifier>();
1631 notifyRequester(request);
1632 }
1633 break;
1634 }
1635 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1636 ar = (AsyncResult) msg.obj;
1637 request = (MainThreadRequest) ar.userObj;
1638 if (ar.exception == null && ar.result != null) {
1639 request.result = ar.result;
1640 } else {
Sarah Chin58691872021-03-13 03:17:40 -08001641 request.result = new IllegalStateException(
1642 "Failed to retrieve system selecton channels");
Sarah Chincc055732020-11-18 13:39:35 -08001643 if (ar.result == null) {
1644 loge("getSystemSelectionChannels: Empty response");
1645 } else {
1646 loge("getSystemSelectionChannels: Unknown exception");
1647 }
1648 }
1649 notifyRequester(request);
1650 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001651 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1652 ar = (AsyncResult) msg.obj;
1653 request = (MainThreadRequest) ar.userObj;
1654 if (ar.exception == null && ar.result != null) {
1655 request.result = ar.result;
1656 } else {
1657 request.result = -1;
1658 loge("Failed to set Forbidden Plmns");
1659 if (ar.result == null) {
1660 loge("setForbidenPlmns: Empty response");
1661 } else if (ar.exception != null) {
1662 loge("setForbiddenPlmns: Exception: " + ar.exception);
1663 request.result = -1;
1664 } else {
1665 loge("setForbiddenPlmns: Unknown exception");
1666 }
1667 }
1668 notifyRequester(request);
1669 break;
1670 case CMD_SET_FORBIDDEN_PLMNS:
1671 request = (MainThreadRequest) msg.obj;
1672 uiccCard = getUiccCardFromRequest(request);
1673 if (uiccCard == null) {
1674 loge("setForbiddenPlmns: UiccCard is null");
1675 request.result = -1;
1676 notifyRequester(request);
1677 break;
1678 }
1679 Pair<Integer, List<String>> setFplmnsArgs =
1680 (Pair<Integer, List<String>>) request.argument;
1681 appType = setFplmnsArgs.first;
1682 List<String> fplmns = setFplmnsArgs.second;
1683 uiccApp = uiccCard.getApplicationByType(appType);
1684 if (uiccApp == null) {
1685 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1686 request.result = -1;
1687 loge("Failed to get UICC App");
1688 notifyRequester(request);
1689 } else {
1690 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1691 ((SIMRecords) uiccApp.getIccRecords())
1692 .setForbiddenPlmns(onCompleted, fplmns);
1693 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001694 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001695 case CMD_ERASE_MODEM_CONFIG:
1696 request = (MainThreadRequest) msg.obj;
1697 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1698 defaultPhone.eraseModemConfig(onCompleted);
1699 break;
1700 case EVENT_ERASE_MODEM_CONFIG_DONE:
1701 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001702 break;
zoey chenf95ca592019-12-30 16:11:23 +08001703
1704 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1707 Pair<String, String> changed = (Pair<String, String>) request.argument;
1708 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1709 changed.first, changed.second, onCompleted);
1710 break;
1711 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1712 ar = (AsyncResult) msg.obj;
1713 request = (MainThreadRequest) ar.userObj;
1714 if (ar.exception == null) {
1715 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001716 // If the operation is successful, update the PIN storage
1717 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1718 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001719 UiccController.getInstance().getPinStorage()
1720 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001721 } else {
1722 request.result = msg.arg1;
1723 }
1724 notifyRequester(request);
1725 break;
1726
Michele Berionned9fbae52020-11-13 02:36:59 +00001727 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001728 request = (MainThreadRequest) msg.obj;
1729 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1730 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1731 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1732 enabled.first, enabled.second, onCompleted);
1733 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001734 }
zoey chenf95ca592019-12-30 16:11:23 +08001735 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1736 ar = (AsyncResult) msg.obj;
1737 request = (MainThreadRequest) ar.userObj;
1738 if (ar.exception == null) {
1739 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001740 // If the operation is successful, update the PIN storage
1741 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1742 int phoneId = getPhoneFromRequest(request).getPhoneId();
1743 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001744 UiccController.getInstance().getPinStorage()
1745 .storePin(enabled.second, phoneId);
Michele Berionned9fbae52020-11-13 02:36:59 +00001746 } else {
1747 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1748 }
zoey chenf95ca592019-12-30 16:11:23 +08001749 } else {
1750 request.result = msg.arg1;
1751 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001752
1753
zoey chenf95ca592019-12-30 16:11:23 +08001754 notifyRequester(request);
1755 break;
1756
Peter Wangdafb9ac2020-01-15 14:13:38 -08001757 case MSG_NOTIFY_USER_ACTIVITY:
1758 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001759 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001760 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1761 getDefaultPhone().getContext().sendBroadcastAsUser(
1762 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1763 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001764
1765 case CMD_SET_DATA_THROTTLING: {
1766 request = (MainThreadRequest) msg.obj;
1767 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1768 DataThrottlingRequest dataThrottlingRequest =
1769 (DataThrottlingRequest) request.argument;
1770 Phone phone = getPhoneFromRequest(request);
1771 if (phone != null) {
1772 phone.setDataThrottling(onCompleted,
1773 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1774 dataThrottlingRequest.getCompletionDurationMillis());
1775 } else {
1776 loge("setDataThrottling: No phone object");
1777 request.result =
1778 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1779 notifyRequester(request);
1780 }
1781
1782 break;
1783 }
1784 case EVENT_SET_DATA_THROTTLING_DONE:
1785 ar = (AsyncResult) msg.obj;
1786 request = (MainThreadRequest) ar.userObj;
1787
1788 if (ar.exception == null) {
1789 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1790 } else if (ar.exception instanceof CommandException) {
1791 loge("setDataThrottling: CommandException: " + ar.exception);
1792 CommandException.Error error =
1793 ((CommandException) (ar.exception)).getCommandError();
1794
1795 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1796 request.result = TelephonyManager
1797 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1798 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1799 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001800 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1801 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001802 } else {
1803 request.result =
1804 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1805 }
1806 } else {
1807 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1808 }
1809 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1810 notifyRequester(request);
1811 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001812
1813 case CMD_SET_SIM_POWER: {
1814 request = (MainThreadRequest) msg.obj;
1815 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1816 request = (MainThreadRequest) msg.obj;
1817 int stateToSet =
1818 ((Pair<Integer, IIntegerConsumer>)
1819 request.argument).first;
1820 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1821 break;
1822 }
1823 case EVENT_SET_SIM_POWER_DONE: {
1824 ar = (AsyncResult) msg.obj;
1825 request = (MainThreadRequest) ar.userObj;
1826 IIntegerConsumer callback =
1827 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1828 if (ar.exception != null) {
1829 loge("setSimPower exception: " + ar.exception);
1830 int errorCode = TelephonyManager.CallForwardingInfoCallback
1831 .RESULT_ERROR_UNKNOWN;
1832 if (ar.exception instanceof CommandException) {
1833 CommandException.Error error =
1834 ((CommandException) (ar.exception)).getCommandError();
1835 if (error == CommandException.Error.SIM_ERR) {
1836 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1837 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1838 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1839 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1840 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1841 } else {
1842 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1843 }
1844 }
1845 try {
1846 callback.accept(errorCode);
1847 } catch (RemoteException e) {
1848 // Ignore if the remote process is no longer available to call back.
1849 Log.w(LOG_TAG, "setSimPower: callback not available.");
1850 }
1851 } else {
1852 try {
1853 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1854 } catch (RemoteException e) {
1855 // Ignore if the remote process is no longer available to call back.
1856 Log.w(LOG_TAG, "setSimPower: callback not available.");
1857 }
1858 }
1859 break;
1860 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001861 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1862 request = (MainThreadRequest) msg.obj;
1863
1864 final Phone phone = getPhoneFromRequest(request);
1865 if (phone == null || phone.getServiceStateTracker() == null) {
1866 request.result = new IllegalStateException("Phone or SST is null");
1867 notifyRequester(request);
1868 break;
1869 }
1870
1871 Pair<Integer, SignalStrengthUpdateRequest> pair =
1872 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1873 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1874 request);
1875 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1876 request.subId, pair.first /*callingUid*/,
1877 pair.second /*request*/, onCompleted);
1878 break;
1879 }
1880 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1881 ar = (AsyncResult) msg.obj;
1882 request = (MainThreadRequest) ar.userObj;
1883 // request.result will be the exception of ar if present, true otherwise.
1884 // Be cautious not to leave result null which will wait() forever
1885 request.result = ar.exception != null ? ar.exception : true;
1886 notifyRequester(request);
1887 break;
1888 }
1889 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1890 request = (MainThreadRequest) msg.obj;
1891
1892 Phone phone = getPhoneFromRequest(request);
1893 if (phone == null || phone.getServiceStateTracker() == null) {
1894 request.result = new IllegalStateException("Phone or SST is null");
1895 notifyRequester(request);
1896 break;
1897 }
1898
1899 Pair<Integer, SignalStrengthUpdateRequest> pair =
1900 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1901 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1902 request);
1903 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1904 request.subId, pair.first /*callingUid*/,
1905 pair.second /*request*/, onCompleted);
1906 break;
1907 }
1908 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1909 ar = (AsyncResult) msg.obj;
1910 request = (MainThreadRequest) ar.userObj;
1911 request.result = ar.exception != null ? ar.exception : true;
1912 notifyRequester(request);
1913 break;
1914 }
Jordan Liud5366d92020-11-24 14:50:34 -08001915
Hongbo Zengd31d3a32021-02-08 21:50:28 +08001916 case CMD_GET_SLICING_CONFIG: {
1917 request = (MainThreadRequest) msg.obj;
1918 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1919 request.phone.getSlicingConfig(onCompleted);
1920 break;
1921 }
1922 case EVENT_GET_SLICING_CONFIG_DONE: {
1923 ar = (AsyncResult) msg.obj;
1924 request = (MainThreadRequest) ar.userObj;
1925 ResultReceiver result = (ResultReceiver) request.argument;
1926
1927 SlicingConfig slicingConfig = null;
1928 Bundle bundle = new Bundle();
1929 int resultCode = 0;
1930 if (ar.exception != null) {
1931 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1932 + ar.exception);
1933 resultCode = TelephonyManager.SlicingException.ERROR_MODEM_ERROR;
1934 } else if (ar.result == null) {
1935 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
1936 resultCode = TelephonyManager.SlicingException.ERROR_TIMEOUT;
1937 } else {
1938 // use the result as returned
1939 resultCode = TelephonyManager.SlicingException.SUCCESS;
1940 slicingConfig = (SlicingConfig) ar.result;
1941 }
1942
1943 if (slicingConfig == null) {
1944 slicingConfig = new SlicingConfig();
1945 }
1946 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1947 result.send(resultCode, bundle);
1948 notifyRequester(request);
1949 break;
1950 }
1951
Michele Berionned9fbae52020-11-13 02:36:59 +00001952 case CMD_PREPARE_UNATTENDED_REBOOT:
1953 request = (MainThreadRequest) msg.obj;
1954 request.result =
1955 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1956 notifyRequester(request);
1957 break;
1958
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 default:
1960 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1961 break;
1962 }
1963 }
Jake Hambye994d462014-02-03 13:10:13 -08001964
Pengquan Menga1bb6272018-09-06 09:59:22 -07001965 private void notifyRequester(MainThreadRequest request) {
1966 synchronized (request) {
1967 request.notifyAll();
1968 }
1969 }
1970
Jake Hambye994d462014-02-03 13:10:13 -08001971 private void handleNullReturnEvent(Message msg, String command) {
1972 AsyncResult ar = (AsyncResult) msg.obj;
1973 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1974 if (ar.exception == null) {
1975 request.result = true;
1976 } else {
1977 request.result = false;
1978 if (ar.exception instanceof CommandException) {
1979 loge(command + ": CommandException: " + ar.exception);
1980 } else {
1981 loge(command + ": Unknown exception");
1982 }
1983 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001984 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001985 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001986 }
1987
1988 /**
1989 * Posts the specified command to be executed on the main thread,
1990 * waits for the request to complete, and returns the result.
1991 * @see #sendRequestAsync
1992 */
1993 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001994 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1995 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001996 }
1997
1998 /**
1999 * Posts the specified command to be executed on the main thread,
2000 * waits for the request to complete, and returns the result.
2001 * @see #sendRequestAsync
2002 */
2003 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2004 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002005 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002006 }
2007
2008 /**
2009 * Posts the specified command to be executed on the main thread,
2010 * waits for the request to complete, and returns the result.
2011 * @see #sendRequestAsync
2012 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002013 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002014 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2015 }
2016
2017 /**
2018 * Posts the specified command to be executed on the main thread,
2019 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2020 * if not timeout or null otherwise.
2021 * @see #sendRequestAsync
2022 */
2023 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2024 long timeoutInMs) {
2025 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002026 }
2027
2028 /**
2029 * Posts the specified command to be executed on the main thread,
2030 * waits for the request to complete, and returns the result.
2031 * @see #sendRequestAsync
2032 */
Nathan Harold92bed182018-10-12 18:16:49 -07002033 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002034 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002035 }
2036
2037 /**
2038 * Posts the specified command to be executed on the main thread,
2039 * waits for the request to complete, and returns the result.
2040 * @see #sendRequestAsync
2041 */
2042 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002043 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2044 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002045 }
2046
2047 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002048 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2049 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2050 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002051 * @see #sendRequestAsync
2052 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002053 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2054 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2056 throw new RuntimeException("This method will deadlock if called from the main thread.");
2057 }
2058
Nathan Harold92bed182018-10-12 18:16:49 -07002059 MainThreadRequest request = null;
2060 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2061 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2062 } else if (phone != null) {
2063 request = new MainThreadRequest(argument, phone, workSource);
2064 } else {
2065 request = new MainThreadRequest(argument, subId, workSource);
2066 }
2067
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 Message msg = mMainThreadHandler.obtainMessage(command, request);
2069 msg.sendToTarget();
2070
Rambo Wang0f050d82021-02-12 11:43:36 -08002071
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002073 if (timeoutInMs >= 0) {
2074 // Wait for at least timeoutInMs before returning null request result
2075 long now = SystemClock.elapsedRealtime();
2076 long deadline = now + timeoutInMs;
2077 while (request == null && now < deadline) {
2078 try {
2079 request.wait(deadline - now);
2080 } catch (InterruptedException e) {
2081 // Do nothing, go back and check if request is completed or timeout
2082 } finally {
2083 now = SystemClock.elapsedRealtime();
2084 }
2085 }
2086 } else {
2087 // Wait for the request to complete
2088 while (request.result == null) {
2089 try {
2090 request.wait();
2091 } catch (InterruptedException e) {
2092 // Do nothing, go back and wait until the request is complete
2093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 }
2095 }
2096 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002097 if (request.result == null) {
2098 Log.wtf(LOG_TAG,
2099 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 return request.result;
2102 }
2103
2104 /**
2105 * Asynchronous ("fire and forget") version of sendRequest():
2106 * Posts the specified command to be executed on the main thread, and
2107 * returns immediately.
2108 * @see #sendRequest
2109 */
2110 private void sendRequestAsync(int command) {
2111 mMainThreadHandler.sendEmptyMessage(command);
2112 }
2113
2114 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002115 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002116 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002117 */
2118 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002119 sendRequestAsync(command, argument, null, null);
2120 }
2121
2122 /**
2123 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2124 * @see {@link #sendRequest(int,Object)}
2125 */
2126 private void sendRequestAsync(
2127 int command, Object argument, Phone phone, WorkSource workSource) {
2128 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002129 Message msg = mMainThreadHandler.obtainMessage(command, request);
2130 msg.sendToTarget();
2131 }
2132
2133 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 * Initialize the singleton PhoneInterfaceManager instance.
2135 * This is only done once, at startup, from PhoneApp.onCreate().
2136 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002137 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 synchronized (PhoneInterfaceManager.class) {
2139 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002140 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 } else {
2142 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2143 }
2144 return sInstance;
2145 }
2146 }
2147
2148 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002149 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerc9c432e2021-05-17 20:54:49 +00002152 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002153 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2155 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002156 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002157 mTelephonySharedPreferences =
2158 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002159 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002160 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08002161 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002162 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002163
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 publish();
2165 }
2166
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002167 private Phone getDefaultPhone() {
2168 Phone thePhone = getPhone(getDefaultSubscription());
2169 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2170 }
2171
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 private void publish() {
2173 if (DBG) log("publish: " + this);
2174
Peter Wangc035ce42020-01-08 21:00:22 -08002175 TelephonyFrameworkInitializer
2176 .getTelephonyServiceManager()
2177 .getTelephonyServiceRegisterer()
2178 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 }
2180
Stuart Scott584921c2015-01-15 17:10:34 -08002181 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002182 if (request.phone != null) {
2183 return request.phone;
2184 } else {
2185 return getPhoneFromSubId(request.subId);
2186 }
2187 }
2188
2189 private Phone getPhoneFromSubId(int subId) {
2190 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2191 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002192 }
2193
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002194 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2195 Phone phone = getPhoneFromRequest(request);
2196 return phone == null ? null :
2197 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2198 }
2199
Wink Saville36469e72014-06-11 15:17:00 -07002200 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002201 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002202 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002205 private void sendEraseModemConfig(Phone phone) {
2206 if (phone != null) {
2207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2208 mApp, phone.getSubId(), "eraseModemConfig");
2209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2212 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2213 } finally {
2214 Binder.restoreCallingIdentity(identity);
2215 }
2216 }
2217 }
2218
Peter Wang050bb052020-01-13 23:33:09 -08002219 private boolean isImsAvailableOnDevice() {
2220 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2221 if (pm == null) {
2222 // For some reason package manger is not available.. This will fail internally anyway,
2223 // so do not throw error and allow.
2224 return true;
2225 }
2226 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2227 }
2228
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002230 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002231 }
2232
Wink Savilleb564aae2014-10-23 10:18:09 -07002233 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 if (DBG) log("dial: " + number);
2235 // No permission check needed here: This is just a wrapper around the
2236 // ACTION_DIAL intent, which is available to any app since it puts up
2237 // the UI before it does anything.
2238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 String url = createTelUrl(number);
2242 if (url == null) {
2243 return;
2244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002246 // PENDING: should we just silently fail if phone is offhook or ringing?
2247 PhoneConstants.State state = mCM.getState(subId);
2248 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2249 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2250 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2251 mApp.startActivity(intent);
2252 }
2253 } finally {
2254 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 }
2256 }
2257
2258 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002259 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002260 }
2261
Wink Savilleb564aae2014-10-23 10:18:09 -07002262 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 if (DBG) log("call: " + number);
2264
2265 // This is just a wrapper around the ACTION_CALL intent, but we still
2266 // need to do a permission check since we're calling startActivity()
2267 // from the context of the phone app.
2268 enforceCallPermission();
2269
Jordan Liu1617b712019-07-10 15:06:26 -07002270 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 != AppOpsManager.MODE_ALLOWED) {
2272 return;
2273 }
2274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275 final long identity = Binder.clearCallingIdentity();
2276 try {
2277 String url = createTelUrl(number);
2278 if (url == null) {
2279 return;
2280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282 boolean isValid = false;
2283 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2284 if (slist != null) {
2285 for (SubscriptionInfo subInfoRecord : slist) {
2286 if (subInfoRecord.getSubscriptionId() == subId) {
2287 isValid = true;
2288 break;
2289 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002290 }
Wink Saville08874612014-08-31 19:19:58 -07002291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292 if (!isValid) {
2293 return;
2294 }
Wink Saville08874612014-08-31 19:19:58 -07002295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2297 intent.putExtra(SUBSCRIPTION_KEY, subId);
2298 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2299 mApp.startActivity(intent);
2300 } finally {
2301 Binder.restoreCallingIdentity(identity);
2302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 }
2304
Wink Savilleb564aae2014-10-23 10:18:09 -07002305 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002306 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002307 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2308 }
2309
Wink Savilleb564aae2014-10-23 10:18:09 -07002310 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002311 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002312 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2313 }
2314
Wink Savilleb564aae2014-10-23 10:18:09 -07002315 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002317
2318 final long identity = Binder.clearCallingIdentity();
2319 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002320 Phone phone = getPhone(subId);
2321 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002322 checkSimPin.start();
2323 return checkSimPin.unlockSim(null, pin);
2324 } finally {
2325 Binder.restoreCallingIdentity(identity);
2326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 }
2328
Wink Savilleb564aae2014-10-23 10:18:09 -07002329 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002331
2332 final long identity = Binder.clearCallingIdentity();
2333 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002334 Phone phone = getPhone(subId);
2335 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002336 checkSimPuk.start();
2337 return checkSimPuk.unlockSim(puk, pin);
2338 } finally {
2339 Binder.restoreCallingIdentity(identity);
2340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 }
2342
2343 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002344 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 * a synchronous one.
2346 */
2347 private static class UnlockSim extends Thread {
2348
2349 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002350 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351
2352 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002353 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2354 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355
2356 // For replies from SimCard interface
2357 private Handler mHandler;
2358
2359 // For async handler to identify request type
2360 private static final int SUPPLY_PIN_COMPLETE = 100;
2361
Michele Berionned9fbae52020-11-13 02:36:59 +00002362 UnlockSim(int phoneId, IccCard simCard) {
2363 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 mSimCard = simCard;
2365 }
2366
2367 @Override
2368 public void run() {
2369 Looper.prepare();
2370 synchronized (UnlockSim.this) {
2371 mHandler = new Handler() {
2372 @Override
2373 public void handleMessage(Message msg) {
2374 AsyncResult ar = (AsyncResult) msg.obj;
2375 switch (msg.what) {
2376 case SUPPLY_PIN_COMPLETE:
2377 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2378 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002379 mRetryCount = msg.arg1;
2380 if (ar.exception != null) {
2381 if (ar.exception instanceof CommandException &&
2382 ((CommandException)(ar.exception)).getCommandError()
2383 == CommandException.Error.PASSWORD_INCORRECT) {
2384 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002385 } //When UiccCardApp dispose,handle message and return exception
2386 else if (ar.exception instanceof CommandException &&
2387 ((CommandException) (ar.exception)).getCommandError()
2388 == CommandException.Error.ABORTED) {
2389 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002390 } else {
2391 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2392 }
2393 } else {
2394 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 mDone = true;
2397 UnlockSim.this.notifyAll();
2398 }
2399 break;
2400 }
2401 }
2402 };
2403 UnlockSim.this.notifyAll();
2404 }
2405 Looper.loop();
2406 }
2407
2408 /*
2409 * Use PIN or PUK to unlock SIM card
2410 *
2411 * If PUK is null, unlock SIM card with PIN
2412 *
2413 * If PUK is not null, unlock SIM card with PUK and set PIN code
2414 */
Wink Saville9de0f752013-10-22 19:04:03 -07002415 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416
2417 while (mHandler == null) {
2418 try {
2419 wait();
2420 } catch (InterruptedException e) {
2421 Thread.currentThread().interrupt();
2422 }
2423 }
2424 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2425
2426 if (puk == null) {
2427 mSimCard.supplyPin(pin, callback);
2428 } else {
2429 mSimCard.supplyPuk(puk, pin, callback);
2430 }
2431
2432 while (!mDone) {
2433 try {
2434 Log.d(LOG_TAG, "wait for done");
2435 wait();
2436 } catch (InterruptedException e) {
2437 // Restore the interrupted status
2438 Thread.currentThread().interrupt();
2439 }
2440 }
2441 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002442 int[] resultArray = new int[2];
2443 resultArray[0] = mResult;
2444 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002445
2446 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002447 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionned9fbae52020-11-13 02:36:59 +00002448 }
2449
Wink Saville9de0f752013-10-22 19:04:03 -07002450 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 }
2452 }
2453
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002454 /**
2455 * This method has been removed due to privacy and stability concerns.
2456 */
2457 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002459 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2460 return;
Wink Saville36469e72014-06-11 15:17:00 -07002461 }
2462
Nathan Harold1f889d82020-06-04 17:05:26 -07002463 @Override
2464 public void updateServiceLocationWithPackageName(String callingPackage) {
2465 mApp.getSystemService(AppOpsManager.class)
2466 .checkPackage(Binder.getCallingUid(), callingPackage);
2467
Nathan Haroldf096d982020-11-18 17:18:06 -08002468 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002469 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2470 // Callers targeting S have no business invoking this method.
2471 return;
2472 }
2473
2474 LocationAccessPolicy.LocationPermissionResult locationResult =
2475 LocationAccessPolicy.checkLocationPermission(mApp,
2476 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2477 .setCallingPackage(callingPackage)
2478 .setCallingFeatureId(null)
2479 .setCallingPid(Binder.getCallingPid())
2480 .setCallingUid(Binder.getCallingUid())
2481 .setMethod("updateServiceLocation")
2482 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2483 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2484 .build());
2485 // Apps that lack location permission have no business calling this method;
2486 // however, because no permission was declared in the public API, denials must
2487 // all be "soft".
2488 switch (locationResult) {
2489 case DENIED_HARD: /* fall through */
2490 case DENIED_SOFT:
2491 return;
2492 }
2493
2494 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002495 final long identity = Binder.clearCallingIdentity();
2496 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002497 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002499 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002500 }
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 }
2505
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002506 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002507 @Override
2508 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002509 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002510 }
2511
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002512
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002513 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002514 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2515 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2516 callingFeatureId);
2517 }
2518
2519 @Deprecated
2520 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002521 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002522 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2523 }
2524
2525 @Override
2526 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2527 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002529 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002530 return false;
2531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532
2533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 return isRadioOnForSubscriber(subId);
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
2538 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002539 }
2540
2541 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 final Phone phone = getPhone(subId);
2545 if (phone != null) {
2546 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2547 } else {
2548 return false;
2549 }
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554
2555 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002556 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 }
Wink Saville36469e72014-06-11 15:17:00 -07002558
Wink Savilleb564aae2014-10-23 10:18:09 -07002559 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561
2562 final long identity = Binder.clearCallingIdentity();
2563 try {
2564 final Phone phone = getPhone(subId);
2565 if (phone != null) {
2566 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2567 }
2568 } finally {
2569 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002570 }
Wink Saville36469e72014-06-11 15:17:00 -07002571 }
2572
2573 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002574 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002575 }
2576
Wink Savilleb564aae2014-10-23 10:18:09 -07002577 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002578 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579
2580 final long identity = Binder.clearCallingIdentity();
2581 try {
2582 final Phone phone = getPhone(subId);
2583 if (phone == null) {
2584 return false;
2585 }
2586 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2587 toggleRadioOnOffForSubscriber(subId);
2588 }
2589 return true;
2590 } finally {
2591 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002593 }
Wink Saville36469e72014-06-11 15:17:00 -07002594
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002595 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002596 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002597 /*
2598 * If any of the Radios are available, it will need to be
2599 * shutdown. So return true if any Radio is available.
2600 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 final long identity = Binder.clearCallingIdentity();
2602 try {
2603 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2604 Phone phone = PhoneFactory.getPhone(i);
2605 if (phone != null && phone.isRadioAvailable()) return true;
2606 }
2607 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2608 return false;
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002611 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002612 }
2613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002615 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 enforceModifyPermission();
2617
2618 final long identity = Binder.clearCallingIdentity();
2619 try {
2620 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2621 logv("Shutting down Phone " + i);
2622 shutdownRadioUsingPhoneId(i);
2623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002626 }
2627 }
2628
2629 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002630 Phone phone = PhoneFactory.getPhone(phoneId);
2631 if (phone != null && phone.isRadioAvailable()) {
2632 phone.shutdownRadio();
2633 }
2634 }
2635
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002636 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002637 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2642 if (defaultPhone != null) {
2643 defaultPhone.setRadioPower(turnOn);
2644 return true;
2645 } else {
2646 loge("There's no default phone.");
2647 return false;
2648 }
2649 } finally {
2650 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002651 }
Wink Saville36469e72014-06-11 15:17:00 -07002652 }
2653
Wink Savilleb564aae2014-10-23 10:18:09 -07002654 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002655 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656
2657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 final Phone phone = getPhone(subId);
2660 if (phone != null) {
2661 phone.setRadioPower(turnOn);
2662 return true;
2663 } else {
2664 return false;
2665 }
2666 } finally {
2667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002669 }
2670
Wink Saville36469e72014-06-11 15:17:00 -07002671 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002672 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002673 public boolean enableDataConnectivity() {
2674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675
2676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 int subId = mSubscriptionController.getDefaultDataSubId();
2679 final Phone phone = getPhone(subId);
2680 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002681 phone.getDataEnabledSettings().setDataEnabled(
2682 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 return true;
2684 } else {
2685 return false;
2686 }
2687 } finally {
2688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
2691
Wink Saville36469e72014-06-11 15:17:00 -07002692 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 public boolean disableDataConnectivity() {
2695 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 int subId = mSubscriptionController.getDefaultDataSubId();
2700 final Phone phone = getPhone(subId);
2701 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002702 phone.getDataEnabledSettings().setDataEnabled(
2703 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704 return true;
2705 } else {
2706 return false;
2707 }
2708 } finally {
2709 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002710 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002711 }
2712
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002714 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 final Phone phone = getPhone(subId);
2718 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002719 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 } else {
2721 return false;
2722 }
2723 } finally {
2724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 }
2727
2728 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002729 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002730 }
2731
pkanwarae03a6b2016-11-06 20:37:09 -08002732 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733 enforceCallPermission();
2734
2735 final long identity = Binder.clearCallingIdentity();
2736 try {
2737 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2738 return;
2739 }
2740 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2741 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
pkanwar32d516d2016-10-14 19:37:38 -07002745 };
2746
Wink Savilleb564aae2014-10-23 10:18:09 -07002747 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2753 return false;
2754 }
2755 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 }
2760
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002762 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002763 }
2764
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002765 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 Phone phone = PhoneFactory.getPhone(slotIndex);
2769 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2770 PhoneConstantConversions.convertCallState(phone.getState());
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
2773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 }
2775
Sanket Padawe356d7632015-06-22 14:03:32 -07002776 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002777 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002778 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2779 }
2780
2781 @Override
2782 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 final long identity = Binder.clearCallingIdentity();
2784 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002785 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 if (phone != null) {
2787 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2788 } else {
2789 return PhoneConstantConversions.convertDataState(
2790 PhoneConstants.DataState.DISCONNECTED);
2791 }
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 }
2796
Sanket Padawe356d7632015-06-22 14:03:32 -07002797 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002798 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002799 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2800 }
2801
2802 @Override
2803 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 final long identity = Binder.clearCallingIdentity();
2805 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002806 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 if (phone != null) {
2808 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2809 } else {
2810 return TelephonyManager.DATA_ACTIVITY_NONE;
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816
2817 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002818 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002819 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002820 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002821
2822 LocationAccessPolicy.LocationPermissionResult locationResult =
2823 LocationAccessPolicy.checkLocationPermission(mApp,
2824 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2825 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002826 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002827 .setCallingPid(Binder.getCallingPid())
2828 .setCallingUid(Binder.getCallingUid())
2829 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002830 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002831 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2832 .build());
2833 switch (locationResult) {
2834 case DENIED_HARD:
2835 throw new SecurityException("Not allowed to access cell location");
2836 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002837 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2838 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 }
2840
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002841 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002845 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002846 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847 } finally {
2848 Binder.restoreCallingIdentity(identity);
2849 }
Svetoslav64fad262015-04-14 14:35:21 -07002850 }
2851
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 @Override
Jack Yu01425032020-02-22 19:38:58 -08002853 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002854 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2855 // registered cell info, so return a NULL country instead.
2856 final long identity = Binder.clearCallingIdentity();
2857 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002858 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2859 // Get default phone in this case.
2860 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2861 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002862 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002864 if (phone == null) return "";
2865 ServiceStateTracker sst = phone.getServiceStateTracker();
2866 if (sst == null) return "";
2867 LocaleTracker lt = sst.getLocaleTracker();
2868 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002869 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002870 } finally {
2871 Binder.restoreCallingIdentity(identity);
2872 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002873 }
2874
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002875 /**
2876 * This method was removed due to potential issues caused by performing partial
2877 * updates of service state, and lack of a credible use case.
2878 *
2879 * This has the ability to break the telephony implementation by disabling notification of
2880 * changes in device connectivity. DO NOT USE THIS!
2881 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002882 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 public void enableLocationUpdates() {
2884 mApp.enforceCallingOrSelfPermission(
2885 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002886 }
2887
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002888 /**
2889 * This method was removed due to potential issues caused by performing partial
2890 * updates of service state, and lack of a credible use case.
2891 *
2892 * This has the ability to break the telephony implementation by disabling notification of
2893 * changes in device connectivity. DO NOT USE THIS!
2894 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 @Override
2896 public void disableLocationUpdates() {
2897 mApp.enforceCallingOrSelfPermission(
2898 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002899 }
2900
2901 @Override
2902 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002903 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2904 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002905 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002906 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2907 throw new SecurityException(
2908 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2909 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002910
Jordan Liu1617b712019-07-10 15:06:26 -07002911 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002912 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2913 return null;
2914 }
Svetoslav64fad262015-04-14 14:35:21 -07002915
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002916 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002917
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002918 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002919 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920
Nathan Haroldf180aac2018-06-01 18:43:55 -07002921 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2922 for (CellInfo ci : info) {
2923 if (ci instanceof CellInfoGsm) {
2924 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2925 } else if (ci instanceof CellInfoWcdma) {
2926 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002929 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002932 private List<CellInfo> getCachedCellInfo() {
2933 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2934 for (Phone phone : PhoneFactory.getPhones()) {
2935 List<CellInfo> info = phone.getAllCellInfo();
2936 if (info != null) cellInfos.addAll(info);
2937 }
2938 return cellInfos;
2939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940
2941 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002942 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002943 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002944 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002945
2946 LocationAccessPolicy.LocationPermissionResult locationResult =
2947 LocationAccessPolicy.checkLocationPermission(mApp,
2948 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2949 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002950 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002951 .setCallingPid(Binder.getCallingPid())
2952 .setCallingUid(Binder.getCallingUid())
2953 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002954 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002955 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2956 .build());
2957 switch (locationResult) {
2958 case DENIED_HARD:
2959 throw new SecurityException("Not allowed to access cell info");
2960 case DENIED_SOFT:
2961 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002962 }
2963
Nathan Haroldf096d982020-11-18 17:18:06 -08002964 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002965 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2966 return getCachedCellInfo();
2967 }
2968
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002969 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002970 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2974 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002975 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002976 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977 if (info != null) cellInfos.addAll(info);
2978 }
2979 return cellInfos;
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002982 }
2983 }
2984
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002985 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002986 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2987 String callingFeatureId) {
2988 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2989 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002990 }
2991
2992 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002993 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2994 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002995 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002996 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002997 }
2998
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002999 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3000 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003001 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003002 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003003
3004 LocationAccessPolicy.LocationPermissionResult locationResult =
3005 LocationAccessPolicy.checkLocationPermission(mApp,
3006 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3007 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003008 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003009 .setCallingPid(Binder.getCallingPid())
3010 .setCallingUid(Binder.getCallingUid())
3011 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07003012 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3013 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003014 .build());
3015 switch (locationResult) {
3016 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003017 if (TelephonyPermissions
3018 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07003019 // Safetynet logging for b/154934934
3020 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3021 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003022 throw new SecurityException("Not allowed to access cell info");
3023 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003024 if (TelephonyPermissions
3025 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07003026 // Safetynet logging for b/154934934
3027 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3028 }
Nathan Harold5320c422019-05-09 10:26:08 -07003029 try {
3030 cb.onCellInfo(new ArrayList<CellInfo>());
3031 } catch (RemoteException re) {
3032 // Drop without consequences
3033 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003034 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003035 }
3036
Nathan Harolda939a962019-05-09 10:13:47 -07003037
3038 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003039 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3040
3041 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3042 }
3043
3044 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003045 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003046 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003047 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003051 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003055 }
3056
Shishir Agrawala9f32182016-04-12 12:00:16 -07003057 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003058 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003059 Phone phone = PhoneFactory.getPhone(slotIndex);
3060 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003061 return null;
3062 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003063 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003064 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003065 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003066 return null;
3067 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003068
3069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 return phone.getImei();
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003075 }
3076
3077 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003078 public String getTypeAllocationCodeForSlot(int slotIndex) {
3079 Phone phone = PhoneFactory.getPhone(slotIndex);
3080 String tac = null;
3081 if (phone != null) {
3082 String imei = phone.getImei();
3083 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3084 }
3085 return tac;
3086 }
3087
3088 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003089 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003090 Phone phone = PhoneFactory.getPhone(slotIndex);
3091 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003092 return null;
3093 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003094
Jeff Davidson913390f2018-02-23 17:11:49 -08003095 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003096 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003097 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003098 return null;
3099 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003100
3101 final long identity = Binder.clearCallingIdentity();
3102 try {
3103 return phone.getMeid();
3104 } finally {
3105 Binder.restoreCallingIdentity(identity);
3106 }
Jack Yu2af8d712017-03-15 17:14:14 -07003107 }
3108
3109 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003110 public String getManufacturerCodeForSlot(int slotIndex) {
3111 Phone phone = PhoneFactory.getPhone(slotIndex);
3112 String manufacturerCode = null;
3113 if (phone != null) {
3114 String meid = phone.getMeid();
3115 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3116 }
3117 return manufacturerCode;
3118 }
3119
3120 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003121 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3122 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003123 Phone phone = PhoneFactory.getPhone(slotIndex);
3124 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003125 return null;
3126 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003127 int subId = phone.getSubId();
3128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003129 mApp, subId, callingPackage, callingFeatureId,
3130 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003131 return null;
3132 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003133
3134 final long identity = Binder.clearCallingIdentity();
3135 try {
3136 return phone.getDeviceSvn();
3137 } finally {
3138 Binder.restoreCallingIdentity(identity);
3139 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003140 }
3141
fionaxu43304da2017-11-27 22:51:16 -08003142 @Override
3143 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144 final long identity = Binder.clearCallingIdentity();
3145 try {
3146 final Phone phone = getPhone(subId);
3147 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
3150 }
fionaxu43304da2017-11-27 22:51:16 -08003151 }
3152
3153 @Override
3154 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003155 final long identity = Binder.clearCallingIdentity();
3156 try {
3157 final Phone phone = getPhone(subId);
3158 return phone == null ? null : phone.getCarrierName();
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
3161 }
fionaxu43304da2017-11-27 22:51:16 -08003162 }
3163
calvinpanffe225e2018-11-01 19:43:06 +08003164 @Override
chen xu0026ca62019-03-06 15:28:50 -08003165 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 final Phone phone = getPhone(subId);
3169 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003170 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003171 } finally {
3172 Binder.restoreCallingIdentity(identity);
3173 }
3174 }
3175
3176 @Override
chen xu0026ca62019-03-06 15:28:50 -08003177 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003178 final long identity = Binder.clearCallingIdentity();
3179 try {
3180 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003181 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003182 } finally {
3183 Binder.restoreCallingIdentity(identity);
3184 }
3185 }
3186
chen xu651eec72018-11-11 19:03:44 -08003187 @Override
chen xu864e11c2018-12-06 22:10:03 -08003188 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3189 if (!isSubscriptionMccMnc) {
3190 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3191 }
chen xu651eec72018-11-11 19:03:44 -08003192 final Phone phone = PhoneFactory.getPhone(slotIndex);
3193 if (phone == null) {
3194 return TelephonyManager.UNKNOWN_CARRIER_ID;
3195 }
3196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3199 } finally {
3200 Binder.restoreCallingIdentity(identity);
3201 }
3202 }
3203
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 //
3205 // Internal helper methods.
3206 //
3207
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003208 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3210 *
3211 * @throws SecurityException if the caller does not have the required permission
3212 */
3213 private void enforceModifyPermission() {
3214 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3215 }
3216
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003217 /**
3218 * Make sure the caller is system.
3219 *
3220 * @throws SecurityException if the caller is not system.
3221 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003222 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003223 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3224 throw new SecurityException("Caller must be system");
3225 }
3226 }
3227
Shuo Qianf2b2df42019-11-13 17:43:31 -08003228 private void enforceActiveEmergencySessionPermission() {
3229 mApp.enforceCallingOrSelfPermission(
3230 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3231 }
3232
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003233 /**
3234 * Make sure the caller has the CALL_PHONE permission.
3235 *
3236 * @throws SecurityException if the caller does not have the required permission
3237 */
3238 private void enforceCallPermission() {
3239 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3240 }
3241
paulhu423b5f22019-08-23 19:17:33 +08003242 private void enforceSettingsPermission() {
3243 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003244 }
3245
Michele Berionned9fbae52020-11-13 02:36:59 +00003246 private void enforceRebootPermission() {
3247 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3248 }
3249
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 private String createTelUrl(String number) {
3251 if (TextUtils.isEmpty(number)) {
3252 return null;
3253 }
3254
Jake Hambye994d462014-02-03 13:10:13 -08003255 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 }
3257
Ihab Awadf9e92732013-12-05 18:02:52 -08003258 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3260 }
3261
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003262 private static void logv(String msg) {
3263 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3264 }
3265
Ihab Awadf9e92732013-12-05 18:02:52 -08003266 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003267 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3268 }
3269
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003270 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003271 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003272 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003273 }
3274
Sanket Padawe356d7632015-06-22 14:03:32 -07003275 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003276 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277 final long identity = Binder.clearCallingIdentity();
3278 try {
3279 final Phone phone = PhoneFactory.getPhone(slotIndex);
3280 if (phone == null) {
3281 return PhoneConstants.PHONE_TYPE_NONE;
3282 } else {
3283 return phone.getPhoneType();
3284 }
3285 } finally {
3286 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003288 }
3289
3290 /**
3291 * Returns the CDMA ERI icon index to display
3292 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003293 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003294 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3295 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3296 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003297 }
3298
Sanket Padawe356d7632015-06-22 14:03:32 -07003299 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003300 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3301 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003302 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003303 mApp, subId, callingPackage, callingFeatureId,
3304 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003305 return -1;
3306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003307
3308 final long identity = Binder.clearCallingIdentity();
3309 try {
3310 final Phone phone = getPhone(subId);
3311 if (phone != null) {
3312 return phone.getCdmaEriIconIndex();
3313 } else {
3314 return -1;
3315 }
3316 } finally {
3317 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003319 }
3320
3321 /**
3322 * Returns the CDMA ERI icon mode,
3323 * 0 - ON
3324 * 1 - FLASHING
3325 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003326 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003327 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3328 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3329 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003330 }
3331
Sanket Padawe356d7632015-06-22 14:03:32 -07003332 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003333 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3334 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003336 mApp, subId, callingPackage, callingFeatureId,
3337 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003338 return -1;
3339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340
3341 final long identity = Binder.clearCallingIdentity();
3342 try {
3343 final Phone phone = getPhone(subId);
3344 if (phone != null) {
3345 return phone.getCdmaEriIconMode();
3346 } else {
3347 return -1;
3348 }
3349 } finally {
3350 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 }
3353
3354 /**
3355 * Returns the CDMA ERI text,
3356 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003357 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003358 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3359 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3360 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003361 }
3362
Sanket Padawe356d7632015-06-22 14:03:32 -07003363 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003364 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3365 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003367 mApp, subId, callingPackage, callingFeatureId,
3368 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003369 return null;
3370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003371
3372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 final Phone phone = getPhone(subId);
3375 if (phone != null) {
3376 return phone.getCdmaEriText();
3377 } else {
3378 return null;
3379 }
3380 } finally {
3381 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003383 }
3384
3385 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003386 * Returns the CDMA MDN.
3387 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003388 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003389 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3391 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392
3393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003396 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003397 return phone.getLine1Number();
3398 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003399 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400 return null;
3401 }
3402 } finally {
3403 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003404 }
3405 }
3406
3407 /**
3408 * Returns the CDMA MIN.
3409 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003410 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003411 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3413 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003414
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 final Phone phone = getPhone(subId);
3418 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3419 return phone.getCdmaMin();
3420 } else {
3421 return null;
3422 }
3423 } finally {
3424 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003425 }
3426 }
3427
Hall Liud892bec2018-11-30 14:51:45 -08003428 @Override
3429 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3430 INumberVerificationCallback callback, String callingPackage) {
3431 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3432 != PERMISSION_GRANTED) {
3433 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3434 }
3435 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3436
3437 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3438 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003439 throw new SecurityException("Calling package must be configured in the device config: "
3440 + "calling package: " + callingPackage
3441 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003442 }
3443
3444 if (range == null) {
3445 throw new NullPointerException("Range must be non-null");
3446 }
3447
3448 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003449 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003450
3451 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3452 }
3453
Junda Liuca05d5d2014-08-14 22:36:34 -07003454 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 * Returns true if CDMA provisioning needs to run.
3456 */
3457 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003458 final long identity = Binder.clearCallingIdentity();
3459 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003460 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461 } finally {
3462 Binder.restoreCallingIdentity(identity);
3463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003464 }
3465
3466 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003467 * Sets the voice mail number of a given subId.
3468 */
3469 @Override
3470 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003471 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3472 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003473
3474 final long identity = Binder.clearCallingIdentity();
3475 try {
3476 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3477 new Pair<String, String>(alphaTag, number), new Integer(subId));
3478 return success;
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003482 }
3483
Ta-wei Yen87c49842016-05-13 21:19:52 -07003484 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003485 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3486 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003487 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3488 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003489 if (!TextUtils.equals(callingPackage, systemDialer)) {
3490 throw new SecurityException("caller must be system dialer");
3491 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3496 if (phoneAccountHandle == null) {
3497 return null;
3498 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003499 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003500 } finally {
3501 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003502 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003503 }
3504
3505 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003506 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3507 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003509 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003510 mApp, subId, callingPackage, callingFeatureId,
3511 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003512 return null;
3513 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003514
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003515 final long identity = Binder.clearCallingIdentity();
3516 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003517 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003518 } finally {
3519 Binder.restoreCallingIdentity(identity);
3520 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003521 }
3522
3523 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003524 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3525 VisualVoicemailSmsFilterSettings settings) {
3526 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527
3528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003531 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003535 }
3536
3537 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003538 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3539 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540
3541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003544 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003548 }
3549
3550 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003551 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3552 String callingPackage, int subId) {
3553 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554
3555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003558 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559 } finally {
3560 Binder.restoreCallingIdentity(identity);
3561 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003562 }
3563
3564 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003565 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003566 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003567
3568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003571 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572 } finally {
3573 Binder.restoreCallingIdentity(identity);
3574 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003575 }
3576
3577 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003578 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3579 String callingAttributionTag, int subId, String number, int port, String text,
3580 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003582 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003583 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003584 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003585 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3586 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003587 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003588
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003589 /**
fionaxu0152e512016-11-14 13:36:14 -08003590 * Sets the voice activation state of a given subId.
3591 */
3592 @Override
3593 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003594 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3595 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596
3597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 final Phone phone = getPhone(subId);
3600 if (phone != null) {
3601 phone.setVoiceActivationState(activationState);
3602 } else {
3603 loge("setVoiceActivationState fails with invalid subId: " + subId);
3604 }
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003607 }
3608 }
3609
3610 /**
3611 * Sets the data activation state of a given subId.
3612 */
3613 @Override
3614 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3616 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003617
3618 final long identity = Binder.clearCallingIdentity();
3619 try {
3620 final Phone phone = getPhone(subId);
3621 if (phone != null) {
3622 phone.setDataActivationState(activationState);
3623 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003624 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003625 }
3626 } finally {
3627 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003628 }
3629 }
3630
3631 /**
3632 * Returns the voice activation state of a given subId.
3633 */
3634 @Override
3635 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003636 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003637
fionaxu0152e512016-11-14 13:36:14 -08003638 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 if (phone != null) {
3642 return phone.getVoiceActivationState();
3643 } else {
3644 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3645 }
3646 } finally {
3647 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003648 }
3649 }
3650
3651 /**
3652 * Returns the data activation state of a given subId.
3653 */
3654 @Override
3655 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003656 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657
fionaxu0152e512016-11-14 13:36:14 -08003658 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 if (phone != null) {
3662 return phone.getDataActivationState();
3663 } else {
3664 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3665 }
3666 } finally {
3667 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003668 }
3669 }
3670
3671 /**
Wink Saville36469e72014-06-11 15:17:00 -07003672 * Returns the unread count of voicemails for a subId
3673 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003674 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003675 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3676 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003677 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003678 mApp, subId, callingPackage, callingFeatureId,
3679 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003680 return 0;
3681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 final Phone phone = getPhone(subId);
3685 if (phone != null) {
3686 return phone.getVoiceMessageCount();
3687 } else {
3688 return 0;
3689 }
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003693 }
3694
3695 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003696 * returns true, if the device is in a state where both voice and data
3697 * are supported simultaneously. This can change based on location or network condition.
3698 */
3699 @Override
3700 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 final Phone phone = getPhone(subId);
3704 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003708 }
3709
3710 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003711 * Send the dialer code if called from the current default dialer or the caller has
3712 * carrier privilege.
3713 * @param inputCode The dialer code to send
3714 */
3715 @Override
3716 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003719 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3720 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003721 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003722 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003723 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003724 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725
3726 final long identity = Binder.clearCallingIdentity();
3727 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003728 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
fionaxu235cc5e2017-03-06 22:25:57 -08003732 }
3733
Pengquan Menga1bb6272018-09-06 09:59:22 -07003734 @Override
3735 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003736 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07003737 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003738 mApp, subId, "getNetworkSelectionMode");
3739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 if (!isActiveSubscription(subId)) {
3742 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3743 }
3744 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3745 } finally {
3746 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003747 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003748 }
3749
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003751 public boolean isInEmergencySmsMode() {
3752 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3753 final long identity = Binder.clearCallingIdentity();
3754 try {
3755 for (Phone phone : PhoneFactory.getPhones()) {
3756 if (phone.isInEmergencySmsMode()) {
3757 return true;
3758 }
3759 }
3760 } finally {
3761 Binder.restoreCallingIdentity(identity);
3762 }
3763 return false;
3764 }
3765
shilu366312e2019-12-17 09:28:10 -08003766 /**
3767 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3768 * @param subId The subscription to use to check the configuration.
3769 * @param c The callback that will be used to send the result.
3770 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003771 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003772 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3773 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003774 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003775 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003776
Brad Ebinger77b832e2019-10-17 17:03:22 -07003777 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3778 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3779 "IMS not available on device.");
3780 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003781 final long token = Binder.clearCallingIdentity();
3782 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003783 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003784 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003785 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003786 } catch (ImsException e) {
3787 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 } finally {
3789 Binder.restoreCallingIdentity(token);
3790 }
3791 }
3792
shilu366312e2019-12-17 09:28:10 -08003793 /**
3794 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3795 * @param subId The subscription to use to check the configuration.
3796 * @param c The callback that will be used to send the result.
3797 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003798 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003799 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003800 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003801 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003802 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3803 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3804 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003805 final long token = Binder.clearCallingIdentity();
3806 try {
3807 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3808 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3809 .removeRegistrationCallbackForSubscription(c, subId);
3810 } catch (ImsException e) {
3811 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3812 + "is inactive, ignoring unregister.");
3813 // If the subscription is no longer active, just return, since the callback
3814 // will already have been removed internally.
3815 } finally {
3816 Binder.restoreCallingIdentity(token);
3817 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003818 }
3819
Brad Ebinger774ba362019-10-22 17:36:18 -07003820 /**
3821 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3822 */
3823 @Override
3824 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3825 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3826 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3827 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3828 "IMS not available on device.");
3829 }
3830 final long token = Binder.clearCallingIdentity();
3831 try {
3832 Phone phone = getPhone(subId);
3833 if (phone == null) {
3834 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3835 + subId + "'");
3836 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3837 }
3838 phone.getImsRegistrationState(regState -> {
3839 try {
3840 consumer.accept((regState == null)
3841 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3842 } catch (RemoteException e) {
3843 // Ignore if the remote process is no longer available to call back.
3844 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3845 }
3846 });
3847 } finally {
3848 Binder.restoreCallingIdentity(token);
3849 }
3850 }
3851
3852 /**
3853 * Get the transport type for the IMS service registration state.
3854 */
3855 @Override
3856 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003857 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003858 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003859 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3860 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3861 "IMS not available on device.");
3862 }
3863 final long token = Binder.clearCallingIdentity();
3864 try {
3865 Phone phone = getPhone(subId);
3866 if (phone == null) {
3867 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3868 + subId + "'");
3869 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3870 }
3871 phone.getImsRegistrationTech(regTech -> {
3872 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3873 int regTechConverted = (regTech == null)
3874 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3875 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3876 regTechConverted);
3877 try {
3878 consumer.accept(regTechConverted);
3879 } catch (RemoteException e) {
3880 // Ignore if the remote process is no longer available to call back.
3881 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3882 }
3883 });
3884 } finally {
3885 Binder.restoreCallingIdentity(token);
3886 }
3887 }
3888
shilu366312e2019-12-17 09:28:10 -08003889 /**
3890 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3891 * @param subId The subscription to use to check the configuration.
3892 * @param c The callback that will be used to send the result.
3893 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003895 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3896 throws RemoteException {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003897 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003898 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003899 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3900 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3901 "IMS not available on device.");
3902 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3904 final long token = Binder.clearCallingIdentity();
3905 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003906 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003908 } catch (ImsException e) {
3909 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 } finally {
3911 Binder.restoreCallingIdentity(token);
3912 }
3913 }
3914
shilu366312e2019-12-17 09:28:10 -08003915 /**
3916 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3917 * @param subId The subscription to use to check the configuration.
3918 * @param c The callback that will be used to send the result.
3919 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003920 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003921 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07003922 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003923 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003924 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3925 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3926 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003927
3928 final long token = Binder.clearCallingIdentity();
3929 try {
3930 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3931 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003932 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003933 } catch (ImsException e) {
3934 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3935 + "is inactive, ignoring unregister.");
3936 // If the subscription is no longer active, just return, since the callback
3937 // will already have been removed internally.
3938 } finally {
3939 Binder.restoreCallingIdentity(token);
3940 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003941 }
3942
3943 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003944 public boolean isCapable(int subId, int capability, int regTech) {
3945 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3947 final long token = Binder.clearCallingIdentity();
3948 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003949 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003950 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003951 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3953 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003954 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003955 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3956 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 } finally {
3958 Binder.restoreCallingIdentity(token);
3959 }
3960 }
3961
3962 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003963 public boolean isAvailable(int subId, int capability, int regTech) {
3964 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 final long token = Binder.clearCallingIdentity();
3966 try {
3967 Phone phone = getPhone(subId);
3968 if (phone == null) return false;
3969 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003970 } catch (com.android.ims.ImsException e) {
3971 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3972 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 } finally {
3974 Binder.restoreCallingIdentity(token);
3975 }
3976 }
3977
Brad Ebinger77b832e2019-10-17 17:03:22 -07003978 /**
3979 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3980 * subscription.
3981 * @param subId The subscription to use to check the configuration.
3982 * @param callback The callback that will be used to send the result.
3983 * @param capability The MmTelFeature capability that will be used to send the result.
3984 * @param transportType The transport type of the MmTelFeature capability.
3985 */
3986 @Override
3987 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3988 int transportType) {
3989 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3990 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3991 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3992 "IMS not available on device.");
3993 }
3994 final long token = Binder.clearCallingIdentity();
3995 try {
3996 int slotId = getSlotIndex(subId);
3997 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3998 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3999 + subId + "'");
4000 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4001 }
4002 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4003 transportType, aBoolean -> {
4004 try {
4005 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4006 } catch (RemoteException e) {
4007 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4008 + "running. Ignore");
4009 }
4010 });
4011 } finally {
4012 Binder.restoreCallingIdentity(token);
4013 }
4014 }
4015
shilu366312e2019-12-17 09:28:10 -08004016 /**
4017 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4018 * @param subId The subscription to use to check the configuration.
4019 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 @Override
4021 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004022 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004023 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004024
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4026 final long token = Binder.clearCallingIdentity();
4027 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004028 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004030 } catch (ImsException e) {
4031 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 } finally {
4033 Binder.restoreCallingIdentity(token);
4034 }
4035 }
4036
4037 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004038 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004040 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004044 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004046 } catch (ImsException e) {
4047 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 } finally {
4049 Binder.restoreCallingIdentity(identity);
4050 }
4051 }
4052
shilu366312e2019-12-17 09:28:10 -08004053 /**
4054 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4055 * @param subId The subscription to use to check the configuration.
4056 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004058 public boolean isVtSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004059 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004060 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 final long identity = Binder.clearCallingIdentity();
4062 try {
4063 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004064 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4065 } catch (ImsException e) {
4066 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 } finally {
4068 Binder.restoreCallingIdentity(identity);
4069 }
4070 }
4071
4072 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004073 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004075 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 final long identity = Binder.clearCallingIdentity();
4077 try {
4078 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004079 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004080 } catch (ImsException e) {
4081 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 } finally {
4083 Binder.restoreCallingIdentity(identity);
4084 }
4085 }
4086
shilu366312e2019-12-17 09:28:10 -08004087 /**
4088 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4089 * @param subId The subscription to use to check the configuration.
4090 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 @Override
4092 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004093 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004094 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004095 final long identity = Binder.clearCallingIdentity();
4096 try {
4097 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004098 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004099 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004100 } catch (ImsException e) {
4101 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004102 } finally {
4103 Binder.restoreCallingIdentity(identity);
4104 }
4105 }
4106
4107 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004108 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004110 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 final long identity = Binder.clearCallingIdentity();
4112 try {
4113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004114 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004115 } catch (ImsException e) {
4116 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
4120 }
4121
shilu366312e2019-12-17 09:28:10 -08004122 /**
4123 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4124 * @param subId The subscription to use to check the configuration.
4125 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 @Override
4127 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004128 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004129 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
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
Brad Ebinger1c162042019-02-21 14:49:10 -08004143 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004145 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004146 final long identity = Binder.clearCallingIdentity();
4147 try {
4148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004149 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004151 } catch (ImsException e) {
4152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 } finally {
4154 Binder.restoreCallingIdentity(identity);
4155 }
4156 }
4157
4158 @Override
4159 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4161 "setVoWiFiNonPersistent");
4162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004165 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004166 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004167 } catch (ImsException e) {
4168 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
4172 }
4173
shilu366312e2019-12-17 09:28:10 -08004174 /**
4175 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4176 * @param subId The subscription to use to check the configuration.
4177 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004178 @Override
4179 public int getVoWiFiModeSetting(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004180 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004181 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 final long identity = Binder.clearCallingIdentity();
4183 try {
4184 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004185 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004186 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004187 } catch (ImsException e) {
4188 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
4192 }
4193
4194 @Override
4195 public void setVoWiFiModeSetting(int subId, int mode) {
4196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4197 "setVoWiFiModeSetting");
4198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004201 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004203 } catch (ImsException e) {
4204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
4208 }
4209
4210 @Override
4211 public int getVoWiFiRoamingModeSetting(int subId) {
4212 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004216 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004218 } catch (ImsException e) {
4219 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 } finally {
4221 Binder.restoreCallingIdentity(identity);
4222 }
4223 }
4224
4225 @Override
4226 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4228 "setVoWiFiRoamingModeSetting");
4229 final long identity = Binder.clearCallingIdentity();
4230 try {
4231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004232 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004234 } catch (ImsException e) {
4235 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 } finally {
4237 Binder.restoreCallingIdentity(identity);
4238 }
4239 }
4240
4241 @Override
4242 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4244 "setRttCapabilityEnabled");
4245 final long identity = Binder.clearCallingIdentity();
4246 try {
4247 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004248 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4249 } catch (ImsException e) {
4250 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
4254 }
4255
shilu366312e2019-12-17 09:28:10 -08004256 /**
4257 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4258 * @param subId The subscription to use to check the configuration.
4259 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004260 @Override
4261 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07004262 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004263 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 final long identity = Binder.clearCallingIdentity();
4265 try {
4266 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004267 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004269 } catch (ImsException e) {
4270 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
4274 }
4275
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004276 @Override
4277 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4278 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004281 if (!isImsAvailableOnDevice()) {
4282 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4283 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004284 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004285 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004286 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004287 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004288 } catch (ImsException e) {
4289 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
4293 }
4294
4295 @Override
4296 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4297 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4298 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004299 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4300 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4301 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004302 try {
4303 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004304 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004305 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004306 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004307 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4308 + "is inactive, ignoring unregister.");
4309 // If the subscription is no longer active, just return, since the callback will already
4310 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
4314 }
4315
allenwtsu99c623b2020-01-03 18:24:23 +08004316
4317 private void checkModifyPhoneStatePermission(int subId, String message) {
4318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4319 message);
4320 }
4321
4322 private boolean isImsProvisioningRequired(int subId, int capability,
4323 boolean isMmtelCapability) {
4324 Phone phone = getPhone(subId);
4325 if (phone == null) {
4326 loge("phone instance null for subid " + subId);
4327 return false;
4328 }
4329 if (isMmtelCapability) {
4330 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4331 return false;
4332 }
4333 } else {
4334 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4335 return false;
4336 }
4337 }
4338 return true;
4339 }
4340
4341 @Override
4342 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4343 boolean isProvisioned) {
4344 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4345
4346 final long identity = Binder.clearCallingIdentity();
4347 try {
4348 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4349 if (!isImsProvisioningRequired(subId, capability, false)) {
4350 return;
4351 }
4352
4353 // this capability requires provisioning, route to the correct API.
4354 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4355 switch (capability) {
4356 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4357 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4358 ims.setEabProvisioned(isProvisioned);
4359 break;
4360 default: {
4361 throw new IllegalArgumentException("Tried to set provisioning for "
4362 + "rcs capability '" + capability + "', which does not require "
4363 + "provisioning.");
4364 }
4365 }
4366 } finally {
4367 Binder.restoreCallingIdentity(identity);
4368 }
4369
4370 }
4371
4372
4373 @Override
4374 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4375 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4379 if (!isImsProvisioningRequired(subId, capability, false)) {
4380 return true;
4381 }
4382
4383 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4384 switch (capability) {
4385 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4386 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4387 return ims.isEabProvisionedOnDevice();
4388
4389 default: {
4390 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4391 + "capability '" + capability + "', which does not require "
4392 + "provisioning.");
4393 }
4394 }
4395
4396 } finally {
4397 Binder.restoreCallingIdentity(identity);
4398 }
4399 }
4400
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004401 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004402 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4403 boolean isProvisioned) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004404 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4405 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004406 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4407 }
allenwtsu99c623b2020-01-03 18:24:23 +08004408 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004409 final long identity = Binder.clearCallingIdentity();
4410 try {
4411 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004412 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004413 return;
4414 }
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004415 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4416 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4417 loge("setImsProvisioningStatusForCapability: called for technology that does "
4418 + "not support provisioning - " + tech);
4419 return;
4420 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004421
4422 // this capability requires provisioning, route to the correct API.
4423 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4424 switch (capability) {
4425 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4426 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4427 ims.setVolteProvisioned(isProvisioned);
4428 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4429 ims.setWfcProvisioned(isProvisioned);
4430 }
4431 break;
4432 }
4433 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4434 // There is currently no difference in VT provisioning type.
4435 ims.setVtProvisioned(isProvisioned);
4436 break;
4437 }
4438 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4439 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4440 // change the capability of the feature instead if needed.
4441 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4442 == isProvisioned) {
4443 // No change in provisioning.
4444 return;
4445 }
4446 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4447 try {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004448 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004449 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004450 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4451 + ", Exception" + e.getMessage());
4452 }
4453 break;
4454 }
4455 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004456 throw new IllegalArgumentException("Tried to set provisioning for "
4457 + "MmTel capability '" + capability + "', which does not require "
4458 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004459 }
4460 }
4461
4462 } finally {
4463 Binder.restoreCallingIdentity(identity);
4464 }
4465 }
4466
4467 @Override
4468 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004469 if (tech < ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4470 || tech > ImsRegistrationImplBase.REGISTRATION_TECH_NR) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004471 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4472 }
4473 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4474 final long identity = Binder.clearCallingIdentity();
4475 try {
4476 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004477 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004478 return true;
4479 }
4480
Brad Ebinger2a6be5f2021-04-17 15:20:49 -07004481 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4482 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4483 loge("getImsProvisioningStatusForCapability: called for technology that does "
4484 + "not support provisioning - " + tech);
4485 return true;
4486 }
4487
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004488 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4489 switch (capability) {
4490 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4491 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4492 return ims.isVolteProvisionedOnDevice();
4493 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4494 return ims.isWfcProvisionedOnDevice();
4495 }
4496 // This should never happen, since we are checking tech above to make sure it
4497 // is either LTE or IWLAN.
4498 throw new IllegalArgumentException("Invalid radio technology for voice "
4499 + "capability.");
4500 }
4501 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4502 // There is currently no difference in VT provisioning type.
4503 return ims.isVtProvisionedOnDevice();
4504 }
4505 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4506 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4507 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4508 }
4509 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004510 throw new IllegalArgumentException(
4511 "Tried to get provisioning for MmTel capability '" + capability
4512 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004513 }
4514 }
4515
4516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
4519 }
4520
4521 @Override
4522 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4523 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4524 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4525 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4526 }
4527 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4528 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4529 return (provisionedBits & capability) > 0;
4530 }
4531
4532 @Override
4533 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4534 boolean isProvisioned) {
4535 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4536 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4537 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4538 }
4539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4540 "setProvisioningStatusForCapability");
4541 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4542 // If the current provisioning status for capability already matches isProvisioned,
4543 // do nothing.
4544 if (((provisionedBits & capability) > 0) == isProvisioned) {
4545 return;
4546 }
4547 if (isProvisioned) {
4548 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4549 } else {
4550 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4551 }
4552 }
4553
4554 /**
4555 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4556 * technology. The bitfield should mirror the bitfield defined by
4557 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4558 */
4559 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4560 String key = getMmTelProvisioningKey(subId, tech);
4561 // Default is no capabilities are provisioned.
4562 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4563 }
4564
4565 /**
4566 * Sets the MmTel capability provisioning bitfield (defined by
4567 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4568 * technology specified.
4569 *
4570 * Note: This is a synchronous command and should not be called on UI thread.
4571 */
4572 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4573 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4574 String key = getMmTelProvisioningKey(subId, tech);
4575 editor.putInt(key, newField);
4576 editor.commit();
4577 }
4578
4579 private static String getMmTelProvisioningKey(int subId, int tech) {
4580 // resulting key is provision_ims_mmtel_{subId}_{tech}
4581 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4582 }
4583
4584 /**
4585 * Query CarrierConfig to see if the specified capability requires provisioning for the
4586 * carrier associated with the subscription id.
4587 */
4588 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4589 int capability) {
4590 CarrierConfigManager configManager = new CarrierConfigManager(context);
4591 PersistableBundle c = configManager.getConfigForSubId(subId);
4592 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004593 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004594 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4595 false);
4596 boolean requireVoiceVtProvisioning = c.getBoolean(
4597 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4598
4599 // First check to make sure that the capability requires provisioning.
4600 switch (capability) {
4601 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4602 // intentional fallthrough
4603 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4604 if (requireVoiceVtProvisioning) {
4605 // Voice and Video requires provisioning
4606 return true;
4607 }
4608 break;
4609 }
4610 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4611 if (requireUtProvisioning) {
4612 // UT requires provisioning
4613 return true;
4614 }
4615 break;
4616 }
4617 }
4618 return false;
4619 }
4620
allenwtsu99c623b2020-01-03 18:24:23 +08004621 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4622 int capability) {
4623 CarrierConfigManager configManager = new CarrierConfigManager(context);
4624 PersistableBundle c = configManager.getConfigForSubId(subId);
4625
4626 boolean requireRcsProvisioning = c.getBoolean(
4627 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4628
4629 // First check to make sure that the capability requires provisioning.
4630 switch (capability) {
4631 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4632 // intentional fallthrough
4633 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4634 if (requireRcsProvisioning) {
4635 // OPTION or PRESENCE requires provisioning
4636 return true;
4637 }
4638 break;
4639 }
4640 }
4641 return false;
4642 }
4643
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004644 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004645 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004646 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4647 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4648 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004649 enforceReadPrivilegedPermission("getImsProvisioningInt");
4650 final long identity = Binder.clearCallingIdentity();
4651 try {
4652 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004653 int slotId = getSlotIndex(subId);
4654 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4655 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4656 + subId + "' for key:" + key);
4657 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4658 }
calvinpan9cfff472021-02-08 19:59:36 +08004659 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004660 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004661 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4662 + subId + "' for key:" + key);
4663 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004664 } finally {
4665 Binder.restoreCallingIdentity(identity);
4666 }
4667 }
4668
4669 @Override
4670 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004671 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4672 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4673 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004674 enforceReadPrivilegedPermission("getImsProvisioningString");
4675 final long identity = Binder.clearCallingIdentity();
4676 try {
4677 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004678 int slotId = getSlotIndex(subId);
4679 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4680 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4681 + subId + "' for key:" + key);
4682 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4683 }
calvinpan9cfff472021-02-08 19:59:36 +08004684 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004685 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004686 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4687 + subId + "' for key:" + key);
4688 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004689 } finally {
4690 Binder.restoreCallingIdentity(identity);
4691 }
4692 }
4693
4694 @Override
4695 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004696 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4697 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4698 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4700 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004701 final long identity = Binder.clearCallingIdentity();
4702 try {
4703 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004704 int slotId = getSlotIndex(subId);
4705 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4706 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4707 + subId + "' for key:" + key);
4708 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4709 }
calvinpan9cfff472021-02-08 19:59:36 +08004710 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4711 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004712 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004713 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004714 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004715 } finally {
4716 Binder.restoreCallingIdentity(identity);
4717 }
4718 }
4719
4720 @Override
4721 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004722 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4723 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4724 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4726 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004727 final long identity = Binder.clearCallingIdentity();
4728 try {
4729 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004730 int slotId = getSlotIndex(subId);
4731 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4732 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4733 + subId + "' for key:" + key);
4734 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4735 }
calvinpan9cfff472021-02-08 19:59:36 +08004736 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4737 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004738 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpan9cfff472021-02-08 19:59:36 +08004739 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004740 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004741 } finally {
4742 Binder.restoreCallingIdentity(identity);
4743 }
4744 }
4745
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004746 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004747 int slotId = SubscriptionManager.getSlotIndex(subId);
4748 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004749 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4750 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004751 }
4752 return slotId;
4753 }
4754
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004755 private int getSlotIndex(int subId) {
4756 int slotId = SubscriptionManager.getSlotIndex(subId);
4757 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4758 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4759 }
4760 return slotId;
4761 }
4762
Wink Saville36469e72014-06-11 15:17:00 -07004763 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004764 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004765 */
4766 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004767 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4768 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004769 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004770 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004771 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004772 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004773 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004774 mApp, subId, callingPackage, callingFeatureId,
4775 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004776 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4777 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 final long identity = Binder.clearCallingIdentity();
4780 try {
4781 final Phone phone = getPhone(subId);
4782 if (phone != null) {
4783 return phone.getServiceState().getDataNetworkType();
4784 } else {
4785 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4786 }
4787 } finally {
4788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004790 }
4791
4792 /**
4793 * Returns the data network type
4794 */
4795 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004796 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004797 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4798 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004799 }
4800
4801 /**
4802 * Returns the data network type for a subId
4803 */
4804 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004805 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4806 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004808 mApp, subId, callingPackage, callingFeatureId,
4809 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004810 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4811 }
4812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813 final long identity = Binder.clearCallingIdentity();
4814 try {
4815 final Phone phone = getPhone(subId);
4816 if (phone != null) {
4817 return phone.getServiceState().getDataNetworkType();
4818 } else {
4819 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4820 }
4821 } finally {
4822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004824 }
4825
4826 /**
Wink Saville36469e72014-06-11 15:17:00 -07004827 * Returns the Voice network type for a subId
4828 */
4829 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004830 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4831 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004832 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004833 mApp, subId, callingPackage, callingFeatureId,
4834 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004835 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4836 }
4837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004838 final long identity = Binder.clearCallingIdentity();
4839 try {
4840 final Phone phone = getPhone(subId);
4841 if (phone != null) {
4842 return phone.getServiceState().getVoiceNetworkType();
4843 } else {
4844 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4845 }
4846 } finally {
4847 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004849 }
4850
4851 /**
4852 * @return true if a ICC card is present
4853 */
4854 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004855 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004856 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4857 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004858 }
4859
4860 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004861 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004862 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004863 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004864 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865 final long identity = Binder.clearCallingIdentity();
4866 try {
4867 final Phone phone = PhoneFactory.getPhone(slotIndex);
4868 if (phone != null) {
4869 return phone.getIccCard().hasIccCard();
4870 } else {
4871 return false;
4872 }
4873 } finally {
4874 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004876 }
4877
4878 /**
4879 * Return if the current radio is LTE on CDMA. This
4880 * is a tri-state return value as for a period of time
4881 * the mode may be unknown.
4882 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004883 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004884 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004885 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004886 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004887 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004888 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4889 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4890 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004891 }
4892
Sanket Padawe356d7632015-06-22 14:03:32 -07004893 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004894 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4895 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004896 try {
4897 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4898 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004899 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4900 }
4901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 final long identity = Binder.clearCallingIdentity();
4903 try {
4904 final Phone phone = getPhone(subId);
4905 if (phone == null) {
4906 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4907 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004908 return TelephonyProperties.lte_on_cdma_device()
4909 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 }
4911 } finally {
4912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004913 }
Wink Saville36469e72014-06-11 15:17:00 -07004914 }
4915
Wink Saville36469e72014-06-11 15:17:00 -07004916 /**
4917 * {@hide}
4918 * Returns Default subId, 0 in the case of single standby.
4919 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004920 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004921 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004922 }
4923
Shishir Agrawala9f32182016-04-12 12:00:16 -07004924 private int getSlotForDefaultSubscription() {
4925 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4926 }
4927
Wink Savilleb564aae2014-10-23 10:18:09 -07004928 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004929 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004930 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004931
Pengquan Menge92a50d2018-09-21 15:54:48 -07004932 private boolean isActiveSubscription(int subId) {
4933 return mSubscriptionController.isActiveSubId(subId);
4934 }
4935
Ihab Awadf2177b72013-11-25 13:33:23 -08004936 /**
4937 * @see android.telephony.TelephonyManager.WifiCallingChoices
4938 */
4939 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 final long identity = Binder.clearCallingIdentity();
4941 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004942 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4944 getWhenToMakeWifiCallsDefaultPreference());
4945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004948 }
4949
4950 /**
4951 * @see android.telephony.TelephonyManager.WifiCallingChoices
4952 */
4953 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 final long identity = Binder.clearCallingIdentity();
4955 try {
4956 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004957 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004962 }
4963
Sailesh Nepald1e68152013-12-12 19:08:02 -08004964 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004965 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004966 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004967 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004968
Jordan Liu4c733742019-02-28 12:03:40 -08004969 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4970 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4971 if (phoneId == -1) {
4972 throw new IllegalArgumentException("Given slot index: " + slotIndex
4973 + " does not correspond to an active phone");
4974 }
4975 return PhoneFactory.getPhone(phoneId);
4976 }
4977
Shishir Agrawal566b7612013-10-28 14:41:00 -07004978 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004979 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4980 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4982 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004984 if (DBG) {
4985 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4986 }
4987 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4988 p2);
4989 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004990
Jordan Liu4c733742019-02-28 12:03:40 -08004991
4992 @Override
4993 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4994 int slotIndex, String callingPackage, String aid, int p2) {
4995 enforceModifyPermission();
4996 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4997 if (DBG) {
4998 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4999 }
5000 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5001 callingPackage, aid, p2);
5002 }
5003
5004 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5005 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006 final long identity = Binder.clearCallingIdentity();
5007 try {
5008 if (TextUtils.equals(ISDR_AID, aid)) {
5009 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005010 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5011 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 if (bestComponent == null
5013 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5014 loge("The calling package is not allowed to access ISD-R.");
5015 throw new SecurityException(
5016 "The calling package is not allowed to access ISD-R.");
5017 }
Derek Tan740e1672017-06-27 14:56:27 -07005018 }
Derek Tan740e1672017-06-27 14:56:27 -07005019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005021 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5022 null /* workSource */);
5023 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 return response;
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
5027 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005028 }
5029
5030 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005031 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5033 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005034 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5035 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5036 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005037
Jordan Liu4c733742019-02-28 12:03:40 -08005038 @Override
5039 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5040 enforceModifyPermission();
5041 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5042 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5043 channel);
5044 }
5045
5046 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 final long identity = Binder.clearCallingIdentity();
5048 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 if (channel < 0) {
5050 return false;
5051 }
Jordan Liu4c733742019-02-28 12:03:40 -08005052 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5053 null /* workSource */);
5054 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005055 return success;
5056 } finally {
5057 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005058 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005059 }
5060
5061 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005062 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005063 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5065 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005066 if (DBG) {
5067 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5068 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5069 + p3 + " data=" + data);
5070 }
5071 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5072 command, p1, p2, p3, data);
5073 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005074
Jordan Liu4c733742019-02-28 12:03:40 -08005075 @Override
5076 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5077 int command, int p1, int p2, int p3, String data) {
5078 enforceModifyPermission();
5079 if (DBG) {
5080 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5081 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5082 + p3 + " data=" + data);
5083 }
5084 return iccTransmitApduLogicalChannelWithPermission(
5085 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5086 data);
5087 }
5088
5089 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5090 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 final long identity = Binder.clearCallingIdentity();
5092 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005093 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 return "";
5095 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005098 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5099 null /* workSource */);
5100 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005101
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 // Append the returned status code to the end of the response payload.
5103 String s = Integer.toHexString(
5104 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5105 if (response.payload != null) {
5106 s = IccUtils.bytesToHexString(response.payload) + s;
5107 }
5108 return s;
5109 } finally {
5110 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005111 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005112 }
Jake Hambye994d462014-02-03 13:10:13 -08005113
Evan Charltonc66da362014-05-16 14:06:40 -07005114 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005115 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5116 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5118 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005120 if (DBG) {
5121 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5122 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5123 }
5124 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5125 cla, command, p1, p2, p3, data);
5126 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005127
Jordan Liu4c733742019-02-28 12:03:40 -08005128 @Override
5129 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5130 int command, int p1, int p2, int p3, String data) {
5131 enforceModifyPermission();
5132 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5133 if (DBG) {
5134 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5135 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5136 + " data=" + data);
5137 }
5138
5139 return iccTransmitApduBasicChannelWithPermission(
5140 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5141 p2, p3, data);
5142 }
5143
5144 // open APDU basic channel assuming the caller has sufficient permissions
5145 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5146 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 final long identity = Binder.clearCallingIdentity();
5148 try {
5149 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5150 && TextUtils.equals(ISDR_AID, data)) {
5151 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005152 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5153 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 if (bestComponent == null
5155 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5156 loge("The calling package is not allowed to select ISD-R.");
5157 throw new SecurityException(
5158 "The calling package is not allowed to select ISD-R.");
5159 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005160 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005163 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5164 null /* workSource */);
5165 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167 // Append the returned status code to the end of the response payload.
5168 String s = Integer.toHexString(
5169 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5170 if (response.payload != null) {
5171 s = IccUtils.bytesToHexString(response.payload) + s;
5172 }
5173 return s;
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005176 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005177 }
5178
5179 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005180 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005181 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5183 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005184
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 if (DBG) {
5188 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5189 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5190 }
5191
5192 IccIoResult response =
5193 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5194 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5195 subId);
5196
5197 if (DBG) {
5198 log("Exchange SIM_IO [R]" + response);
5199 }
5200
5201 byte[] result = null;
5202 int length = 2;
5203 if (response.payload != null) {
5204 length = 2 + response.payload.length;
5205 result = new byte[length];
5206 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5207 } else {
5208 result = new byte[length];
5209 }
5210
5211 result[length - 1] = (byte) response.sw2;
5212 result[length - 2] = (byte) response.sw1;
5213 return result;
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005216 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005217 }
5218
Nathan Haroldb3014052017-01-25 15:57:32 -08005219 /**
5220 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5221 * on a particular subscription
5222 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005223 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5224 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005226 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005227 return null;
5228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229
5230 final long identity = Binder.clearCallingIdentity();
5231 try {
5232 if (appType != TelephonyManager.APPTYPE_USIM
5233 && appType != TelephonyManager.APPTYPE_SIM) {
5234 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5235 return null;
5236 }
5237 Object response = sendRequest(
5238 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5239 if (response instanceof String[]) {
5240 return (String[]) response;
5241 }
yincheng zhaod698b842019-09-06 17:06:54 -07005242 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005244 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 } finally {
5246 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005247 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005248 }
5249
yincheng zhaod698b842019-09-06 17:06:54 -07005250 /**
5251 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5252 * subscription.
5253 *
5254 * @param subId the id of the subscription.
5255 * @param appType the uicc app type, must be USIM or SIM.
5256 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5257 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005258 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005259 * @return number of fplmns that is successfully written to the SIM.
5260 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005261 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5262 String callingFeatureId) {
5263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5264 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005265 if (DBG) logv("no permissions for setForbiddenplmns");
5266 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5267 }
5268 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5269 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5270 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5271 }
5272 if (fplmns == null) {
5273 throw new IllegalArgumentException("Fplmn List provided is null");
5274 }
5275 for (String fplmn : fplmns) {
5276 if (!CellIdentity.isValidPlmn(fplmn)) {
5277 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5278 }
5279 }
5280 final long identity = Binder.clearCallingIdentity();
5281 try {
5282 Object response = sendRequest(
5283 CMD_SET_FORBIDDEN_PLMNS,
5284 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5285 subId);
5286 return (int) response;
5287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
5290 }
5291
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005292 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005293 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5295 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 final long identity = Binder.clearCallingIdentity();
5298 try {
5299 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5300 if (response.payload == null) {
5301 return "";
5302 }
Evan Charltonc66da362014-05-16 14:06:40 -07005303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005304 // Append the returned status code to the end of the response payload.
5305 String s = Integer.toHexString(
5306 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5307 s = IccUtils.bytesToHexString(response.payload) + s;
5308 return s;
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
5311 }
Evan Charltonc66da362014-05-16 14:06:40 -07005312 }
5313
Jake Hambye994d462014-02-03 13:10:13 -08005314 /**
5315 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5316 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5317 *
5318 * @param itemID the ID of the item to read
5319 * @return the NV item as a String, or null on error.
5320 */
5321 @Override
5322 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005323 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5325 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326
5327 final long identity = Binder.clearCallingIdentity();
5328 try {
5329 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005330 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5332 return value;
5333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
Jake Hambye994d462014-02-03 13:10:13 -08005336 }
5337
5338 /**
5339 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5340 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5341 *
5342 * @param itemID the ID of the item to read
5343 * @param itemValue the value to write, as a String
5344 * @return true on success; false on any failure
5345 */
5346 @Override
5347 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005348 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5350 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351
5352 final long identity = Binder.clearCallingIdentity();
5353 try {
5354 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5355 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005356 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5358 return success;
5359 } finally {
5360 Binder.restoreCallingIdentity(identity);
5361 }
Jake Hambye994d462014-02-03 13:10:13 -08005362 }
5363
5364 /**
5365 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5366 * Used for device configuration by some CDMA operators.
5367 *
5368 * @param preferredRoamingList byte array containing the new PRL
5369 * @return true on success; false on any failure
5370 */
5371 @Override
5372 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5374 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375
5376 final long identity = Binder.clearCallingIdentity();
5377 try {
5378 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5379 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5380 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5381 return success;
5382 } finally {
5383 Binder.restoreCallingIdentity(identity);
5384 }
Jake Hambye994d462014-02-03 13:10:13 -08005385 }
5386
5387 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005388 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005389 * Used for device configuration by some CDMA operators.
5390 *
chen xu6dac5ab2018-10-26 17:39:23 -07005391 * @param slotIndex - device slot.
5392 *
Jake Hambye994d462014-02-03 13:10:13 -08005393 * @return true on success; false on any failure
5394 */
5395 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005396 public boolean resetModemConfig(int slotIndex) {
5397 Phone phone = PhoneFactory.getPhone(slotIndex);
5398 if (phone != null) {
5399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5400 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401
chen xu6dac5ab2018-10-26 17:39:23 -07005402 final long identity = Binder.clearCallingIdentity();
5403 try {
5404 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5405 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5406 return success;
5407 } finally {
5408 Binder.restoreCallingIdentity(identity);
5409 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 }
chen xu6dac5ab2018-10-26 17:39:23 -07005411 return false;
5412 }
5413
5414 /**
5415 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5416 *
5417 * @param slotIndex - device slot.
5418 *
5419 * @return true on success; false on any failure
5420 */
5421 @Override
5422 public boolean rebootModem(int slotIndex) {
5423 Phone phone = PhoneFactory.getPhone(slotIndex);
5424 if (phone != null) {
5425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5426 mApp, phone.getSubId(), "rebootModem");
5427
5428 final long identity = Binder.clearCallingIdentity();
5429 try {
5430 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5431 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5432 return success;
5433 } finally {
5434 Binder.restoreCallingIdentity(identity);
5435 }
5436 }
5437 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005438 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005439
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005440 public String[] getPcscfAddress(String apnType, String callingPackage,
5441 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005442 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5444 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005445 return new String[0];
5446 }
5447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 final long identity = Binder.clearCallingIdentity();
5449 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005450 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451 } finally {
5452 Binder.restoreCallingIdentity(identity);
5453 }
Wink Saville36469e72014-06-11 15:17:00 -07005454 }
5455
Brad Ebinger51f743a2017-01-23 13:50:20 -08005456 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005457 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5458 * {@link #disableIms(int)}.
5459 * @param slotIndex device slot.
5460 */
5461 public void resetIms(int slotIndex) {
5462 enforceModifyPermission();
5463
5464 final long identity = Binder.clearCallingIdentity();
5465 try {
5466 if (mImsResolver == null) {
5467 // may happen if the does not support IMS.
5468 return;
5469 }
5470 mImsResolver.disableIms(slotIndex);
5471 mImsResolver.enableIms(slotIndex);
5472 } finally {
5473 Binder.restoreCallingIdentity(identity);
5474 }
5475 }
5476
5477 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005478 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5479 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005480 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005481 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483
5484 final long identity = Binder.clearCallingIdentity();
5485 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005486 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005487 // may happen if the device does not support IMS.
5488 return;
5489 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005490 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 } finally {
5492 Binder.restoreCallingIdentity(identity);
5493 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005494 }
5495
5496 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005497 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5498 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005499 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005500 public void disableIms(int slotId) {
5501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502
5503 final long identity = Binder.clearCallingIdentity();
5504 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005505 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005506 // may happen if the device does not support IMS.
5507 return;
5508 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005509 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 } finally {
5511 Binder.restoreCallingIdentity(identity);
5512 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005513 }
5514
5515 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005516 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5517 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005518 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005519 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005520 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005521 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522
5523 final long identity = Binder.clearCallingIdentity();
5524 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005525 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005526 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5527 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005528 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005529 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005533 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005534 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005535 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5536 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005537 @Override
5538 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005539 enforceModifyPermission();
5540
5541 final long identity = Binder.clearCallingIdentity();
5542 try {
5543 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005544 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005545 } finally {
5546 Binder.restoreCallingIdentity(identity);
5547 }
5548 }
5549
5550 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005551 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005552 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005553 */
5554 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556
5557 final long identity = Binder.clearCallingIdentity();
5558 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005559 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005560 // may happen if the device does not support IMS.
5561 return null;
5562 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005563 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 } finally {
5565 Binder.restoreCallingIdentity(identity);
5566 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005567 }
5568
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005569 /**
5570 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005571 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005572 */
5573 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5574 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575
5576 final long identity = Binder.clearCallingIdentity();
5577 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005578 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005579 // may happen if the device does not support IMS.
5580 return null;
5581 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005582 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005586 }
5587
Brad Ebinger884c07b2018-02-15 16:17:40 -08005588 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005589 * Sets the ImsService Package Name that Telephony will bind to.
5590 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005591 * @param slotIndex the slot ID that the ImsService should bind for.
5592 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005593 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005594 * @param featureTypes An integer array of feature types associated with a packageName.
5595 * @param packageName The name of the package that the current configuration will be replaced
5596 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005597 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005598 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005599 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5600 int[] featureTypes, String packageName) {
5601 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5602 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5604 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005605 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 final long identity = Binder.clearCallingIdentity();
5608 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005609 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005610 // may happen if the device does not support IMS.
5611 return false;
5612 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005613 Map<Integer, String> featureConfig = new HashMap<>();
5614 for (int featureType : featureTypes) {
5615 featureConfig.put(featureType, packageName);
5616 }
5617 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5618 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 } finally {
5620 Binder.restoreCallingIdentity(identity);
5621 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005622 }
5623
5624 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005625 * Clears any carrier ImsService overrides for the slot index specified that were previously
5626 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5627 *
5628 * This should only be used for testing.
5629 *
5630 * @param slotIndex the slot ID that the ImsService should bind for.
5631 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5632 */
5633 @Override
5634 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5635 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5636 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5637 "clearCarrierImsServiceOverride");
5638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5639 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5640 "clearCarrierImsServiceOverride");
5641
5642 final long identity = Binder.clearCallingIdentity();
5643 try {
5644 if (mImsResolver == null) {
5645 // may happen if the device does not support IMS.
5646 return false;
5647 }
5648 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5649 } finally {
5650 Binder.restoreCallingIdentity(identity);
5651 }
5652 }
5653
5654 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005655 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005656 *
5657 * @param slotId The slot that the ImsService is associated with.
5658 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5659 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005660 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005661 * @return the package name of the ImsService configuration.
5662 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005663 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5664 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005665 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005666 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005667 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger05f52c22019-12-05 13:03:21 -08005668 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5669 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005670
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 final long identity = Binder.clearCallingIdentity();
5672 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005673 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005674 // may happen if the device does not support IMS.
5675 return "";
5676 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005677 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005678 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5679 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 } finally {
5681 Binder.restoreCallingIdentity(identity);
5682 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005683 }
5684
Brad Ebinger77b832e2019-10-17 17:03:22 -07005685 /**
5686 * Get the MmTelFeature state associated with the requested subscription id.
5687 * @param subId The subscription that the MmTelFeature is associated with.
5688 * @param callback A callback with an integer containing the
5689 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5690 */
5691 @Override
5692 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5693 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5694 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5695 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5696 "IMS not available on device.");
5697 }
5698 final long token = Binder.clearCallingIdentity();
5699 try {
5700 int slotId = getSlotIndex(subId);
5701 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5702 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5703 + subId + "'");
5704 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5705 }
5706 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5707 try {
5708 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5709 } catch (RemoteException e) {
5710 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5711 + "Ignore");
5712 }
5713 });
5714 } finally {
5715 Binder.restoreCallingIdentity(token);
5716 }
5717 }
5718
Daniel Brightbb5840b2021-01-12 15:48:18 -08005719 /**
5720 * Sets the ims registration state on all valid {@link Phone}s.
5721 */
5722 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005723 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724
5725 final long identity = Binder.clearCallingIdentity();
5726 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005727 // NOTE: Before S, this method only set the default phone.
5728 for (final Phone phone : PhoneFactory.getPhones()) {
5729 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5730 phone.setImsRegistrationState(registered);
5731 }
5732 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
Wink Saville36469e72014-06-11 15:17:00 -07005736 }
5737
5738 /**
Stuart Scott54788802015-03-30 13:18:01 -07005739 * Set the network selection mode to automatic.
5740 *
5741 */
5742 @Override
5743 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5745 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746
5747 final long identity = Binder.clearCallingIdentity();
5748 try {
shilufc958392020-01-20 11:36:01 -08005749 if (!isActiveSubscription(subId)) {
5750 return;
5751 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005753 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5754 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755 } finally {
5756 Binder.restoreCallingIdentity(identity);
5757 }
Stuart Scott54788802015-03-30 13:18:01 -07005758 }
5759
Jack Yud10cdd42020-09-28 20:28:01 -07005760 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005761 * Ask the radio to connect to the input network and change selection mode to manual.
5762 *
5763 * @param subId the id of the subscription.
5764 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5765 * the operator to attach to.
5766 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5767 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5768 * normal network selection next time.
5769 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005770 */
5771 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005772 public boolean setNetworkSelectionModeManual(
5773 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5775 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005776
5777 if (!isActiveSubscription(subId)) {
5778 return false;
5779 }
5780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 final long identity = Binder.clearCallingIdentity();
5782 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005783 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005785 if (DBG) {
5786 log("setNetworkSelectionModeManual: subId: " + subId
5787 + " operator: " + operatorInfo);
5788 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
5792 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005793 }
shilu84f6e8b2019-12-19 13:58:01 -08005794 /**
5795 * Get the manual network selection
5796 *
5797 * @param subId the id of the subscription.
5798 *
5799 * @return the previously saved user selected PLMN
5800 */
5801 @Override
5802 public String getManualNetworkSelectionPlmn(int subId) {
5803 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07005804 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005805 mApp, subId, "getManualNetworkSelectionPlmn");
5806
5807 final long identity = Binder.clearCallingIdentity();
5808 try {
5809 if (!isActiveSubscription(subId)) {
5810 return "";
5811 }
5812
5813 final Phone phone = getPhone(subId);
5814 if (phone == null) {
5815 return "";
5816 }
5817 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5818 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5819 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
5823 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005824
5825 /**
5826 * Scans for available networks.
5827 */
5828 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005829 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5830 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5832 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005833 LocationAccessPolicy.LocationPermissionResult locationResult =
5834 LocationAccessPolicy.checkLocationPermission(mApp,
5835 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5836 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005837 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005838 .setCallingPid(Binder.getCallingPid())
5839 .setCallingUid(Binder.getCallingUid())
5840 .setMethod("getCellNetworkScanResults")
5841 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07005842 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5843 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005844 .build());
5845 switch (locationResult) {
5846 case DENIED_HARD:
5847 throw new SecurityException("Not allowed to access scan results -- location");
5848 case DENIED_SOFT:
5849 return null;
5850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851
Pengquan Menga1bb6272018-09-06 09:59:22 -07005852 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853 try {
5854 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005855 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005860 }
5861
5862 /**
sqian80370722020-01-29 15:02:51 -08005863 * Get the call forwarding info, given the call forwarding reason.
5864 */
5865 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005866 public void getCallForwarding(int subId, int callForwardingReason,
5867 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005868 enforceReadPrivilegedPermission("getCallForwarding");
5869 long identity = Binder.clearCallingIdentity();
5870 try {
5871 if (DBG) {
5872 log("getCallForwarding: subId " + subId
5873 + " callForwardingReason" + callForwardingReason);
5874 }
Hall Liua1acea22020-09-18 19:04:59 -07005875
5876 Phone phone = getPhone(subId);
5877 if (phone == null) {
5878 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005879 callback.onError(
5880 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005881 } catch (RemoteException e) {
5882 // ignore
5883 }
5884 return;
5885 }
5886
5887 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5888 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5889 @Override
5890 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5891 try {
5892 callback.onCallForwardingInfoAvailable(info);
5893 } catch (RemoteException e) {
5894 // ignore
5895 }
5896 }
5897
5898 @Override
5899 public void onError(int error) {
5900 try {
5901 callback.onError(error);
5902 } catch (RemoteException e) {
5903 // ignore
5904 }
5905 }
5906 });
5907 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005908 } finally {
5909 Binder.restoreCallingIdentity(identity);
5910 }
5911 }
5912
5913 /**
5914 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5915 * reason, the number to forward, and the timeout before the forwarding is attempted.
5916 */
5917 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005918 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5919 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005920 enforceModifyPermission();
5921 long identity = Binder.clearCallingIdentity();
5922 try {
5923 if (DBG) {
5924 log("setCallForwarding: subId " + subId
5925 + " callForwardingInfo" + callForwardingInfo);
5926 }
Hall Liua1acea22020-09-18 19:04:59 -07005927
5928 Phone phone = getPhone(subId);
5929 if (phone == null) {
5930 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005931 callback.accept(
5932 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005933 } catch (RemoteException e) {
5934 // ignore
5935 }
5936 return;
5937 }
5938
5939 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5940 FunctionalUtils.ignoreRemoteException(callback::accept));
5941
5942 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005943 } finally {
5944 Binder.restoreCallingIdentity(identity);
5945 }
5946 }
5947
5948 /**
Hall Liua1acea22020-09-18 19:04:59 -07005949 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005950 */
5951 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005952 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWangc63cf522021-03-31 22:08:45 +08005953 enforceReadPrivilegedPermission("getCallWaitingStatus");
sqian80370722020-01-29 15:02:51 -08005954 long identity = Binder.clearCallingIdentity();
5955 try {
Hall Liua1acea22020-09-18 19:04:59 -07005956 Phone phone = getPhone(subId);
5957 if (phone == null) {
5958 try {
5959 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5960 } catch (RemoteException e) {
5961 // ignore
5962 }
5963 return;
5964 }
SongFerngWangc63cf522021-03-31 22:08:45 +08005965 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
5966 PersistableBundle c = configManager.getConfigForSubId(subId);
5967 boolean requireUssd = c.getBoolean(
5968 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07005969
sqian80370722020-01-29 15:02:51 -08005970 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWangc63cf522021-03-31 22:08:45 +08005971 if (requireUssd) {
5972 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
5973 getSubscriptionCarrierId(subId));
5974 String newUssdCommand = "";
5975 try {
5976 newUssdCommand = carrierXmlParser.getFeature(
5977 CarrierXmlParser.FEATURE_CALL_WAITING)
5978 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
5979 } catch (NullPointerException e) {
5980 loge("Failed to generate USSD number" + e);
5981 }
5982 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
5983 mMainThreadHandler, callback, carrierXmlParser,
5984 CarrierXmlParser.SsEntry.SSAction.QUERY);
5985 final String ussdCommand = newUssdCommand;
5986 Executors.newSingleThreadExecutor().execute(() -> {
5987 handleUssdRequest(subId, ussdCommand, wrappedCallback);
5988 });
5989 } else {
5990 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
5991 callback::accept);
5992 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
5993 }
sqian80370722020-01-29 15:02:51 -08005994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
5997 }
5998
5999 /**
Hall Liua1acea22020-09-18 19:04:59 -07006000 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08006001 */
6002 @Override
Hall Liua1acea22020-09-18 19:04:59 -07006003 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08006004 enforceModifyPermission();
6005 long identity = Binder.clearCallingIdentity();
6006 try {
Hall Liua1acea22020-09-18 19:04:59 -07006007 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6008
6009 Phone phone = getPhone(subId);
6010 if (phone == null) {
6011 try {
6012 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6013 } catch (RemoteException e) {
6014 // ignore
6015 }
6016 return;
6017 }
6018
SongFerngWangc63cf522021-03-31 22:08:45 +08006019 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6020 PersistableBundle c = configManager.getConfigForSubId(subId);
6021 boolean requireUssd = c.getBoolean(
6022 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liua1acea22020-09-18 19:04:59 -07006023
SongFerngWangc63cf522021-03-31 22:08:45 +08006024 if (DBG) log("getCallWaitingStatus: subId " + subId);
6025 if (requireUssd) {
6026 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6027 getSubscriptionCarrierId(subId));
6028 CarrierXmlParser.SsEntry.SSAction ssAction =
6029 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6030 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6031 String newUssdCommand = "";
6032 try {
6033 newUssdCommand = carrierXmlParser.getFeature(
6034 CarrierXmlParser.FEATURE_CALL_WAITING)
6035 .makeCommand(ssAction, null);
6036 } catch (NullPointerException e) {
6037 loge("Failed to generate USSD number" + e);
6038 }
6039 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6040 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6041 final String ussdCommand = newUssdCommand;
6042 Executors.newSingleThreadExecutor().execute(() -> {
6043 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6044 });
6045 } else {
6046 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6047 FunctionalUtils.ignoreRemoteException(callback::accept));
6048
6049 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6050 }
sqian80370722020-01-29 15:02:51 -08006051 } finally {
6052 Binder.restoreCallingIdentity(identity);
6053 }
6054 }
6055
6056 /**
yinxub1bed742017-04-17 11:45:04 -07006057 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006058 *
yinxub1bed742017-04-17 11:45:04 -07006059 * @param subId id of the subscription
6060 * @param request contains the radio access networks with bands/channels to scan
6061 * @param messenger callback messenger for scan results or errors
6062 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006063 * @return the id of the requested scan which can be used to stop the scan.
6064 */
6065 @Override
6066 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006067 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6069 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006070 LocationAccessPolicy.LocationPermissionResult locationResult =
6071 LocationAccessPolicy.checkLocationPermission(mApp,
6072 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6073 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006074 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006075 .setCallingPid(Binder.getCallingPid())
6076 .setCallingUid(Binder.getCallingUid())
6077 .setMethod("requestNetworkScan")
6078 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6079 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006080 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07006081 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6082 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006083 if (e != null) {
6084 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6085 throw e;
6086 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006087 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006088 return TelephonyScanManager.INVALID_SCAN_ID;
6089 }
6090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 }
Hall Liu912dfd32019-04-25 14:02:26 -07006092 int callingUid = Binder.getCallingUid();
6093 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006094 final long identity = Binder.clearCallingIdentity();
6095 try {
6096 return mNetworkScanRequestTracker.startNetworkScan(
6097 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006098 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
yinxu504e1392017-04-12 16:03:22 -07006102 }
6103
Hall Liub2ac8ef2019-02-28 15:56:23 -08006104 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07006105 NetworkScanRequest request, int subId, String callingPackage) {
6106 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006107 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6108 boolean hasNetworkScanPermission =
6109 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6110 == PERMISSION_GRANTED;
6111
6112 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6113 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6114 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006115 }
6116
6117 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6118 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006119 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6120 return new SecurityException("Specific channels must not be"
6121 + " scanned without location access.");
6122 }
6123 }
6124 }
6125
Hall Liub2ac8ef2019-02-28 15:56:23 -08006126 return null;
6127 }
6128
yinxu504e1392017-04-12 16:03:22 -07006129 /**
6130 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006131 *
6132 * @param subId id of the subscription
6133 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006134 */
6135 @Override
6136 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6138 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139
Hall Liu912dfd32019-04-25 14:02:26 -07006140 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 final long identity = Binder.clearCallingIdentity();
6142 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006143 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
yinxu504e1392017-04-12 16:03:22 -07006147 }
6148
6149 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006150 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006151 *
SongFerngWang9e060372020-12-21 16:41:52 +08006152 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006153 */
6154 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006155 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006156 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006157 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006158 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159
6160 final long identity = Binder.clearCallingIdentity();
6161 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006162 if (DBG) log("getAllowedNetworkTypesBitmask");
6163 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6164 int networkTypesBitmask = (result != null ? result[0] : -1);
6165 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6166 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006170 }
6171
6172 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006173 * Get the allowed network types for certain reason.
6174 *
6175 * @param subId the id of the subscription.
6176 * @param reason the reason the allowed network type change is taking place
6177 * @return the allowed network types.
6178 */
6179 @Override
6180 public long getAllowedNetworkTypesForReason(int subId,
6181 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07006182 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang522637d2021-03-02 22:09:29 +08006183 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006184 final long identity = Binder.clearCallingIdentity();
6185 try {
6186 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006193 * Enable/Disable E-UTRA-NR Dual Connectivity
6194 * @param subId subscription id of the sim card
6195 * @param nrDualConnectivityState expected NR dual connectivity state
6196 * This can be passed following states
6197 * <ol>
6198 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6199 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6200 * <li>Disable NR dual connectivity and force secondary cell to be released
6201 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6202 * </ol>
6203 * @return operation result.
6204 */
6205 @Override
6206 public int setNrDualConnectivityState(int subId,
6207 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6209 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006210 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006211 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6212 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6213 }
6214
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006215 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6216 final long identity = Binder.clearCallingIdentity();
6217 try {
6218 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6219 nrDualConnectivityState, subId,
6220 workSource);
6221 if (DBG) log("enableNRDualConnectivity result: " + result);
6222 return result;
6223 } finally {
6224 Binder.restoreCallingIdentity(identity);
6225 }
6226 }
6227
6228 /**
6229 * Is E-UTRA-NR Dual Connectivity enabled
6230 * @return true if dual connectivity is enabled else false
6231 */
6232 @Override
6233 public boolean isNrDualConnectivityEnabled(int subId) {
6234 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07006235 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006236 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006237 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006238 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6239 return false;
6240 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006241 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6242 final long identity = Binder.clearCallingIdentity();
6243 try {
6244 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6245 null, subId, workSource);
6246 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6247 return isEnabled;
6248 } finally {
6249 Binder.restoreCallingIdentity(identity);
6250 }
6251 }
6252
6253 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006254 * Set the allowed network types of the device and
6255 * provide the reason triggering the allowed network change.
6256 *
6257 * @param subId the id of the subscription.
6258 * @param reason the reason the allowed network type change is taking place
6259 * @param allowedNetworkTypes the allowed network types.
6260 * @return true on success; false on any failure.
6261 */
6262 @Override
6263 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006264 @TelephonyManager.AllowedNetworkTypesReason int reason,
6265 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6267 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006268 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWangc2d3ccc2021-04-15 19:46:33 +08006269 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6270 return false;
6271 }
6272 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6273 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang9e060372020-12-21 16:41:52 +08006274 return false;
6275 }
6276
SongFerngWang522637d2021-03-02 22:09:29 +08006277 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6278 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6279
6280
6281 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6282 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6283 return true;
SongFerngWang9e060372020-12-21 16:41:52 +08006284 }
SongFerngWang522637d2021-03-02 22:09:29 +08006285
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006286 final long identity = Binder.clearCallingIdentity();
6287 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006288 Boolean success = (Boolean) sendRequest(
6289 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6290 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6291
6292 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6293 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006294 } finally {
6295 Binder.restoreCallingIdentity(identity);
6296 }
6297 }
6298
6299 /**
Miaoa84611c2019-03-15 09:21:10 +08006300 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006301 *
Miaoa84611c2019-03-15 09:21:10 +08006302 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006303 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006304 * @hide
6305 */
6306 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006307 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006308 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006310 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 try {
Miaoa84611c2019-03-15 09:21:10 +08006312 if (phone != null) {
6313 return phone.hasMatchedTetherApnSetting();
6314 } else {
6315 return false;
6316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 } finally {
6318 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006319 }
Junda Liu475951f2014-11-07 16:45:03 -08006320 }
6321
6322 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006323 * Enable or disable always reporting signal strength changes from radio.
6324 *
6325 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6326 */
6327 @Override
6328 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6329 enforceModifyPermission();
6330 enforceSystemCaller();
6331
6332 final long identity = Binder.clearCallingIdentity();
6333 final Phone phone = getPhone(subId);
6334 try {
6335 if (phone != null) {
6336 if (DBG) {
6337 log("setAlwaysReportSignalStrength: subId=" + subId
6338 + " isEnable=" + isEnable);
6339 }
6340 phone.setAlwaysReportSignalStrength(isEnable);
6341 } else {
6342 loge("setAlwaysReportSignalStrength: no phone found for subId="
6343 + subId);
6344 }
6345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
6348 }
6349
6350 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006351 * Get the user enabled state of Mobile Data.
6352 *
6353 * TODO: remove and use isUserDataEnabled.
6354 * This can't be removed now because some vendor codes
6355 * calls through ITelephony directly while they should
6356 * use TelephonyManager.
6357 *
6358 * @return true on enabled
6359 */
6360 @Override
6361 public boolean getDataEnabled(int subId) {
6362 return isUserDataEnabled(subId);
6363 }
6364
6365 /**
6366 * Get whether mobile data is enabled per user setting.
6367 *
6368 * There are other factors deciding whether mobile data is actually enabled, but they are
6369 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006370 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006371 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006372 *
6373 * @return {@code true} if data is enabled else {@code false}
6374 */
6375 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006376 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006377 try {
6378 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6379 null);
6380 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6382 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006383 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006384
6385 final long identity = Binder.clearCallingIdentity();
6386 try {
6387 int phoneId = mSubscriptionController.getPhoneId(subId);
6388 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6389 Phone phone = PhoneFactory.getPhone(phoneId);
6390 if (phone != null) {
6391 boolean retVal = phone.isUserDataEnabled();
6392 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6393 return retVal;
6394 } else {
6395 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6396 return false;
6397 }
6398 } finally {
6399 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006400 }
6401 }
6402
6403 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006404 * Checks if the device is capable of mobile data by considering whether whether the
6405 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6406 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006407 *
Shuo Qian985d1232020-01-08 14:30:06 -08006408 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006409 */
6410 @Override
6411 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006412 try {
6413 try {
6414 mApp.enforceCallingOrSelfPermission(
6415 android.Manifest.permission.ACCESS_NETWORK_STATE,
6416 null);
6417 } catch (Exception e) {
6418 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6419 "isDataEnabled");
6420 }
6421 } catch (Exception e) {
6422 enforceReadPrivilegedPermission("isDataEnabled");
6423 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424
6425 final long identity = Binder.clearCallingIdentity();
6426 try {
6427 int phoneId = mSubscriptionController.getPhoneId(subId);
6428 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6429 Phone phone = PhoneFactory.getPhone(phoneId);
6430 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006431 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6433 return retVal;
6434 } else {
6435 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6436 return false;
6437 }
6438 } finally {
6439 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006440 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006441 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006442
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006443 /**
6444 * Check if data is enabled for a specific reason
6445 * @param subId Subscription index
6446 * @param reason the reason the data enable change is taking place
6447 * @return {@code true} if the overall data is enabled; {@code false} if not.
6448 */
6449 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006450 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006451 @TelephonyManager.DataEnabledReason int reason) {
6452 try {
6453 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6454 null);
6455 } catch (Exception e) {
6456 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006457 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006458 }
6459
6460
6461 final long identity = Binder.clearCallingIdentity();
6462 try {
6463 int phoneId = mSubscriptionController.getPhoneId(subId);
6464 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006465 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006466 + " reason=" + reason);
6467 }
6468 Phone phone = PhoneFactory.getPhone(phoneId);
6469 if (phone != null) {
6470 boolean retVal;
6471 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6472 retVal = phone.isUserDataEnabled();
6473 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006474 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006475 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006476 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006477 return retVal;
6478 } else {
6479 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006480 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006481 + subId + " retVal=false");
6482 }
6483 return false;
6484 }
6485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
6488 }
6489
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006490 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006491 Phone phone) {
Sarah Chinca45c312021-04-09 10:37:15 -07006492 if (uid == Process.PHONE_UID) {
6493 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6494 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liuce478d22020-07-13 12:13:03 -07006495 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6496 }
6497
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006498 //load access rules from carrier configs, and check those as well: b/139133814
6499 SubscriptionController subController = SubscriptionController.getInstance();
6500 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6501 || subController == null) return privilegeFromSim;
6502
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006503 PackageManager pkgMgr = phone.getContext().getPackageManager();
6504 String[] packages = pkgMgr.getPackagesForUid(uid);
6505
6506 final long identity = Binder.clearCallingIdentity();
6507 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006508 int subId = phone.getSubId();
6509 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6510 // A test override is in place for the privileges for this subId, so don't try to
6511 // read the subscription privileges.
6512 return privilegeFromSim;
6513 }
6514 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006515 SubscriptionManager subManager = (SubscriptionManager)
6516 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6517 for (String pkg : packages) {
6518 if (subManager.canManageSubscription(subInfo, pkg)) {
6519 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6520 }
6521 }
6522 return privilegeFromSim;
6523 } finally {
6524 Binder.restoreCallingIdentity(identity);
6525 }
6526 }
6527
6528 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6529 String pkgName) {
6530 //load access rules from carrier configs, and check those as well: b/139133814
6531 SubscriptionController subController = SubscriptionController.getInstance();
6532 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6533 || subController == null) return privilegeFromSim;
6534
6535 final long identity = Binder.clearCallingIdentity();
6536 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006537 int subId = phone.getSubId();
6538 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6539 // A test override is in place for the privileges for this subId, so don't try to
6540 // read the subscription privileges.
6541 return privilegeFromSim;
6542 }
6543 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006544 SubscriptionManager subManager = (SubscriptionManager)
6545 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6546 return subManager.canManageSubscription(subInfo, pkgName)
6547 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6548 } finally {
6549 Binder.restoreCallingIdentity(identity);
6550 }
6551 }
6552
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006553 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006554 public int getCarrierPrivilegeStatus(int subId) {
6555 final Phone phone = getPhone(subId);
6556 if (phone == null) {
6557 loge("getCarrierPrivilegeStatus: Invalid subId");
6558 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6559 }
6560 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006561 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006562 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006563 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6564 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006565
6566 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6567 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006568 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006569 }
Junda Liu29340342014-07-10 15:23:27 -07006570
6571 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006572 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006573 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006574 final Phone phone = getPhone(subId);
6575 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006576 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006577 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6578 }
6579 UiccProfile profile =
6580 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6581 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006582 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006583 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6584 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006585 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006586 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006587 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006588 }
6589
6590 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006591 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6592 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006593 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006594 }
6595
6596 int phoneId = SubscriptionManager.getPhoneId(subId);
6597 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006598 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006599 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006600 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6601 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006602 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6603 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6604 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006605 }
6606
6607 @Override
6608 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006609 if (TextUtils.isEmpty(pkgName))
6610 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006611 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6612 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6613 UiccCard card = UiccController.getInstance().getUiccCard(i);
6614 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006615 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006616 continue;
6617 }
6618
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006619 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6620 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6621 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006622 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6623 break;
6624 }
6625 }
6626
6627 return result;
Junda Liu29340342014-07-10 15:23:27 -07006628 }
Derek Tan89e89d42014-07-08 17:00:10 -07006629
6630 @Override
Junda Liue64de782015-04-16 17:19:16 -07006631 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6632 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6633 loge("phoneId " + phoneId + " is not valid.");
6634 return null;
6635 }
6636 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006637 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006638 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006639 return null ;
6640 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006641 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006642 }
6643
Amith Yamasani6e118872016-02-19 12:53:51 -08006644 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006645 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006646 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006647 List<String> privilegedPackages = new ArrayList<>();
6648 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006649 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6650 // has UICC in that slot.
6651 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006652 if (card.hasCarrierPrivilegeRules()) {
6653 if (packages == null) {
6654 // Only check packages in user 0 for now
6655 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006656 PackageManager.MATCH_DISABLED_COMPONENTS
6657 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006658 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006659 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006660 }
6661 for (int p = packages.size() - 1; p >= 0; p--) {
6662 PackageInfo pkgInfo = packages.get(p);
6663 if (pkgInfo != null && pkgInfo.packageName != null
6664 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006665 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006666 privilegedPackages.add(pkgInfo.packageName);
6667 }
6668 }
6669 }
6670 }
6671 return privilegedPackages;
6672 }
6673
chen xuf7e9fe82019-05-09 19:31:02 -07006674 @Override
6675 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006676 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6677
6678 final long identity = Binder.clearCallingIdentity();
6679
chen xuf7e9fe82019-05-09 19:31:02 -07006680 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006681 try {
6682 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6683 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6684 }
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006687 }
6688 return privilegedPackages;
6689 }
6690
Wink Savilleb564aae2014-10-23 10:18:09 -07006691 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006692 final Phone phone = getPhone(subId);
6693 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006694 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006695 return null;
6696 }
6697 String iccId = card.getIccId();
6698 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006699 return null;
6700 }
6701 return iccId;
6702 }
6703
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006704 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006705 public void setCallComposerStatus(int subId, int status) {
6706 enforceModifyPermission();
6707
6708 final long identity = Binder.clearCallingIdentity();
6709 try {
6710 Phone phone = getPhone(subId);
6711 if (phone != null) {
6712 Phone defaultPhone = phone.getImsPhone();
6713 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6714 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6715 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006716 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6717 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006718 }
6719 }
Shuo Qiand8782462020-12-22 19:10:14 -08006720 } catch (ImsException e) {
6721 throw new ServiceSpecificException(e.getCode());
6722 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006723 Binder.restoreCallingIdentity(identity);
6724 }
6725 }
6726
6727 @Override
6728 public int getCallComposerStatus(int subId) {
6729 enforceReadPrivilegedPermission("getCallComposerStatus");
6730
6731 final long identity = Binder.clearCallingIdentity();
6732 try {
6733 Phone phone = getPhone(subId);
6734 if (phone != null) {
6735 Phone defaultPhone = phone.getImsPhone();
6736 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6737 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6738 return imsPhone.getCallComposerStatus();
6739 }
6740 }
6741 } finally {
6742 Binder.restoreCallingIdentity(identity);
6743 }
6744 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6745 }
6746
6747 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006748 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6749 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006750 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006751 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006753 final long identity = Binder.clearCallingIdentity();
6754 try {
6755 final String iccId = getIccId(subId);
6756 final Phone phone = getPhone(subId);
6757 if (phone == null) {
6758 return false;
6759 }
6760 final String subscriberId = phone.getSubscriberId();
6761
6762 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006763 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006764 + subscriberId + " to " + number);
6765 }
6766
6767 if (TextUtils.isEmpty(iccId)) {
6768 return false;
6769 }
6770
6771 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6772
6773 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6774 if (alphaTag == null) {
6775 editor.remove(alphaTagPrefKey);
6776 } else {
6777 editor.putString(alphaTagPrefKey, alphaTag);
6778 }
6779
6780 // Record both the line number and IMSI for this ICCID, since we need to
6781 // track all merged IMSIs based on line number
6782 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6783 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6784 if (number == null) {
6785 editor.remove(numberPrefKey);
6786 editor.remove(subscriberPrefKey);
6787 } else {
6788 editor.putString(numberPrefKey, number);
6789 editor.putString(subscriberPrefKey, subscriberId);
6790 }
6791
6792 editor.commit();
6793 return true;
6794 } finally {
6795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006796 }
Derek Tan7226c842014-07-02 17:42:23 -07006797 }
6798
6799 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006800 public String getLine1NumberForDisplay(int subId, String callingPackage,
6801 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006802 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006804 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006805 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
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 numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6814 if (DBG_MERGE) {
6815 log("getLine1NumberForDisplay returning "
6816 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6817 }
6818 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006819 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006820 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6821 return null;
6822 } finally {
6823 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006824 }
Derek Tan7226c842014-07-02 17:42:23 -07006825 }
6826
6827 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006828 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6829 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006831 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006832 return null;
6833 }
Derek Tan97ebb422014-09-05 16:55:38 -07006834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835 final long identity = Binder.clearCallingIdentity();
6836 try {
6837 String iccId = getIccId(subId);
6838 if (iccId != null) {
6839 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6840 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6841 }
6842 return null;
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006845 }
Derek Tan7226c842014-07-02 17:42:23 -07006846 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006847
6848 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006849 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6850 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006851 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6852 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006853 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006854 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006855 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006856 return null;
6857 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006858
Jordan Liub49b04b2019-05-06 14:45:15 -07006859 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6860 // the process, where TelephonyManager was instantiated.
6861 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006862 final long identity = Binder.clearCallingIdentity();
6863 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006864 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 final TelephonyManager tele = TelephonyManager.from(context);
6866 final SubscriptionManager sub = SubscriptionManager.from(context);
6867
6868 // Figure out what subscribers are currently active
6869 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006870
Jordan Liub49b04b2019-05-06 14:45:15 -07006871 // Only consider subs which match the current subId
6872 // This logic can be simplified. See b/131189269 for progress.
6873 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006874 activeSubscriberIds.add(tele.getSubscriberId(subId));
6875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876
6877 // First pass, find a number override for an active subscriber
6878 String mergeNumber = null;
6879 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6880 for (String key : prefs.keySet()) {
6881 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6882 final String subscriberId = (String) prefs.get(key);
6883 if (activeSubscriberIds.contains(subscriberId)) {
6884 final String iccId = key.substring(
6885 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6886 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6887 mergeNumber = (String) prefs.get(numberKey);
6888 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006889 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890 + " for active subscriber " + subscriberId);
6891 }
6892 if (!TextUtils.isEmpty(mergeNumber)) {
6893 break;
6894 }
6895 }
6896 }
6897 }
6898
6899 // Shortcut when no active merged subscribers
6900 if (TextUtils.isEmpty(mergeNumber)) {
6901 return null;
6902 }
6903
6904 // Second pass, find all subscribers under that line override
6905 final ArraySet<String> result = new ArraySet<>();
6906 for (String key : prefs.keySet()) {
6907 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6908 final String number = (String) prefs.get(key);
6909 if (mergeNumber.equals(number)) {
6910 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6911 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6912 final String subscriberId = (String) prefs.get(subscriberKey);
6913 if (!TextUtils.isEmpty(subscriberId)) {
6914 result.add(subscriberId);
6915 }
6916 }
6917 }
6918 }
6919
6920 final String[] resultArray = result.toArray(new String[result.size()]);
6921 Arrays.sort(resultArray);
6922 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006923 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006924 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6925 }
6926 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006927 } finally {
6928 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006929 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006930 }
6931
6932 @Override
zoey chen38003472019-12-13 17:16:31 +08006933 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6934 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006935
6936 final long identity = Binder.clearCallingIdentity();
6937 try {
6938 final TelephonyManager telephonyManager = mApp.getSystemService(
6939 TelephonyManager.class);
6940 String subscriberId = telephonyManager.getSubscriberId(subId);
6941 if (subscriberId == null) {
6942 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006943 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006944 + subId);
6945 }
6946 return null;
6947 }
6948
6949 final SubscriptionInfo info = SubscriptionController.getInstance()
6950 .getSubscriptionInfo(subId);
6951 final ParcelUuid groupUuid = info.getGroupUuid();
6952 // If it doesn't belong to any group, return just subscriberId of itself.
6953 if (groupUuid == null) {
6954 return new String[]{subscriberId};
6955 }
6956
6957 // Get all subscriberIds from the group.
6958 final List<String> mergedSubscriberIds = new ArrayList<>();
6959 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006960 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006961 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006962 for (SubscriptionInfo subInfo : groupInfos) {
6963 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6964 if (subscriberId != null) {
6965 mergedSubscriberIds.add(subscriberId);
6966 }
6967 }
6968
6969 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6970 } finally {
6971 Binder.restoreCallingIdentity(identity);
6972
6973 }
6974 }
6975
6976 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006977 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006978 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006979 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980
6981 final long identity = Binder.clearCallingIdentity();
6982 try {
6983 final Phone phone = getPhone(subId);
6984 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6985 } finally {
6986 Binder.restoreCallingIdentity(identity);
6987 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006988 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006989
6990 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006991 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006992 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6993 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006994 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6995 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996
6997 final long identity = Binder.clearCallingIdentity();
6998 try {
6999 final Phone phone = getPhone(subId);
7000 if (phone == null) {
7001 return false;
7002 }
7003 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7004 cdmaNonRoamingList);
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007007 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007008 }
7009
7010 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007011 @Deprecated
7012 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7013 enforceModifyPermission();
7014
7015 int returnValue = 0;
7016 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007017 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007018 if(result.exception == null) {
7019 if (result.result != null) {
7020 byte[] responseData = (byte[])(result.result);
7021 if(responseData.length > oemResp.length) {
7022 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7023 responseData.length + "bytes. Buffer Size is " +
7024 oemResp.length + "bytes.");
7025 }
7026 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7027 returnValue = responseData.length;
7028 }
7029 } else {
7030 CommandException ex = (CommandException) result.exception;
7031 returnValue = ex.getCommandError().ordinal();
7032 if(returnValue > 0) returnValue *= -1;
7033 }
7034 } catch (RuntimeException e) {
7035 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7036 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7037 if(returnValue > 0) returnValue *= -1;
7038 }
7039
7040 return returnValue;
7041 }
7042
7043 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007044 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007045 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007046 try {
7047 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007048 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007049 mApp, phone.getSubId(), "getRadioAccessFamily");
7050 } catch (SecurityException e) {
7051 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7052 throw e;
7053 }
chen xub97461a2018-10-26 14:17:57 -07007054 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007055 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007056 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007057 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 final long identity = Binder.clearCallingIdentity();
7059 try {
chen xub97461a2018-10-26 14:17:57 -07007060 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07007061 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007062 mApp, phone.getSubId(), "getRadioAccessFamily");
7063 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064 } finally {
7065 Binder.restoreCallingIdentity(identity);
7066 }
chen xub97461a2018-10-26 14:17:57 -07007067 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007068 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007069
7070 @Override
7071 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007072 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007073 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074
7075 final long identity = Binder.clearCallingIdentity();
7076 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007077 ImsManager.getInstance(defaultPhone.getContext(),
7078 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079 } finally {
7080 Binder.restoreCallingIdentity(identity);
7081 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007082 }
7083
7084 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007085 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007086 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7088 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007089 return false;
7090 }
Svet Ganovb320e182015-04-16 12:30:10 -07007091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 // Check the user preference and the system-level IMS setting. Even if the user has
7095 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7096 // In the long run, we may instead need to check if there exists a connection service
7097 // which can support video calling.
7098 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007099 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100 return imsManager.isVtEnabledByPlatform()
7101 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7102 && imsManager.isVtEnabledByUser();
7103 } finally {
7104 Binder.restoreCallingIdentity(identity);
7105 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007106 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007107
Andrew Leea1239f22015-03-02 17:44:07 -08007108 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007109 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7110 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007112 mApp, subId, callingPackage, callingFeatureId,
7113 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007114 return false;
7115 }
7116
7117 final long identity = Binder.clearCallingIdentity();
7118 try {
7119 CarrierConfigManager configManager =
7120 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007121 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7123 } finally {
7124 Binder.restoreCallingIdentity(identity);
7125 }
Andrew Leea1239f22015-03-02 17:44:07 -08007126 }
7127
7128 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007129 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007131 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007132 return false;
7133 }
7134
7135 final long identity = Binder.clearCallingIdentity();
7136 try {
7137 CarrierConfigManager configManager =
7138 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007139 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
Andrew Leea1239f22015-03-02 17:44:07 -08007144 }
7145
Andrew Lee9431b832015-03-09 18:46:45 -07007146 @Override
7147 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007148 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007149 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007150 }
7151
7152 @Override
7153 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154 final long identity = Binder.clearCallingIdentity();
7155 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007156 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 } finally {
7158 Binder.restoreCallingIdentity(identity);
7159 }
Andrew Lee9431b832015-03-09 18:46:45 -07007160 }
7161
Hall Liuf6668912018-10-31 17:05:23 -07007162 /**
7163 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7164 * support for the feature and device firmware support.
7165 *
7166 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7167 */
7168 @Override
7169 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007170 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007171 final Phone phone = getPhone(subscriptionId);
7172 if (phone == null) {
7173 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7174 return false;
7175 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007177 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7179 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007180 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 return isCarrierSupported && isDeviceSupported;
7182 } finally {
7183 Binder.restoreCallingIdentity(identity);
7184 }
Hall Liu98187582018-01-22 19:15:32 -08007185 }
7186
Hall Liuf6668912018-10-31 17:05:23 -07007187 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007188 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7189 * RTT setting, will return true if the device and carrier both support RTT.
7190 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007191 */
7192 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193 final long identity = Binder.clearCallingIdentity();
7194 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007195 boolean isRttSupported = isRttSupported(subscriptionId);
7196 boolean isUserRttSettingOn = Settings.Secure.getInt(
7197 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7198 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7199 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7200 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 } finally {
7202 Binder.restoreCallingIdentity(identity);
7203 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007204 }
7205
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007206 @Deprecated
7207 @Override
7208 public String getDeviceId(String callingPackage) {
7209 return getDeviceIdWithFeature(callingPackage, null);
7210 }
7211
Sanket Padawe7310cc72015-01-14 09:53:20 -08007212 /**
7213 * Returns the unique device ID of phone, for example, the IMEI for
7214 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7215 *
7216 * <p>Requires Permission:
7217 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7218 */
7219 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007220 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007221 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007222 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007223 return null;
7224 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007225 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007226 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007227 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007228 return null;
7229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230
7231 final long identity = Binder.clearCallingIdentity();
7232 try {
7233 return phone.getDeviceId();
7234 } finally {
7235 Binder.restoreCallingIdentity(identity);
7236 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007237 }
7238
Ping Sunc67b7c22016-03-02 19:16:45 +08007239 /**
7240 * {@hide}
7241 * Returns the IMS Registration Status on a particular subid
7242 *
7243 * @param subId
7244 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007245 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007246 Phone phone = getPhone(subId);
7247 if (phone != null) {
7248 return phone.isImsRegistered();
7249 } else {
7250 return false;
7251 }
7252 }
7253
Santos Cordon7a1885b2015-02-03 11:15:19 -08007254 @Override
7255 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256 final long identity = Binder.clearCallingIdentity();
7257 try {
7258 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7259 } finally {
7260 Binder.restoreCallingIdentity(identity);
7261 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007262 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007263
Tyler Gunnf70ed162019-04-03 15:28:53 -07007264 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007265 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007266 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007268 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007269 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7270 }
7271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7274 } finally {
7275 Binder.restoreCallingIdentity(identity);
7276 }
7277 }
7278
7279 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007280 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007281 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7282 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 Phone phone = getPhone(subscriptionId);
7286 if (phone == null) {
7287 return null;
7288 }
7289 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7290 } finally {
7291 Binder.restoreCallingIdentity(identity);
7292 }
7293 }
7294
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007295 /**
7296 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007297 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007298 public boolean isWifiCallingAvailable(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.isWifiCallingEnabled();
7304 } else {
7305 return false;
7306 }
7307 } finally {
7308 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007309 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007310 }
7311
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007312 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007313 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007314 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007315 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007316 final long identity = Binder.clearCallingIdentity();
7317 try {
7318 Phone phone = getPhone(subId);
7319 if (phone != null) {
7320 return phone.isVideoEnabled();
7321 } else {
7322 return false;
7323 }
7324 } finally {
7325 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007326 }
7327 }
7328
7329 /**
7330 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7331 * defined in {@link ImsRegistrationImplBase}.
7332 */
7333 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007334 final long identity = Binder.clearCallingIdentity();
7335 try {
7336 Phone phone = getPhone(subId);
7337 if (phone != null) {
7338 return phone.getImsRegistrationTech();
7339 } else {
7340 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7341 }
7342 } finally {
7343 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007344 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007345 }
7346
Stuart Scott8eef64f2015-04-08 15:13:54 -07007347 @Override
7348 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007349 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007350 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7351 return;
7352 }
7353
Svet Ganovcc087f82015-05-12 20:35:54 -07007354 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007355
Svet Ganovcc087f82015-05-12 20:35:54 -07007356 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007357 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7358 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007359 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007360 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007361 setNetworkSelectionModeAutomatic(subId);
SongFerngWang522637d2021-03-02 22:09:29 +08007362 Phone phone = getPhone(subId);
SongFerngWang51ee2b12021-05-27 22:44:54 +08007363 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007364 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7365 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007366 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007367 // There has been issues when Sms raw table somehow stores orphan
7368 // fragments. They lead to garbled message when new fragments come
7369 // in and combined with those stale ones. In case this happens again,
7370 // user can reset all network settings which will clean up this table.
7371 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007372 // Clean up IMS settings as well here.
7373 int slotId = getSlotIndex(subId);
7374 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7375 ImsManager.getInstance(mApp, slotId).factoryReset();
7376 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007377
7378 // Erase modem config if erase modem on network setting is enabled.
7379 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7380 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7381 if (configValue != null && Boolean.parseBoolean(configValue)) {
7382 sendEraseModemConfig(getDefaultPhone());
7383 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007384 } finally {
7385 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007386 }
7387 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007388
SongFerngWang51ee2b12021-05-27 22:44:54 +08007389 @VisibleForTesting
7390 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7391 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7392 return;
7393 }
7394 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7395 RILConstants.PREFERRED_NETWORK_MODE);
7396 SubscriptionManager.setSubscriptionProperty(subId,
7397 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7398 "user=" + defaultNetworkType);
7399 phone.loadAllowedNetworksFromSubscriptionDatabase();
7400 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7401 defaultNetworkType, null);
7402 }
7403
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007404 private void cleanUpSmsRawTable(Context context) {
7405 ContentResolver resolver = context.getContentResolver();
7406 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7407 resolver.delete(uri, null, null);
7408 }
7409
Narayan Kamath1c496c22015-04-16 14:40:19 +01007410 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007411 public String getSimLocaleForSubscriber(int subId) {
7412 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7413 final Phone phone = getPhone(subId);
7414 if (phone == null) {
7415 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007416 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418 final long identity = Binder.clearCallingIdentity();
7419 try {
chen xu5d3637b2019-01-21 23:31:38 -08007420 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007421 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007422 if (info == null) {
7423 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7424 return null;
7425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 // Try and fetch the locale from the carrier properties or from the SIM language
7427 // preferences (EF-PL and EF-LI)...
7428 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007430 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7431 if (localeFromDefaultSim != null) {
7432 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7433 if (DBG) log("Using locale from subId: " + subId + " locale: "
7434 + localeFromDefaultSim);
7435 return localeFromDefaultSim.toLanguageTag();
7436 } else {
7437 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 }
7439 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 // The SIM language preferences only store a language (e.g. fr = French), not an
7442 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7443 // the SIM and carrier preferences does not include a country we add the country
7444 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007445 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007446 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007447 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448 return mccLocale.toLanguageTag();
7449 }
7450
7451 if (DBG) log("No locale found - returning null");
7452 return null;
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
7455 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007456 }
7457
7458 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007459 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007460 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007461 }
7462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 /**
7464 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7465 */
7466 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007467 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007468 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007469 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007470
Chenjie Yu1ba97252018-01-11 18:16:20 -08007471 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liue8315982020-10-09 19:00:11 -07007472 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007473
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007474 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007475 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7476 * representing the state of the modem.
7477 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007478 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7479 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007480 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007481 */
7482 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007483 public void requestModemActivityInfo(ResultReceiver result) {
7484 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486
7487 final long identity = Binder.clearCallingIdentity();
7488 try {
sqian1a1be542020-03-05 11:37:28 -08007489 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 } finally {
7491 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007492 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007493 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007494
Siddharth Rayb8114062018-06-17 15:02:38 -07007495 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7496 // less than total activity duration.
7497 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7498 if (info == null) {
7499 return false;
7500 }
7501 int activityDurationMs =
Hall Liue8315982020-10-09 19:00:11 -07007502 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7503 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7504
Siddharth Rayb8114062018-06-17 15:02:38 -07007505 return (info.isValid()
7506 && (info.getSleepTimeMillis() <= activityDurationMs)
7507 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007508 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007509 && (totalTxTimeMs <= activityDurationMs));
7510 }
7511
Jack Yu85bd38a2015-11-09 11:34:32 -08007512 /**
7513 * {@hide}
7514 * Returns the service state information on specified subscription.
7515 */
7516 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007517 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7518 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007519 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007520 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007521 return null;
7522 }
7523
Hall Liuf19c44f2018-11-27 14:38:17 -08007524 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7525 LocationAccessPolicy.checkLocationPermission(mApp,
7526 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7527 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007528 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007529 .setCallingPid(Binder.getCallingPid())
7530 .setCallingUid(Binder.getCallingUid())
7531 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007532 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007533 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007534 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7535 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007536 .build());
7537
7538 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7539 LocationAccessPolicy.checkLocationPermission(mApp,
7540 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7541 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007542 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007543 .setCallingPid(Binder.getCallingPid())
7544 .setCallingUid(Binder.getCallingUid())
7545 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007546 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007547 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liu008b1692020-05-26 17:18:03 -07007548 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7549 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007550 .build());
7551 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7552 boolean hasFinePermission =
7553 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7554 boolean hasCoarsePermission =
7555 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 final long identity = Binder.clearCallingIdentity();
7558 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007559 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7560 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7561 Rlog.d(LOG_TAG,
7562 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7563 return null;
7564 }
7565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007566 final Phone phone = getPhone(subId);
7567 if (phone == null) {
7568 return null;
7569 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007570
Hall Liuf19c44f2018-11-27 14:38:17 -08007571 ServiceState ss = phone.getServiceState();
7572
7573 // Scrub out the location info in ServiceState depending on what level of access
7574 // the caller has.
7575 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007576 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7577 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007578 } finally {
7579 Binder.restoreCallingIdentity(identity);
7580 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007581 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007582
7583 /**
7584 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7585 *
7586 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7587 * voicemail ringtone.
7588 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7589 * PhoneAccount.
7590 */
7591 @Override
7592 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 final long identity = Binder.clearCallingIdentity();
7594 try {
7595 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7596 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007597 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007598 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7601 } finally {
7602 Binder.restoreCallingIdentity(identity);
7603 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007604 }
7605
7606 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007607 * Sets the per-account voicemail ringtone.
7608 *
7609 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7610 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7611 *
7612 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7613 * voicemail ringtone.
7614 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7615 * PhoneAccount.
7616 */
7617 @Override
7618 public void setVoicemailRingtoneUri(String callingPackage,
7619 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007620 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007621 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007622 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7623 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7625 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7626 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007627 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007628
7629 final long identity = Binder.clearCallingIdentity();
7630 try {
7631 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7632 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007633 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 }
7635 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7636 } finally {
7637 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007638 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007639 }
7640
7641 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007642 * Returns whether vibration is set for voicemail notification in Phone settings.
7643 *
7644 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7645 * voicemail vibration setting.
7646 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7647 */
7648 @Override
7649 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7653 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007654 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007655 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007661 }
7662
Youhan Wange64578a2016-05-02 15:32:42 -07007663 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007664 * Sets the per-account voicemail vibration.
7665 *
7666 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7667 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7668 *
7669 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7670 * voicemail vibration setting.
7671 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7672 * specific PhoneAccount.
7673 */
7674 @Override
7675 public void setVoicemailVibrationEnabled(String callingPackage,
7676 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007677 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007678 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007679 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7680 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7682 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7683 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007684 }
7685
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 final long identity = Binder.clearCallingIdentity();
7687 try {
7688 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7689 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007690 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 }
7692 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7693 } finally {
7694 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007695 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007696 }
7697
7698 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007699 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7700 *
7701 * @throws SecurityException if the caller does not have the required permission
7702 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007703 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007704 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007705 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007706 }
7707
7708 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007709 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7710 * permission.
7711 *
7712 * @throws SecurityException if the caller does not have the required permission
7713 */
7714 private void enforceSendSmsPermission() {
7715 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7716 }
7717
7718 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007719 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007720 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007721 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007722 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007723 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007727 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728 if (componentName == null) {
7729 throw new SecurityException(
7730 "Caller not current active visual voicemail package[null]");
7731 }
7732 String vvmPackage = componentName.getPackageName();
7733 if (!callingPackage.equals(vvmPackage)) {
7734 throw new SecurityException("Caller not current active visual voicemail package["
7735 + vvmPackage + "]");
7736 }
7737 } finally {
7738 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007739 }
7740 }
7741
7742 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007743 * Return the application ID for the app type.
7744 *
7745 * @param subId the subscription ID that this request applies to.
7746 * @param appType the uicc app type.
7747 * @return Application ID for specificied app type, or null if no uicc.
7748 */
7749 @Override
7750 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007751 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007752 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753
7754 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007755 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756 if (phone == null) {
7757 return null;
7758 }
7759 String aid = null;
7760 try {
7761 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7762 .getApplicationByType(appType).getAid();
7763 } catch (Exception e) {
7764 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7765 }
7766 return aid;
7767 } finally {
7768 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007769 }
Youhan Wange64578a2016-05-02 15:32:42 -07007770 }
7771
Youhan Wang4001d252016-05-11 10:29:41 -07007772 /**
7773 * Return the Electronic Serial Number.
7774 *
7775 * @param subId the subscription ID that this request applies to.
7776 * @return ESN or null if error.
7777 */
7778 @Override
7779 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007780 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007781 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782
7783 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007784 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785 if (phone == null) {
7786 return null;
7787 }
7788 String esn = null;
7789 try {
7790 esn = phone.getEsn();
7791 } catch (Exception e) {
7792 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7793 }
7794 return esn;
7795 } finally {
7796 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007797 }
Youhan Wang4001d252016-05-11 10:29:41 -07007798 }
7799
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007800 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007801 * Return the Preferred Roaming List Version.
7802 *
7803 * @param subId the subscription ID that this request applies to.
7804 * @return PRLVersion or null if error.
7805 */
7806 @Override
7807 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007808 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007809 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810
7811 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007812 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 if (phone == null) {
7814 return null;
7815 }
7816 String cdmaPrlVersion = null;
7817 try {
7818 cdmaPrlVersion = phone.getCdmaPrlVersion();
7819 } catch (Exception e) {
7820 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7821 }
7822 return cdmaPrlVersion;
7823 } finally {
7824 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007825 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007826 }
7827
7828 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007829 * Get snapshot of Telephony histograms
7830 * @return List of Telephony histograms
7831 * @hide
7832 */
7833 @Override
7834 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7836 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837
7838 final long identity = Binder.clearCallingIdentity();
7839 try {
7840 return RIL.getTelephonyRILTimingHistograms();
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007844 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007845
7846 /**
7847 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007848 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7849 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007850 * Require system privileges. In the future we may add this to carrier APIs.
7851 *
Michele Berionne482f8202018-11-27 18:57:59 -08007852 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007853 */
7854 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007855 @TelephonyManager.SetCarrierRestrictionResult
7856 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007857 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007858 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007859
Michele Berionne482f8202018-11-27 18:57:59 -08007860 if (carrierRestrictionRules == null) {
7861 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007862 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007863
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 final long identity = Binder.clearCallingIdentity();
7865 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007866 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007867 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 } finally {
7869 Binder.restoreCallingIdentity(identity);
7870 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007871 }
7872
7873 /**
7874 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007875 * Get the allowed carrier list and the excluded carrier list, including the priority between
7876 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007877 * Require system privileges. In the future we may add this to carrier APIs.
7878 *
Michele Berionne482f8202018-11-27 18:57:59 -08007879 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007880 */
7881 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007882 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007883 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007884 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885
7886 final long identity = Binder.clearCallingIdentity();
7887 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007888 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7889 if (response instanceof CarrierRestrictionRules) {
7890 return (CarrierRestrictionRules) response;
7891 }
7892 // Response is an Exception of some kind,
7893 // which is signalled to the user as a NULL retval
7894 return null;
7895 } catch (Exception e) {
7896 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7897 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 } finally {
7899 Binder.restoreCallingIdentity(identity);
7900 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007901 }
7902
fionaxu59545b42016-05-25 15:53:37 -07007903 /**
fionaxu59545b42016-05-25 15:53:37 -07007904 * Action set from carrier signalling broadcast receivers to enable/disable radio
7905 * @param subId the subscription ID that this action applies to.
7906 * @param enabled control enable or disable radio.
7907 * {@hide}
7908 */
7909 @Override
7910 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7911 enforceModifyPermission();
7912 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007913
7914 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007915 if (phone == null) {
7916 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7917 return;
7918 }
7919 try {
7920 phone.carrierActionSetRadioEnabled(enabled);
7921 } catch (Exception e) {
7922 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923 } finally {
7924 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007925 }
7926 }
7927
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007928 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007929 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7930 * network status based on which carrier apps could apply actions accordingly,
7931 * enable/disable default url handler for example.
7932 *
7933 * @param subId the subscription ID that this action applies to.
7934 * @param report control start/stop reporting the default network status.
7935 * {@hide}
7936 */
7937 @Override
7938 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7939 enforceModifyPermission();
7940 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007941
7942 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007943 if (phone == null) {
7944 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7945 return;
7946 }
7947 try {
7948 phone.carrierActionReportDefaultNetworkStatus(report);
7949 } catch (Exception e) {
7950 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951 } finally {
7952 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007953 }
7954 }
7955
7956 /**
fionaxud9622282017-07-17 17:51:30 -07007957 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7958 * @param subId the subscription ID that this action applies to.
7959 * {@hide}
7960 */
7961 @Override
7962 public void carrierActionResetAll(int subId) {
7963 enforceModifyPermission();
7964 final Phone phone = getPhone(subId);
7965 if (phone == null) {
7966 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7967 return;
7968 }
7969 try {
7970 phone.carrierActionResetAll();
7971 } catch (Exception e) {
7972 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7973 }
7974 }
7975
7976 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007977 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7978 * bug report is being generated.
7979 */
7980 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007981 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007982 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7983 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007984 writer.println("Permission Denial: can't dump Phone from pid="
7985 + Binder.getCallingPid()
7986 + ", uid=" + Binder.getCallingUid()
7987 + "without permission "
7988 + android.Manifest.permission.DUMP);
7989 return;
7990 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007991 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007992 }
Jack Yueb89b242016-06-22 13:27:47 -07007993
Brad Ebingerdac2f002018-04-03 15:17:52 -07007994 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007995 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7996 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7997 @NonNull String[] args) {
7998 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7999 this, in.getFileDescriptor(), out.getFileDescriptor(),
8000 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008001 }
8002
Jack Yueb89b242016-06-22 13:27:47 -07008003 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008004 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07008005 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008006 * @param reason the reason the data enable change is taking place
8007 * @param enabled True if enabling the data, otherwise disabling.
8008 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008009 */
8010 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07008011 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008012 boolean enabled) {
8013 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8014 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8015 try {
8016 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07008017 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008018 } catch (SecurityException se) {
8019 enforceModifyPermission();
8020 }
8021 } else {
8022 enforceModifyPermission();
8023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024
8025 final long identity = Binder.clearCallingIdentity();
8026 try {
8027 Phone phone = getPhone(subId);
8028 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07008029 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8030 phone.carrierActionSetMeteredApnsEnabled(enabled);
8031 } else {
8032 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008034 }
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008037 }
8038 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008039
8040 /**
8041 * Get Client request stats
8042 * @return List of Client Request Stats
8043 * @hide
8044 */
8045 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008046 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8047 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008049 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008050 return null;
8051 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008052 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 if (phone != null) {
8057 return phone.getClientRequestStats();
8058 }
8059
8060 return null;
8061 } finally {
8062 Binder.restoreCallingIdentity(identity);
8063 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008064 }
8065
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008066 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008067 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008068 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008069 }
Jack Yueb4124c2017-02-16 15:32:43 -08008070
8071 /**
Grace Chen70990072017-03-24 17:21:30 -07008072 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008073 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008074 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008075 * @param state State of SIM (power down, power up, pass through)
8076 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8077 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8078 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008079 *
8080 **/
8081 @Override
Grace Chen70990072017-03-24 17:21:30 -07008082 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008083 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008084 Phone phone = PhoneFactory.getPhone(slotIndex);
8085
vagdeviaf9a5b92018-08-15 16:01:53 -07008086 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008088 final long identity = Binder.clearCallingIdentity();
8089 try {
8090 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008091 phone.setSimPowerState(state, null, workSource);
8092 }
8093 } finally {
8094 Binder.restoreCallingIdentity(identity);
8095 }
8096 }
8097
8098 /**
8099 * Set SIM card power state.
8100 *
8101 * @param slotIndex SIM slot id.
8102 * @param state State of SIM (power down, power up, pass through)
8103 * @param callback callback to trigger after success or failure
8104 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8105 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8106 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8107 *
8108 **/
8109 @Override
8110 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8111 IIntegerConsumer callback) {
8112 enforceModifyPermission();
8113 Phone phone = PhoneFactory.getPhone(slotIndex);
8114
8115 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8116
8117 final long identity = Binder.clearCallingIdentity();
8118 try {
8119 if (phone != null) {
8120 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8121 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008122 }
8123 } finally {
8124 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008125 }
8126 }
Shuo Qiandd210312017-04-12 22:11:33 +00008127
Tyler Gunn65d45c22017-06-05 11:22:26 -07008128 private boolean isUssdApiAllowed(int subId) {
8129 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008130 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008131 if (configManager == null) {
8132 return false;
8133 }
8134 PersistableBundle pb = configManager.getConfigForSubId(subId);
8135 if (pb == null) {
8136 return false;
8137 }
8138 return pb.getBoolean(
8139 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8140 }
8141
Shuo Qiandd210312017-04-12 22:11:33 +00008142 /**
8143 * Check if phone is in emergency callback mode
8144 * @return true if phone is in emergency callback mode
8145 * @param subId sub id
8146 */
goneil9c5f4872017-12-05 14:07:56 -08008147 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008148 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008149 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008150 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008151
8152 final long identity = Binder.clearCallingIdentity();
8153 try {
8154 if (phone != null) {
8155 return phone.isInEcm();
8156 } else {
8157 return false;
8158 }
8159 } finally {
8160 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008161 }
8162 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008163
8164 /**
8165 * Get the current signal strength information for the given subscription.
8166 * Because this information is not updated when the device is in a low power state
8167 * it should not be relied-upon to be current.
8168 * @param subId Subscription index
8169 * @return the most recent cached signal strength info from the modem
8170 */
8171 @Override
8172 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 final long identity = Binder.clearCallingIdentity();
8174 try {
8175 Phone p = getPhone(subId);
8176 if (p == null) {
8177 return null;
8178 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008180 return p.getSignalStrength();
8181 } finally {
8182 Binder.restoreCallingIdentity(identity);
8183 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008184 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008185
Pengquan Meng77b7f132018-08-22 14:49:57 -07008186 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008187 * Get the current modem radio state for the given slot.
8188 * @param slotIndex slot index.
8189 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008190 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008191 * @return the current radio power state from the modem
8192 */
8193 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008194 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008195 Phone phone = PhoneFactory.getPhone(slotIndex);
8196 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8198 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008199 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8200 }
8201
8202 final long identity = Binder.clearCallingIdentity();
8203 try {
8204 return phone.getRadioPowerState();
8205 } finally {
8206 Binder.restoreCallingIdentity(identity);
8207 }
8208 }
8209 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8210 }
8211
8212 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008213 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8214 *
8215 * <p>Requires one of the following permissions:
8216 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8217 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8218 * privileges.
8219 *
8220 * @param subId subscription id
8221 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8222 * {@code false}.
8223 */
8224 @Override
8225 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008226 try {
8227 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8228 null);
8229 } catch (Exception e) {
Nathan Harold75a9ff12021-04-06 11:26:02 -07008230 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian11263f32020-08-13 15:42:55 -07008231 mApp, subId, "isDataRoamingEnabled");
8232 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008233
Pengquan Menga1bb6272018-09-06 09:59:22 -07008234 boolean isEnabled = false;
8235 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008236 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008237 Phone phone = getPhone(subId);
8238 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008239 } finally {
8240 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008241 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008242 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008243 }
8244
8245
8246 /**
8247 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8248 *
8249 * <p> Requires permission:
8250 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8251 * privileges.
8252 *
8253 * @param subId subscription id
8254 * @param isEnabled {@code true} means enable, {@code false} means disable.
8255 */
8256 @Override
8257 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8259 mApp, subId, "setDataRoamingEnabled");
8260
Pengquan Menga1bb6272018-09-06 09:59:22 -07008261 final long identity = Binder.clearCallingIdentity();
8262 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008263 Phone phone = getPhone(subId);
8264 if (phone != null) {
8265 phone.setDataRoamingEnabled(isEnabled);
8266 }
8267 } finally {
8268 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008269 }
8270 }
8271
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008272 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008273 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008274 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008275 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008276 mApp, subId, "isManualNetworkSelectionAllowed");
8277
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008278 boolean isAllowed = true;
8279 final long identity = Binder.clearCallingIdentity();
8280 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008281 Phone phone = getPhone(subId);
8282 if (phone != null) {
8283 isAllowed = phone.isCspPlmnEnabled();
8284 }
8285 } finally {
8286 Binder.restoreCallingIdentity(identity);
8287 }
8288 return isAllowed;
8289 }
8290
8291 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008292 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008293 // Verify that tha callingPackage belongs to the calling UID
8294 mApp.getSystemService(AppOpsManager.class)
8295 .checkPackage(Binder.getCallingUid(), callingPackage);
8296
Jordan Liu1e142fc2019-04-22 15:10:43 -07008297 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008298 try {
8299 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008300 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008301 } catch (SecurityException e) {
8302 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8303 // has carrier privileges on an active UICC
8304 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8305 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008306 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008307 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008308 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008309
8310 final long identity = Binder.clearCallingIdentity();
8311 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008312 UiccController uiccController = UiccController.getInstance();
8313 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008314 if (hasReadPermission) {
8315 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008316 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008317
8318 // Remove private info if the caller doesn't have access
8319 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8320 for (UiccCardInfo cardInfo : cardInfos) {
8321 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8322 // is available
8323 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8324 if (card == null || card.getUiccProfile() == null) {
8325 // assume no access if the card or profile is unavailable
8326 filteredInfos.add(cardInfo.getUnprivileged());
8327 continue;
8328 }
8329 UiccProfile profile = card.getUiccProfile();
8330 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8331 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8332 filteredInfos.add(cardInfo);
8333 } else {
8334 filteredInfos.add(cardInfo.getUnprivileged());
8335 }
8336 }
8337 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008338 } finally {
8339 Binder.restoreCallingIdentity(identity);
8340 }
8341 }
8342
8343 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008344 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008345 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008347 final long identity = Binder.clearCallingIdentity();
8348 try {
8349 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8350 if (slots == null) {
8351 Rlog.i(LOG_TAG, "slots is null.");
8352 return null;
8353 }
8354
8355 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8356 for (int i = 0; i < slots.length; i++) {
8357 UiccSlot slot = slots[i];
8358 if (slot == null) {
8359 continue;
8360 }
8361
Jordan Liu7be7e652019-05-06 18:55:02 +00008362 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363 UiccCard card = slot.getUiccCard();
8364 if (card != null) {
8365 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008366 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008367 cardId = slot.getEid();
8368 if (TextUtils.isEmpty(cardId)) {
8369 cardId = slot.getIccId();
8370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371 }
8372
Jordan Liu857451f2019-05-09 16:35:35 -07008373 if (cardId != null) {
8374 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8375 // if cardId is an EID, it's all digits so this is fine
8376 cardId = IccUtils.stripTrailingFs(cardId);
8377 }
8378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008379 int cardState = 0;
8380 switch (slot.getCardState()) {
8381 case CARDSTATE_ABSENT:
8382 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8383 break;
8384 case CARDSTATE_PRESENT:
8385 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8386 break;
8387 case CARDSTATE_ERROR:
8388 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8389 break;
8390 case CARDSTATE_RESTRICTED:
8391 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8392 break;
8393 default:
8394 break;
8395
8396 }
8397
8398 infos[i] = new UiccSlotInfo(
8399 slot.isActive(),
8400 slot.isEuicc(),
8401 cardId,
8402 cardState,
8403 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008404 slot.isExtendedApduSupported(),
8405 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008406 }
8407 return infos;
8408 } finally {
8409 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008410 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008411 }
8412
8413 @Override
8414 public boolean switchSlots(int[] physicalSlots) {
8415 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008416
8417 final long identity = Binder.clearCallingIdentity();
8418 try {
8419 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8420 } finally {
8421 Binder.restoreCallingIdentity(identity);
8422 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008423 }
Jack Yu4c988042018-02-27 15:30:01 -08008424
8425 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008426 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008427 final long identity = Binder.clearCallingIdentity();
8428 try {
8429 return UiccController.getInstance().getCardIdForDefaultEuicc();
8430 } finally {
8431 Binder.restoreCallingIdentity(identity);
8432 }
8433 }
8434
Pengquan Meng85728fb2018-03-12 16:31:21 -07008435 /**
goneil47ffb6e2018-04-06 15:40:58 -07008436 * A test API to reload the UICC profile.
8437 *
8438 * <p>Requires that the calling app has permission
8439 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8440 * @hide
8441 */
8442 @Override
8443 public void refreshUiccProfile(int subId) {
8444 enforceModifyPermission();
8445
8446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 Phone phone = getPhone(subId);
8449 if (phone == null) {
8450 return;
8451 }
8452 UiccCard uiccCard = phone.getUiccCard();
8453 if (uiccCard == null) {
8454 return;
8455 }
8456 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8457 if (uiccProfile == null) {
8458 return;
8459 }
8460 uiccProfile.refresh();
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
8463 }
8464 }
8465
8466 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008467 * Returns false if the mobile data is disabled by default, otherwise return true.
8468 */
8469 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008470 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008471 }
8472
8473 /**
8474 * Returns true if the data roaming is enabled by default, i.e the system property
8475 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8476 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8477 */
8478 private boolean getDefaultDataRoamingEnabled(int subId) {
8479 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008480 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008481 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008482 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8483 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8484 return isDataRoamingEnabled;
8485 }
8486
8487 /**
8488 * Returns the default network type for the given {@code subId}, if the default network type is
8489 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8490 */
8491 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008492 List<Integer> list = TelephonyProperties.default_network();
8493 int phoneId = mSubscriptionController.getPhoneId(subId);
8494 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8495 return list.get(phoneId);
8496 }
8497 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008498 }
fionaxua13278b2018-03-21 00:08:13 -07008499
8500 @Override
8501 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008502 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008504
8505 final long identity = Binder.clearCallingIdentity();
8506 try {
8507 final Phone phone = getPhone(subId);
8508 if (phone == null) {
8509 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8510 return;
8511 }
chen xueaba88a2019-03-15 13:15:10 -07008512 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8513 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008514 if (carrierPrivilegeRules == null) {
8515 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8516 } else {
8517 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008519 } finally {
8520 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008521 }
fionaxua13278b2018-03-21 00:08:13 -07008522 }
8523
8524 @Override
8525 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008526 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008527
8528 final long identity = Binder.clearCallingIdentity();
8529 try {
8530 final Phone phone = getPhone(subId);
8531 if (phone == null) {
8532 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8533 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8534 }
8535 return phone.getCarrierIdListVersion();
8536 } finally {
8537 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008538 }
fionaxua13278b2018-03-21 00:08:13 -07008539 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008540
8541 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008542 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8543 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008545 mApp, subId, callingPackage, callingFeatureId,
8546 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008547 return -1;
8548 }
8549
8550 final long identity = Binder.clearCallingIdentity();
8551 try {
8552 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8553 } finally {
8554 Binder.restoreCallingIdentity(identity);
8555 }
8556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008557
8558 @Override
8559 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008560 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008561 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008562 mApp, subId, "getCdmaRoamingMode");
8563
8564 final long identity = Binder.clearCallingIdentity();
8565 try {
8566 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8567 } finally {
8568 Binder.restoreCallingIdentity(identity);
8569 }
8570 }
8571
8572 @Override
8573 public boolean setCdmaRoamingMode(int subId, int mode) {
8574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8575 mApp, subId, "setCdmaRoamingMode");
8576
8577 final long identity = Binder.clearCallingIdentity();
8578 try {
8579 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8580 } finally {
8581 Binder.restoreCallingIdentity(identity);
8582 }
8583 }
8584
8585 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008586 public int getCdmaSubscriptionMode(int subId) {
8587 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008588 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin49f22af2020-10-28 13:46:24 -07008589 mApp, subId, "getCdmaSubscriptionMode");
8590
8591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8594 } finally {
8595 Binder.restoreCallingIdentity(identity);
8596 }
8597 }
8598
8599 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008600 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8602 mApp, subId, "setCdmaSubscriptionMode");
8603
8604 final long identity = Binder.clearCallingIdentity();
8605 try {
8606 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8607 } finally {
8608 Binder.restoreCallingIdentity(identity);
8609 }
8610 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008611
sqianc5eccab2018-10-19 18:46:41 -07008612 @Override
sqian8c685422019-02-22 15:55:18 -08008613 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008614 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008616 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8617 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008618 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8619 }
8620 final long identity = Binder.clearCallingIdentity();
8621 try {
sqian854d44b2018-12-12 16:48:18 -08008622 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8623 for (Phone phone: PhoneFactory.getPhones()) {
8624 if (phone.getEmergencyNumberTracker() != null
8625 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8626 emergencyNumberListInternal.put(
8627 phone.getSubId(),
8628 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8629 }
sqian11b7a0e2018-12-05 18:48:28 -08008630 }
sqian854d44b2018-12-12 16:48:18 -08008631 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008632 } finally {
8633 Binder.restoreCallingIdentity(identity);
8634 }
sqianc5eccab2018-10-19 18:46:41 -07008635 }
8636
8637 @Override
sqian8c685422019-02-22 15:55:18 -08008638 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008639 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008640 if (!exactMatch) {
8641 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07008642 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008643 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008644 }
8645 final long identity = Binder.clearCallingIdentity();
8646 try {
sqian854d44b2018-12-12 16:48:18 -08008647 for (Phone phone: PhoneFactory.getPhones()) {
8648 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008649 && phone.getEmergencyNumberTracker()
8650 .isEmergencyNumber(number, exactMatch)) {
8651 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008652 }
sqian11b7a0e2018-12-05 18:48:28 -08008653 }
8654 return false;
8655 } finally {
8656 Binder.restoreCallingIdentity(identity);
8657 }
8658 }
8659
sqianf4ca7ed2019-01-15 18:32:07 -08008660 /**
Shuo Qian479dd9e2021-02-22 18:32:21 -08008661 * Start emergency callback mode for GsmCdmaPhone for testing.
8662 */
8663 @Override
8664 public void startEmergencyCallbackMode() {
8665 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8666 "startEmergencyCallbackMode");
8667 enforceModifyPermission();
8668 final long identity = Binder.clearCallingIdentity();
8669 try {
8670 for (Phone phone : PhoneFactory.getPhones()) {
8671 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8672 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8673 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8674 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8675 gsmCdmaPhone.obtainMessage(
8676 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8677 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8678 }
8679 }
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
8683 }
8684
8685 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008686 * Update emergency number list for test mode.
8687 */
8688 @Override
8689 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8690 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8691 "updateEmergencyNumberListTestMode");
8692
8693 final long identity = Binder.clearCallingIdentity();
8694 try {
8695 for (Phone phone: PhoneFactory.getPhones()) {
8696 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8697 if (tracker != null) {
8698 tracker.executeEmergencyNumberTestModeCommand(action, num);
8699 }
8700 }
8701 } finally {
8702 Binder.restoreCallingIdentity(identity);
8703 }
8704 }
8705
8706 /**
8707 * Get the full emergency number list for test mode.
8708 */
8709 @Override
8710 public List<String> getEmergencyNumberListTestMode() {
8711 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8712 "getEmergencyNumberListTestMode");
8713
8714 final long identity = Binder.clearCallingIdentity();
8715 try {
8716 Set<String> emergencyNumbers = new HashSet<>();
8717 for (Phone phone: PhoneFactory.getPhones()) {
8718 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8719 if (tracker != null) {
8720 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8721 emergencyNumbers.add(num.getNumber());
8722 }
8723 }
8724 }
8725 return new ArrayList<>(emergencyNumbers);
8726 } finally {
8727 Binder.restoreCallingIdentity(identity);
8728 }
8729 }
8730
chen xud6b45bd2018-10-30 22:27:10 -07008731 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008732 public int getEmergencyNumberDbVersion(int subId) {
8733 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8734
8735 final long identity = Binder.clearCallingIdentity();
8736 try {
8737 final Phone phone = getPhone(subId);
8738 if (phone == null) {
8739 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8740 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8741 }
8742 return phone.getEmergencyNumberDbVersion();
8743 } finally {
8744 Binder.restoreCallingIdentity(identity);
8745 }
8746 }
8747
8748 @Override
8749 public void notifyOtaEmergencyNumberDbInstalled() {
8750 enforceModifyPermission();
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.updateOtaEmergencyNumberDatabase();
8758 }
8759 }
8760 } finally {
8761 Binder.restoreCallingIdentity(identity);
8762 }
8763 }
8764
8765 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008766 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008767 enforceActiveEmergencySessionPermission();
8768
8769 final long identity = Binder.clearCallingIdentity();
8770 try {
8771 for (Phone phone: PhoneFactory.getPhones()) {
8772 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8773 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008774 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8775 }
8776 }
8777 } finally {
8778 Binder.restoreCallingIdentity(identity);
8779 }
8780 }
8781
8782 @Override
8783 public void resetOtaEmergencyNumberDbFilePath() {
8784 enforceActiveEmergencySessionPermission();
8785
8786 final long identity = Binder.clearCallingIdentity();
8787 try {
8788 for (Phone phone: PhoneFactory.getPhones()) {
8789 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8790 if (tracker != null) {
8791 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008792 }
8793 }
8794 } finally {
8795 Binder.restoreCallingIdentity(identity);
8796 }
8797 }
8798
8799 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008800 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8801 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8802 Phone phone = getPhone(subId);
8803 if (phone == null) {
8804 return null;
8805 }
8806 final long identity = Binder.clearCallingIdentity();
8807 try {
8808 UiccProfile profile = UiccController.getInstance()
8809 .getUiccProfileForPhone(phone.getPhoneId());
8810 if (profile != null) {
8811 return profile.getCertsFromCarrierPrivilegeAccessRules();
8812 }
8813 } finally {
8814 Binder.restoreCallingIdentity(identity);
8815 }
8816 return null;
8817 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008818
8819 /**
8820 * Enable or disable a modem stack.
8821 */
8822 @Override
8823 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8824 enforceModifyPermission();
8825
8826 final long identity = Binder.clearCallingIdentity();
8827 try {
8828 Phone phone = PhoneFactory.getPhone(slotIndex);
8829 if (phone == null) {
8830 return false;
8831 } else {
8832 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8833 }
8834 } finally {
8835 Binder.restoreCallingIdentity(identity);
8836 }
8837 }
Michelecea4cf22018-12-21 15:00:11 -08008838
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008839 /**
8840 * Whether a modem stack is enabled or not.
8841 */
8842 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008843 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8844 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008845 Phone phone = PhoneFactory.getPhone(slotIndex);
8846 if (phone == null) return false;
8847
8848 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008849 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8850 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008851 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8852 }
8853
8854 final long identity = Binder.clearCallingIdentity();
8855 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008856 try {
8857 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8858 } catch (NoSuchElementException ex) {
8859 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8860 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008861 } finally {
8862 Binder.restoreCallingIdentity(identity);
8863 }
8864 }
8865
Michelecea4cf22018-12-21 15:00:11 -08008866 @Override
Michele0ea7d782019-03-19 14:58:42 -07008867 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008868 enforceModifyPermission();
8869
8870 final long identity = Binder.clearCallingIdentity();
8871 try {
8872 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008873 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008874 .commit();
8875 } finally {
8876 Binder.restoreCallingIdentity(identity);
8877 }
8878 }
8879
8880 @Override
Michele0ea7d782019-03-19 14:58:42 -07008881 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008882 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008884 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8885 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008886 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008887 }
Michelecea4cf22018-12-21 15:00:11 -08008888
8889 final long identity = Binder.clearCallingIdentity();
8890 try {
Michele0ea7d782019-03-19 14:58:42 -07008891 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008892 } finally {
8893 Binder.restoreCallingIdentity(identity);
8894 }
8895 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008896
Michele0ea7d782019-03-19 14:58:42 -07008897 @TelephonyManager.IsMultiSimSupportedResult
8898 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008899 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8900 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8901 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008902 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8903 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008904 }
8905 // Check if the hardware supports multisim functionality. If usage of multisim is not
8906 // supported by the modem, indicate that it is restricted.
8907 PhoneCapability staticCapability =
8908 mPhoneConfigurationManager.getStaticPhoneCapability();
8909 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008910 loge("isMultiSimSupportedInternal: no static configuration available");
8911 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008912 }
SongFerngWang2c4309d2021-01-17 21:51:44 +08008913 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008914 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8915 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008916 }
8917 // Check if support of multiple SIMs is restricted by carrier
8918 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008919 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008920 }
8921
Michele0ea7d782019-03-19 14:58:42 -07008922 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008923 }
8924
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008925 /**
8926 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008927 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8928 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8929 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008930 * @param numOfSims number of active sims we want to switch to
8931 */
8932 @Override
8933 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008934 if (numOfSims == 1) {
8935 enforceModifyPermission();
8936 } else {
8937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8938 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8939 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008940 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008941
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008942 try {
Michele30b57b22019-03-01 12:01:14 -08008943 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008944 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008945 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8946 return;
8947 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008948 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8949 } finally {
8950 Binder.restoreCallingIdentity(identity);
8951 }
8952 }
8953
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008954 @Override
8955 public boolean isApplicationOnUicc(int subId, int appType) {
8956 enforceReadPrivilegedPermission("isApplicationOnUicc");
8957 Phone phone = getPhone(subId);
8958 if (phone == null) {
8959 return false;
8960 }
8961 final long identity = Binder.clearCallingIdentity();
8962 try {
8963 UiccCard uiccCard = phone.getUiccCard();
8964 if (uiccCard == null) {
8965 return false;
8966 }
8967 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8968 if (uiccProfile == null) {
8969 return false;
8970 }
8971 if (TelephonyManager.APPTYPE_SIM <= appType
8972 && appType <= TelephonyManager.APPTYPE_ISIM) {
8973 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8974 }
8975 return false;
8976 } finally {
8977 Binder.restoreCallingIdentity(identity);
8978 }
8979 }
8980
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008981 /**
chen xub4baa772019-04-03 10:23:41 -07008982 * Get whether making changes to modem configurations will trigger reboot.
8983 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008984 */
8985 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008986 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8987 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008989 mApp, subId, callingPackage, callingFeatureId,
8990 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008991 return false;
8992 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
9000
Nathan Harold29f5f052019-02-15 13:41:57 -08009001 private void updateModemStateMetrics() {
9002 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9003 // TODO: check the state for each modem if the api is ready.
9004 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9005 }
9006
Pengquan Meng3889a572019-01-23 11:16:29 -08009007 @Override
9008 public int[] getSlotsMapping() {
9009 enforceReadPrivilegedPermission("getSlotsMapping");
9010
9011 final long identity = Binder.clearCallingIdentity();
9012 try {
9013 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9014 // All logical slots should have a mapping to a physical slot.
9015 int[] logicalSlotsMapping = new int[phoneCount];
9016 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9017 for (int i = 0; i < slotInfos.length; i++) {
9018 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9019 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9020 }
9021 }
9022 return logicalSlotsMapping;
9023 } finally {
9024 Binder.restoreCallingIdentity(identity);
9025 }
9026 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009027
9028 /**
9029 * Get the IRadio HAL Version
9030 */
9031 @Override
9032 public int getRadioHalVersion() {
9033 Phone phone = getDefaultPhone();
9034 if (phone == null) return -1;
9035 HalVersion hv = phone.getHalVersion();
9036 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9037 return hv.major * 100 + hv.minor;
9038 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009039
9040 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08009041 * Get the current calling package name.
9042 * @return the current calling package name
9043 */
9044 @Override
9045 public String getCurrentPackageName() {
9046 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9047 }
9048
9049 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009050 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9051 * corresponding network requests on a subId.
9052 *
9053 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009054 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009055 * 2) APN is un-metered for this subscription, or
9056 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07009057 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009058 *
9059 * @return whether data is allowed for a apn type.
9060 *
9061 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009062 */
9063 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009064 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07009065 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9066 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009067
9068 // Now that all security checks passes, perform the operation as ourselves.
9069 final long identity = Binder.clearCallingIdentity();
9070 try {
9071 Phone phone = getPhone(subId);
9072 if (phone == null) return false;
9073
Jack Yu41407ee2019-05-13 16:54:09 -07009074 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009075 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9076 } finally {
9077 Binder.restoreCallingIdentity(identity);
9078 }
9079 }
9080
9081 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009082 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009083 enforceReadPrivilegedPermission("isApnMetered");
9084
9085 // Now that all security checks passes, perform the operation as ourselves.
9086 final long identity = Binder.clearCallingIdentity();
9087 try {
9088 Phone phone = getPhone(subId);
9089 if (phone == null) return true; // By default return true.
9090
Jack Yu41407ee2019-05-13 16:54:09 -07009091 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009092 } finally {
9093 Binder.restoreCallingIdentity(identity);
9094 }
9095 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009096
9097 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08009098 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9099 int subscriptionId, IBooleanConsumer resultCallback) {
9100 enforceModifyPermission();
9101 long token = Binder.clearCallingIdentity();
9102 try {
9103 Phone phone = getPhone(subscriptionId);
9104 if (phone == null) {
9105 try {
9106 if (resultCallback != null) {
9107 resultCallback.accept(false);
9108 }
9109 } catch (RemoteException e) {
9110 // ignore
9111 }
9112 return;
9113 }
9114 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9115 Pair.create(specifiers, (x) -> {
9116 try {
9117 if (resultCallback != null) {
9118 resultCallback.accept(x);
9119 }
9120 } catch (RemoteException e) {
9121 // ignore
9122 }
9123 });
9124 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9125 } finally {
9126 Binder.restoreCallingIdentity(token);
9127 }
9128 }
9129
9130 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009131 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9132 TelephonyPermissions
Nathan Harold75a9ff12021-04-06 11:26:02 -07009133 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chincc055732020-11-18 13:39:35 -08009134 mApp, subId, "getSystemSelectionChannels");
9135 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
Sarah Chin58691872021-03-13 03:17:40 -08009138 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9139 if (result instanceof IllegalStateException) {
9140 throw (IllegalStateException) result;
9141 }
9142 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chincc055732020-11-18 13:39:35 -08009143 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9144 return specifiers;
9145 } finally {
9146 Binder.restoreCallingIdentity(identity);
9147 }
9148 }
9149
9150 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009151 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009152 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009153 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9154 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9155 if (iccRecords == null) {
9156 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9157 return false;
9158 }
9159 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9160 }
9161
9162 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009163 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9164 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009165 if (callingPackage == null) {
9166 callingPackage = getCurrentPackageName();
9167 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009168 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9169 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009170 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9171 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009172 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9173 }
9174 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9175 Intent intent = new Intent();
9176 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9177 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9178 // Bring up choose default SMS subscription dialog right now
9179 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9180 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9181 mApp.startActivity(intent);
9182 }
chen xud5ca2d52019-05-28 15:20:57 -07009183
9184 @Override
9185 public String getMmsUAProfUrl(int subId) {
9186 //TODO investigate if this API should require proper permission check in R b/133791609
9187 final long identity = Binder.clearCallingIdentity();
9188 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009189 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9190 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9191 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9192 return carrierUAProfUrl;
9193 }
chen xud5ca2d52019-05-28 15:20:57 -07009194 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9195 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9196 } finally {
9197 Binder.restoreCallingIdentity(identity);
9198 }
9199 }
9200
9201 @Override
9202 public String getMmsUserAgent(int subId) {
9203 //TODO investigate if this API should require proper permission check in R b/133791609
9204 final long identity = Binder.clearCallingIdentity();
9205 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009206 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9207 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9208 if (!TextUtils.isEmpty(carrierUserAgent)) {
9209 return carrierUserAgent;
9210 }
chen xud5ca2d52019-05-28 15:20:57 -07009211 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9212 .getString(com.android.internal.R.string.config_mms_user_agent);
9213 } finally {
9214 Binder.restoreCallingIdentity(identity);
9215 }
9216 }
Jack Yub07d4972019-05-28 16:12:25 -07009217
9218 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009219 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9220 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9221
9222 final long identity = Binder.clearCallingIdentity();
9223 try {
9224 Phone phone = getPhone(subscriptionId);
9225 if (phone == null) return false;
9226
9227 switch (policy) {
9228 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9229 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9230 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9231 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9232 default:
9233 throw new IllegalArgumentException(policy + " is not a valid policy");
9234 }
9235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 }
9239
9240 @Override
9241 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9242 boolean enabled) {
9243 enforceModifyPermission();
9244
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
9247 Phone phone = getPhone(subscriptionId);
9248 if (phone == null) return;
9249
9250 switch (policy) {
9251 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9252 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9253 break;
9254 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9255 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9256 break;
9257 default:
9258 throw new IllegalArgumentException(policy + " is not a valid policy");
9259 }
9260 } finally {
9261 Binder.restoreCallingIdentity(identity);
9262 }
9263 }
9264
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009265 /**
Hall Liub48cf452020-09-25 11:13:49 -07009266 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009267 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9268 * otherwise.
9269 */
9270 @Override
9271 public void setCepEnabled(boolean isCepEnabled) {
9272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9273
9274 final long identity = Binder.clearCallingIdentity();
9275 try {
9276 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9277 for (Phone phone : PhoneFactory.getPhones()) {
9278 Phone defaultPhone = phone.getImsPhone();
9279 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9280 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9281 ImsPhoneCallTracker imsPhoneCallTracker =
9282 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9283 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9284 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9285 + imsPhone.getMsisdn());
9286 }
9287 }
9288 } finally {
9289 Binder.restoreCallingIdentity(identity);
9290 }
9291 }
allenwtsu46dcc572020-01-08 18:24:03 +08009292
9293 /**
9294 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9295 *
9296 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9297 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9298 * before being read.
9299 */
9300 @Override
9301 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9302 isCompressed) {
9303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9304 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009305 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9306 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9307 }
9308 if (!isImsAvailableOnDevice()) {
9309 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9310 "IMS not available on device.");
9311 }
9312
9313 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009314 try {
Hui Wang068ab862020-10-31 05:12:53 +00009315 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9316 } finally {
9317 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009318 }
9319 }
zoey chenf95ca592019-12-30 16:11:23 +08009320
9321 @Override
9322 public boolean isIccLockEnabled(int subId) {
9323 enforceReadPrivilegedPermission("isIccLockEnabled");
9324
9325 // Now that all security checks passes, perform the operation as ourselves.
9326 final long identity = Binder.clearCallingIdentity();
9327 try {
9328 Phone phone = getPhone(subId);
9329 if (phone != null && phone.getIccCard() != null) {
9330 return phone.getIccCard().getIccLockEnabled();
9331 } else {
9332 return false;
9333 }
9334 } finally {
9335 Binder.restoreCallingIdentity(identity);
9336 }
9337 }
9338
9339 /**
zoey chene02881a2019-12-30 16:11:23 +08009340 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009341 *
zoey chene02881a2019-12-30 16:11:23 +08009342 * @return an integer representing the status of IccLock enabled or disabled in the following
9343 * three cases:
9344 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9345 * successfully.
9346 * - Positive number and zero for remaining password attempts.
9347 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009348 *
9349 */
9350 @Override
9351 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9352 enforceModifyPermission();
9353
9354 Phone phone = getPhone(subId);
9355 if (phone == null) {
9356 return 0;
9357 }
9358 // Now that all security checks passes, perform the operation as ourselves.
9359 final long identity = Binder.clearCallingIdentity();
9360 try {
9361 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9362 new Pair<Boolean, String>(enabled, password), phone, null);
9363 return attemptsRemaining;
9364
9365 } catch (Exception e) {
9366 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9367 } finally {
9368 Binder.restoreCallingIdentity(identity);
9369 }
9370 return 0;
9371 }
9372
9373 /**
9374 * Change the ICC password used in ICC pin lock.
9375 *
zoey chene02881a2019-12-30 16:11:23 +08009376 * @return an integer representing the status of IccLock changed in the following three cases:
9377 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9378 * - Positive number and zero for remaining password attempts.
9379 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009380 *
9381 */
9382 @Override
9383 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9384 enforceModifyPermission();
9385
9386 Phone phone = getPhone(subId);
9387 if (phone == null) {
9388 return 0;
9389 }
9390 // Now that all security checks passes, perform the operation as ourselves.
9391 final long identity = Binder.clearCallingIdentity();
9392 try {
9393 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9394 new Pair<String, String>(oldPassword, newPassword), phone, null);
9395 return attemptsRemaining;
9396
9397 } catch (Exception e) {
9398 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9399 } finally {
9400 Binder.restoreCallingIdentity(identity);
9401 }
9402 return 0;
9403 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009404
Peter Wangdafb9ac2020-01-15 14:13:38 -08009405 /**
9406 * Request for receiving user activity notification
9407 */
9408 @Override
9409 public void requestUserActivityNotification() {
9410 if (!mNotifyUserActivity.get()
9411 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9412 mNotifyUserActivity.set(true);
9413 }
9414 }
9415
9416 /**
9417 * Called when userActivity is signalled in the power manager.
9418 * This is safe to call from any thread, with any window manager locks held or not.
9419 */
9420 @Override
9421 public void userActivity() {
9422 // ***************************************
9423 // * Inherited from PhoneWindowManager *
9424 // ***************************************
9425 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9426 // WITH ITS LOCKS HELD.
9427 //
9428 // This code must be VERY careful about the locks
9429 // it acquires.
9430 // In fact, the current code acquires way too many,
9431 // and probably has lurking deadlocks.
9432
9433 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9434 throw new SecurityException("Only the OS may call notifyUserActivity()");
9435 }
9436
9437 if (mNotifyUserActivity.getAndSet(false)) {
9438 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9439 USER_ACTIVITY_NOTIFICATION_DELAY);
9440 }
9441 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009442
Malcolm Chen884180b2020-04-13 11:59:40 -07009443 @Override
9444 public boolean canConnectTo5GInDsdsMode() {
9445 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9446 }
Jack Yud10cdd42020-09-28 20:28:01 -07009447
9448 @Override
9449 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9450 String callingFeatureId) {
9451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9452 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9453 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9454 }
9455
9456 Phone phone = getPhone(subId);
9457 if (phone == null) {
9458 throw new RuntimeException("phone is not available");
9459 }
9460 // Now that all security checks passes, perform the operation as ourselves.
9461 final long identity = Binder.clearCallingIdentity();
9462 try {
9463 return phone.getEquivalentHomePlmns();
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009468
Hui Wang0866fcc2020-10-12 12:14:23 -07009469 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009470 public boolean isRadioInterfaceCapabilitySupported(
9471 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009472 Set<String> radioInterfaceCapabilities =
Daniel Brightfe1e6ac2021-03-12 10:25:03 -08009473 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright74f1ca82020-11-13 11:49:37 -08009474 if (radioInterfaceCapabilities == null) {
9475 throw new RuntimeException("radio interface capabilities are not available");
9476 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009477 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009478 }
9479 }
9480
9481 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009482 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9483 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009484 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9485 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9486 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9487 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9488 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009489 if (DBG) {
9490 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9491 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9492 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9493 }
9494
9495 if (!SubscriptionManager.isValidSubscriptionId(subId)
9496 || appType < TelephonyManager.APPTYPE_UNKNOWN
9497 || appType > TelephonyManager.APPTYPE_ISIM
9498 || nafUrl == null || securityProtocol == null || callback == null) {
9499 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9500 if (callback != null) {
9501 try {
9502 callback.onAuthenticationFailure(
9503 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9504 } catch (RemoteException exception) {
9505 log("Fail to notify onAuthenticationFailure due to " + exception);
9506 }
9507 return;
9508 }
9509 }
9510
9511 final long token = Binder.clearCallingIdentity();
9512 try {
9513 getGbaManager(subId).bootstrapAuthenticationRequest(
9514 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9515 forceBootStrapping, callback));
9516 } finally {
9517 Binder.restoreCallingIdentity(token);
9518 }
9519 }
9520
Jack Nudelman24d51a52020-11-24 12:08:04 -08009521 /**
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009522 * Attempts to set the radio power state for all phones for thermal reason.
9523 * This does not guarantee that the
Jack Nudelman24d51a52020-11-24 12:08:04 -08009524 * requested radio power state will actually be set. See {@link
9525 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9526 *
Jack Nudelman24d51a52020-11-24 12:08:04 -08009527 * @param enable {@code true} if trying to turn radio on.
9528 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9529 * false}.
9530 */
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009531 private boolean setRadioPowerForThermal(boolean enable) {
9532 boolean isPhoneAvailable = false;
9533 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9534 Phone phone = PhoneFactory.getPhone(i);
9535 if (phone != null) {
9536 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9537 isPhoneAvailable = true;
9538 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009539 }
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009540
9541 // return true if successfully informed the phone object about the thermal radio power
9542 // request.
9543 return isPhoneAvailable;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009544 }
9545
9546 private int handleDataThrottlingRequest(int subId,
9547 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009548 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9549 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9550 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9551 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9552 throw new IllegalArgumentException("modem does not support data throttling");
9553 }
9554
Jack Nudelman24d51a52020-11-24 12:08:04 -08009555 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9556 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009557 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009558 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9559 }
9560
9561 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9562
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009563 if (isDataThrottlingSupported) {
9564 int thermalMitigationResult =
Jack Nudelman24d51a52020-11-24 12:08:04 -08009565 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009566 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9567 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9568 } else if (thermalMitigationResult
9569 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman20352592021-05-20 13:57:30 -07009570 log("Modem likely does not support data throttling on secondary carrier. Data " +
9571 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9572 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009573 }
9574 return thermalMitigationResult;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009575 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009576
9577 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009578 }
9579
Jack Nudelman644b91a2021-03-12 14:09:48 -08009580 private static List<String> getThermalMitigationAllowlist(Context context) {
9581 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9582 for (String pckg : context.getResources()
9583 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9584 sThermalMitigationAllowlistedPackages.add(pckg);
9585 }
9586 }
9587
9588 return sThermalMitigationAllowlistedPackages;
9589 }
9590
Jack Nudelmane634f962021-05-13 10:00:15 -07009591 private boolean isAnyPhoneInEmergencyState() {
9592 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9593 if (tm.isInEmergencyCall()) {
9594 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9595 return true;
9596 }
9597 for (Phone phone : PhoneFactory.getPhones()) {
9598 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9599 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9600 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9601 + phone.isInEcm());
9602 return true;
9603 }
9604 }
9605
9606 return false;
9607 }
9608
Jack Nudelman644b91a2021-03-12 14:09:48 -08009609 /**
9610 * Used by shell commands to add an authorized package name for thermal mitigation.
9611 * @param packageName name of package to be allowlisted
9612 * @param context
9613 */
9614 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9615 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9616 sThermalMitigationAllowlistedPackages.add(packageName);
9617 }
9618
9619 /**
9620 * Used by shell commands to remove an authorized package name for thermal mitigation.
9621 * @param packageName name of package to remove from allowlist
9622 * @param context
9623 */
9624 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9625 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9626 sThermalMitigationAllowlistedPackages.remove(packageName);
9627 }
9628
Jack Nudelman24d51a52020-11-24 12:08:04 -08009629 /**
9630 * Thermal mitigation request to control functionalities at modem.
9631 *
9632 * @param subId the id of the subscription.
9633 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009634 * @param callingPackage the package name of the calling package.
Jack Nudelman24d51a52020-11-24 12:08:04 -08009635 *
9636 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9637 */
9638 @Override
9639 @ThermalMitigationResult
9640 public int sendThermalMitigationRequest(
9641 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009642 ThermalMitigationRequest thermalMitigationRequest,
9643 String callingPackage) throws IllegalArgumentException {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009644 enforceModifyPermission();
9645
Jack Nudelman644b91a2021-03-12 14:09:48 -08009646 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9647 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9648 .contains(callingPackage)) {
9649 throw new SecurityException("Calling package must be configured in the device config. "
9650 + "calling package: " + callingPackage);
9651 }
9652
Jack Nudelman24d51a52020-11-24 12:08:04 -08009653 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9654 final long identity = Binder.clearCallingIdentity();
9655
9656 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9657 try {
9658 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9659 switch (thermalMitigationAction) {
9660 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9661 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009662 handleDataThrottlingRequest(subId,
9663 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009664 break;
9665 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9666 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9667 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9668 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9669 }
9670
9671 // Ensure that radio is on. If not able to power on due to phone being
9672 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009673 if (!setRadioPowerForThermal(true)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009674 thermalMitigationResult =
9675 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9676 break;
9677 }
9678
9679 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9680 false);
9681 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9682 break;
9683 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9684 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9685 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9686 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9687 }
9688
9689 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9690 if (registry != null) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009691 Phone phone = getPhone(subId);
9692 if (phone == null) {
9693 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009694 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009695 break;
9696 }
9697
Jack Nudelmane634f962021-05-13 10:00:15 -07009698 TelephonyConnectionService service =
9699 registry.getTelephonyConnectionService();
Jack Nudelmana80c0012021-06-17 15:39:58 -07009700 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane634f962021-05-13 10:00:15 -07009701 Log.e(LOG_TAG, "An emergency call is pending");
9702 thermalMitigationResult =
9703 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9704 break;
9705 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009706 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009707 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009708 break;
9709 }
9710 } else {
9711 thermalMitigationResult =
9712 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9713 break;
9714 }
9715
9716 // Turn radio off. If not able to power off due to phone being unavailable,
9717 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran730fcba2021-07-29 09:42:42 -07009718 if (!setRadioPowerForThermal(false)) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009719 thermalMitigationResult =
9720 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9721 break;
9722 }
9723 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009724 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009725 break;
9726 default:
9727 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9728 + "not exist. Requested action: " + thermalMitigationAction);
9729 }
9730 } catch (IllegalArgumentException e) {
9731 throw e;
9732 } catch (Exception e) {
9733 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9734 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9735 } finally {
9736 Binder.restoreCallingIdentity(identity);
9737 }
9738
9739 if (DBG) {
9740 log("thermalMitigationRequest returning with thermalMitigationResult: "
9741 + thermalMitigationResult);
9742 }
9743
9744 return thermalMitigationResult;
9745 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009746
9747 /**
9748 * Set the GbaService Package Name that Telephony will bind to.
9749 *
9750 * @param subId The sim that the GbaService is associated with.
9751 * @param packageName The name of the package to be replaced with.
9752 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9753 */
9754 @Override
9755 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9756 enforceModifyPermission();
9757
9758 final long identity = Binder.clearCallingIdentity();
9759 try {
9760 return getGbaManager(subId).overrideServicePackage(packageName);
9761 } finally {
9762 Binder.restoreCallingIdentity(identity);
9763 }
9764 }
9765
9766 /**
9767 * Return the package name of the currently bound GbaService.
9768 *
9769 * @param subId The sim that the GbaService is associated with.
9770 * @return the package name of the GbaService configuration, null if GBA is not supported.
9771 */
9772 @Override
9773 public String getBoundGbaService(int subId) {
9774 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9775
9776 final long identity = Binder.clearCallingIdentity();
9777 try {
9778 return getGbaManager(subId).getServicePackage();
9779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 }
9783
9784 /**
9785 * Set the release time for telephony to unbind GbaService.
9786 *
9787 * @param subId The sim that the GbaService is associated with.
9788 * @param interval The release time to unbind GbaService by millisecond.
9789 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9790 */
9791 @Override
9792 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9793 enforceModifyPermission();
9794
9795 final long identity = Binder.clearCallingIdentity();
9796 try {
9797 return getGbaManager(subId).overrideReleaseTime(interval);
9798 } finally {
9799 Binder.restoreCallingIdentity(identity);
9800 }
9801 }
9802
9803 /**
9804 * Return the release time for telephony to unbind GbaService.
9805 *
9806 * @param subId The sim that the GbaService is associated with.
9807 * @return The release time to unbind GbaService by millisecond.
9808 */
9809 @Override
9810 public int getGbaReleaseTime(int subId) {
9811 enforceReadPrivilegedPermission("getGbaReleaseTime");
9812
9813 final long identity = Binder.clearCallingIdentity();
9814 try {
9815 return getGbaManager(subId).getReleaseTime();
9816 } finally {
9817 Binder.restoreCallingIdentity(identity);
9818 }
9819 }
9820
9821 private GbaManager getGbaManager(int subId) {
9822 GbaManager instance = GbaManager.getInstance(subId);
9823 if (instance == null) {
9824 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9825 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9826 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9827 }
9828 return instance;
9829 }
Hui Wang068ab862020-10-31 05:12:53 +00009830
9831 /**
9832 * indicate whether the device and the carrier can support
9833 * RCS VoLTE single registration.
9834 */
9835 @Override
9836 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009837 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9838 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9839 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9840 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009841
9842 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9843 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9844 }
9845
9846 final long identity = Binder.clearCallingIdentity();
9847 try {
9848 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9849 if (rpm != null) {
Hui Wang048c10a2021-06-21 18:05:57 +00009850 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
9851 if (isCapable != null) {
9852 return isCapable;
9853 }
Hui Wang068ab862020-10-31 05:12:53 +00009854 }
Hui Wang048c10a2021-06-21 18:05:57 +00009855 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
9856 "service is temporarily unavailable.");
Hui Wang068ab862020-10-31 05:12:53 +00009857 } finally {
9858 Binder.restoreCallingIdentity(identity);
9859 }
9860 }
9861
9862 /**
9863 * Register RCS provisioning callback.
9864 */
9865 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009866 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009867 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009868 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009869 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009870 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9871 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009872
9873 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9874 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9875 }
9876 if (!isImsAvailableOnDevice()) {
9877 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9878 "IMS not available on device.");
9879 }
9880
9881 final long identity = Binder.clearCallingIdentity();
9882 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009883 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009884 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009885 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9886 "Service not available for the subscription.");
9887 }
Hui Wang068ab862020-10-31 05:12:53 +00009888 } finally {
9889 Binder.restoreCallingIdentity(identity);
9890 }
9891 }
9892
9893 /**
9894 * Unregister RCS provisioning callback.
9895 */
9896 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009897 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009898 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009899 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009900 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009901 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9902 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009903
9904 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9905 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9906 }
9907 if (!isImsAvailableOnDevice()) {
9908 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9909 "IMS not available on device.");
9910 }
9911
9912 final long identity = Binder.clearCallingIdentity();
9913 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009914 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009915 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009916 } finally {
9917 Binder.restoreCallingIdentity(identity);
9918 }
9919 }
9920
9921 /**
9922 * trigger RCS reconfiguration.
9923 */
9924 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009925 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9926 "triggerRcsReconfiguration",
9927 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009928
9929 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9930 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9931 }
9932 if (!isImsAvailableOnDevice()) {
9933 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9934 "IMS not available on device.");
9935 }
9936
9937 final long identity = Binder.clearCallingIdentity();
9938 try {
9939 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9940 } finally {
9941 Binder.restoreCallingIdentity(identity);
9942 }
9943 }
9944
9945 /**
9946 * Provide the client configuration parameters of the RCS application.
9947 */
9948 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009949 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9950 "setRcsClientConfiguration",
9951 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009952
9953 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9954 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9955 }
9956 if (!isImsAvailableOnDevice()) {
9957 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9958 "IMS not available on device.");
9959 }
9960
9961 final long identity = Binder.clearCallingIdentity();
9962
9963 try {
9964 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9965 if (configBinder == null) {
9966 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9967 } else {
9968 configBinder.setRcsClientConfiguration(rcc);
9969 }
9970 } catch (RemoteException e) {
9971 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9972 } finally {
9973 Binder.restoreCallingIdentity(identity);
9974 }
9975 }
9976
9977 /**
Hui Wang19a21872021-02-19 20:45:36 -08009978 * Enables or disables the test mode for RCS VoLTE single registration.
9979 */
9980 @Override
9981 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9982 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9983 "setRcsSingleRegistrationTestModeEnabled");
9984
9985 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9986 }
9987
9988 /**
9989 * Gets the test mode for RCS VoLTE single registration.
9990 */
9991 @Override
9992 public boolean getRcsSingleRegistrationTestModeEnabled() {
9993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9994 "getRcsSingleRegistrationTestModeEnabled");
9995
9996 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9997 }
9998
9999 /**
Hui Wang068ab862020-10-31 05:12:53 +000010000 * Overrides the config of RCS VoLTE single registration enabled for the device.
10001 */
10002 @Override
10003 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10004 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10005 "setDeviceSingleRegistrationEnabledOverride");
10006 enforceModifyPermission();
10007
10008 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10009 : Boolean.parseBoolean(enabledStr);
10010 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010011 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +000010012 }
10013
10014 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010015 * Sends a device to device communication message. Only usable via shell.
10016 * @param message message to send.
10017 * @param value message value.
10018 */
10019 @Override
10020 public void sendDeviceToDeviceMessage(int message, int value) {
10021 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10022 "setCarrierSingleRegistrationEnabledOverride");
10023 enforceModifyPermission();
10024
10025 final long identity = Binder.clearCallingIdentity();
10026 try {
10027 TelephonyConnectionService service =
10028 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10029 if (service == null) {
10030 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10031 return;
10032 }
10033 service.sendTestDeviceToDeviceMessage(message, value);
10034 } finally {
10035 Binder.restoreCallingIdentity(identity);
10036 }
10037 }
10038
10039
10040 /**
Hui Wang068ab862020-10-31 05:12:53 +000010041 * Gets the config of RCS VoLTE single registration enabled for the device.
10042 */
10043 @Override
10044 public boolean getDeviceSingleRegistrationEnabled() {
10045 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10046 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10047 }
10048
10049 /**
10050 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10051 */
10052 @Override
10053 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10054 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10055 "setCarrierSingleRegistrationEnabledOverride");
10056 enforceModifyPermission();
10057
10058 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10059 : Boolean.parseBoolean(enabledStr);
10060 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10061 subId, enabled);
10062 }
10063
10064 /**
10065 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10066 */
10067 @Override
10068 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10069 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10070 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10071 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010072
10073 /**
Hui Wangeadb2562021-02-26 09:33:38 -080010074 * Overrides the ims feature validation result
10075 */
10076 @Override
10077 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10078 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10079 "setImsFeatureValidationOverride");
10080
10081 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10082 : Boolean.parseBoolean(enabledStr);
10083 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10084 subId, enabled);
10085 }
10086
10087 /**
10088 * Gets the ims feature validation override value
10089 */
10090 @Override
10091 public boolean getImsFeatureValidationOverride(int subId) {
10092 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10093 "getImsFeatureValidationOverride");
10094 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10095 }
10096
10097 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010098 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10099 * their mobile plan.
10100 */
10101 @Override
10102 public String getMobileProvisioningUrl() {
10103 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10104 final long identity = Binder.clearCallingIdentity();
10105 try {
10106 return getDefaultPhone().getMobileProvisioningUrl();
10107 } finally {
10108 Binder.restoreCallingIdentity(identity);
10109 }
10110 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010111
James.cf Linbcdf8b32021-01-14 16:44:13 +080010112 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010113 * Get the EAB contact from the EAB database.
10114 */
10115 @Override
10116 public String getContactFromEab(String contact) {
10117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10118 enforceModifyPermission();
10119 final long identity = Binder.clearCallingIdentity();
10120 try {
10121 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10122 } finally {
10123 Binder.restoreCallingIdentity(identity);
10124 }
10125 }
10126
10127 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010128 * Remove the EAB contacts from the EAB database.
10129 */
10130 @Override
10131 public int removeContactFromEab(int subId, String contacts) {
10132 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10133 enforceModifyPermission();
10134 final long identity = Binder.clearCallingIdentity();
10135 try {
10136 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10137 } finally {
10138 Binder.restoreCallingIdentity(identity);
10139 }
10140 }
10141
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010142 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010143 public boolean getDeviceUceEnabled() {
10144 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10145 final long identity = Binder.clearCallingIdentity();
10146 try {
10147 return mApp.getDeviceUceEnabled();
10148 } finally {
10149 Binder.restoreCallingIdentity(identity);
10150 }
10151 }
10152
10153 @Override
10154 public void setDeviceUceEnabled(boolean isEnabled) {
10155 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10156 final long identity = Binder.clearCallingIdentity();
10157 try {
10158 mApp.setDeviceUceEnabled(isEnabled);
10159 } finally {
10160 Binder.restoreCallingIdentity(identity);
10161 }
10162 }
10163
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010164 /**
10165 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10166 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10167 */
10168 // Used for SHELL command only right now.
10169 @Override
10170 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10171 List<String> featureTags) {
10172 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10173 "addUceRegistrationOverrideShell");
10174 final long identity = Binder.clearCallingIdentity();
10175 try {
10176 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10177 new ArraySet<>(featureTags));
10178 } catch (ImsException e) {
10179 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10180 } finally {
10181 Binder.restoreCallingIdentity(identity);
10182 }
10183 }
10184
10185 /**
10186 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10187 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10188 */
10189 // Used for SHELL command only right now.
10190 @Override
10191 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10192 List<String> featureTags) {
10193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10194 "removeUceRegistrationOverrideShell");
10195 final long identity = Binder.clearCallingIdentity();
10196 try {
10197 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10198 new ArraySet<>(featureTags));
10199 } catch (ImsException e) {
10200 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10201 } finally {
10202 Binder.restoreCallingIdentity(identity);
10203 }
10204 }
10205
10206 /**
10207 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10208 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10209 */
10210 // Used for SHELL command only right now.
10211 @Override
10212 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10213 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10214 "clearUceRegistrationOverrideShell");
10215 final long identity = Binder.clearCallingIdentity();
10216 try {
10217 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10218 } catch (ImsException e) {
10219 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10220 } finally {
10221 Binder.restoreCallingIdentity(identity);
10222 }
10223 }
10224
10225 /**
10226 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10227 */
10228 // Used for SHELL command only right now.
10229 @Override
10230 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10232 "getLatestRcsContactUceCapabilityShell");
10233 final long identity = Binder.clearCallingIdentity();
10234 try {
10235 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10236 } catch (ImsException e) {
10237 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10238 } finally {
10239 Binder.restoreCallingIdentity(identity);
10240 }
10241 }
10242
10243 /**
10244 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10245 * device does not have an active PUBLISH.
10246 */
10247 // Used for SHELL command only right now.
10248 @Override
10249 public String getLastUcePidfXmlShell(int subId) {
10250 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10251 final long identity = Binder.clearCallingIdentity();
10252 try {
10253 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10254 } catch (ImsException e) {
10255 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10256 } finally {
10257 Binder.restoreCallingIdentity(identity);
10258 }
10259 }
10260
James.cf Line8713a42021-04-29 16:04:26 +080010261 /**
10262 * Remove UCE requests cannot be sent to the network status.
10263 */
10264 // Used for SHELL command only right now.
10265 @Override
10266 public boolean removeUceRequestDisallowedStatus(int subId) {
10267 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10268 final long identity = Binder.clearCallingIdentity();
10269 try {
10270 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10271 } catch (ImsException e) {
10272 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10273 } finally {
10274 Binder.restoreCallingIdentity(identity);
10275 }
10276 }
10277
James.cf Lin18bb9002021-05-25 01:37:38 +080010278 /**
10279 * Remove UCE requests cannot be sent to the network status.
10280 */
10281 // Used for SHELL command only.
10282 @Override
10283 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10284 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10285 final long identity = Binder.clearCallingIdentity();
10286 try {
10287 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10288 } catch (ImsException e) {
10289 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10290 } finally {
10291 Binder.restoreCallingIdentity(identity);
10292 }
10293 }
Brad Ebingerd4c5bde2021-02-12 06:18:28 +000010294
James.cf Lin4b784aa2021-01-31 03:25:15 +080010295 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010296 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10297 String callingPackage) {
10298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10299 mApp, subId, "setSignalStrengthUpdateRequest");
10300
10301 final int callingUid = Binder.getCallingUid();
10302 // Verify that tha callingPackage belongs to the calling UID
10303 mApp.getSystemService(AppOpsManager.class)
10304 .checkPackage(callingUid, callingPackage);
10305
10306 validateSignalStrengthUpdateRequest(request, callingUid);
10307
10308 final long identity = Binder.clearCallingIdentity();
10309 try {
10310 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10311 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10312
10313 if (result instanceof IllegalStateException) {
10314 throw (IllegalStateException) result;
10315 }
10316 } finally {
10317 Binder.restoreCallingIdentity(identity);
10318 }
10319 }
10320
10321 @Override
10322 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10323 String callingPackage) {
10324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10325 mApp, subId, "clearSignalStrengthUpdateRequest");
10326
10327 final int callingUid = Binder.getCallingUid();
10328 // Verify that tha callingPackage belongs to the calling UID
10329 mApp.getSystemService(AppOpsManager.class)
10330 .checkPackage(callingUid, callingPackage);
10331
10332 final long identity = Binder.clearCallingIdentity();
10333 try {
10334 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10335 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10336
10337 if (result instanceof IllegalStateException) {
10338 throw (IllegalStateException) result;
10339 }
10340 } finally {
10341 Binder.restoreCallingIdentity(identity);
10342 }
10343 }
10344
10345 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10346 int callingUid) {
10347 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10348 // phone/system process do not have further restriction on request
10349 return;
10350 }
10351
10352 // Applications has restrictions on how to use the request:
10353 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10354 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10355 // This is not system caller which has been checked above
10356 throw new IllegalArgumentException(
10357 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10358 }
10359
10360 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10361 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10362 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10363 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10364 || info.isEnabled()) {
10365 throw new IllegalArgumentException(
10366 "Only system can set hide fields in SignalThresholdInfo");
10367 }
10368
10369 // Thresholds length for each RAN need in range. This has been validated in
10370 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10371 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10372 final int[] thresholds = info.getThresholds();
10373 Objects.requireNonNull(thresholds);
10374 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10375 || thresholds.length
10376 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10377 throw new IllegalArgumentException(
10378 "thresholds length is out of range: " + thresholds.length);
10379 }
10380 }
10381 }
Michele Berionned9fbae52020-11-13 02:36:59 +000010382
10383 /**
10384 * Prepare TelephonyManager for an unattended reboot. The reboot is
10385 * required to be done shortly after the API is invoked.
10386 */
10387 @Override
10388 @TelephonyManager.PrepareUnattendedRebootResult
10389 public int prepareForUnattendedReboot() {
10390 enforceRebootPermission();
10391
10392 final long identity = Binder.clearCallingIdentity();
10393 try {
10394 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10395 } finally {
10396 Binder.restoreCallingIdentity(identity);
10397 }
10398 }
SongFerngWang2c4309d2021-01-17 21:51:44 +080010399
10400 /**
10401 * Gets the current phone capability.
10402 *
10403 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10404 * @return the PhoneCapability which describes the data connection capability of modem.
10405 * It's used to evaluate possible phone config change, for example from single
10406 * SIM device to multi-SIM device.
10407 */
10408 @Override
10409 public PhoneCapability getPhoneCapability() {
10410 enforceReadPrivilegedPermission("getPhoneCapability");
10411 final long identity = Binder.clearCallingIdentity();
10412 try {
10413 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10414 } finally {
10415 Binder.restoreCallingIdentity(identity);
10416 }
10417 }
Hongbo Zengd31d3a32021-02-08 21:50:28 +080010418
10419 /**
10420 * Request to get the current slicing configuration including URSP rules and
10421 * NSSAIs (configured, allowed and rejected).
10422 *
10423 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10424 */
10425 @Override
10426 public void getSlicingConfig(ResultReceiver callback) {
10427 enforceReadPrivilegedPermission("getSlicingConfig");
10428
10429 final long identity = Binder.clearCallingIdentity();
10430 try {
10431 Phone phone = getDefaultPhone();
10432 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10433 } finally {
10434 Binder.restoreCallingIdentity(identity);
10435 }
10436 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010437}